aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-04-26 21:48:01 +0200
committerjohannst <johannes.stoelp@gmail.com>2021-04-26 21:48:01 +0200
commit7da4d2b9cfa1d09991431f849d62a8a8d30f5e51 (patch)
treeba061f2e5f4355e0e24d33e85b0a2f3d0fd51984
parent96cf3e4ee49c256b214795e30eb66801bcdcef6d (diff)
downloaddynld-7da4d2b9cfa1d09991431f849d62a8a8d30f5e51.tar.gz
dynld-7da4d2b9cfa1d09991431f849d62a8a8d30f5e51.zip
libgreet/main: updated comments
-rw-r--r--04_dynld_nostd/libgreet.c10
-rw-r--r--04_dynld_nostd/main.c5
2 files changed, 10 insertions, 5 deletions
diff --git a/04_dynld_nostd/libgreet.c b/04_dynld_nostd/libgreet.c
index e697690..f90bdbf 100644
--- a/04_dynld_nostd/libgreet.c
+++ b/04_dynld_nostd/libgreet.c
@@ -5,19 +5,25 @@
int gCalled = 0;
const char* get_greet() {
+ // Reference global variable -> generates RELA relocation (R_X86_64_GLOB_DAT).
++gCalled;
return "Hello from libgreet.so!";
}
const char* get_greet2() {
+ // Reference global variable -> generates RELA relocation (R_X86_64_GLOB_DAT).
++gCalled;
return "Hello 2 from libgreet.so!";
}
-__attribute__((constructor)) static void libinit() { /* static -> generates R_X86_64_RELATIVE relocation */
+// Definition of `static` function which is referenced from the `INIT` dynamic
+// section entry -> generates R_X86_64_RELATIVE relocation.
+__attribute__((constructor)) static void libinit() {
pfmt("libgreet.so: libinit\n");
}
-__attribute__((destructor)) void libfini() { /* non static -> generates R_X86_64_64 relocation */
+// Definition of `non static` function which is referenced from the `FINI`
+// dynamic section entry -> generates R_X86_64_64 relocation.
+__attribute__((destructor)) void libfini() {
pfmt("libgreet.so: libfini\n");
}
diff --git a/04_dynld_nostd/main.c b/04_dynld_nostd/main.c
index 709fad0..6efa5fc 100644
--- a/04_dynld_nostd/main.c
+++ b/04_dynld_nostd/main.c
@@ -1,7 +1,6 @@
// Copyright (c) 2020 Johannes Stoelp
#include <io.h>
-#include <syscalls.h>
// API of `libgreet.so`.
extern const char* get_greet();
@@ -11,10 +10,10 @@ extern int gCalled;
void _start() {
pfmt("Running _start() @ %s\n", __FILE__);
- // Call function from libgreet.so -> generates PLT relocations.
+ // Call function from libgreet.so -> generates PLT relocations (R_X86_64_JUMP_SLOT).
pfmt("get_greet() -> %s\n", get_greet());
pfmt("get_greet2() -> %s\n", get_greet2());
- // Reference global variable from libgreet.so -> generates RELA relocation.
+ // Reference global variable from libgreet.so -> generates RELA relocation (R_X86_64_COPY).
pfmt("libgreet.so called %d times\n", gCalled);
}