From 287f736e614a2931f57e9aabf42105e3cf3e8992 Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 17 Apr 2021 23:47:17 +0200 Subject: 04: able to map dependency & resolve reolcs and execture main program (initial commit) --- 04_dynld_nostd/libgreet.c | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 04_dynld_nostd/libgreet.c (limited to '04_dynld_nostd/libgreet.c') diff --git a/04_dynld_nostd/libgreet.c b/04_dynld_nostd/libgreet.c new file mode 100644 index 0000000..f2a96a3 --- /dev/null +++ b/04_dynld_nostd/libgreet.c @@ -0,0 +1,9 @@ +// Copyright (c) 2020 Johannes Stoelp + +const char* get_greet() { + return "Hello from libgreet.so!"; +} + +const char* get_greet2() { + return "Hello 2 from libgreet.so!"; +} -- cgit v1.2.3 From 85230524414b6d27664bf77c8584bfeced6c71cb Mon Sep 17 00:00:00 2001 From: johannst Date: Wed, 21 Apr 2021 23:41:59 +0200 Subject: add support to resolve all relocations in PLT & RELA tables; add global variable as example to libgreet.so --- 04_dynld_nostd/libgreet.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to '04_dynld_nostd/libgreet.c') diff --git a/04_dynld_nostd/libgreet.c b/04_dynld_nostd/libgreet.c index f2a96a3..439e236 100644 --- a/04_dynld_nostd/libgreet.c +++ b/04_dynld_nostd/libgreet.c @@ -1,9 +1,13 @@ // Copyright (c) 2020 Johannes Stoelp +int gCalled = 0; + const char* get_greet() { + ++gCalled; return "Hello from libgreet.so!"; } const char* get_greet2() { + ++gCalled; return "Hello 2 from libgreet.so!"; } -- cgit v1.2.3 From 05f740db6fe966d32256d4ed3b897f7b3e051fff Mon Sep 17 00:00:00 2001 From: johannst Date: Sun, 25 Apr 2021 23:38:36 +0200 Subject: added support for R_X86_64_64/R_X86_64_RELATIVE relocations + added init/fini --- 04_dynld_nostd/libgreet.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to '04_dynld_nostd/libgreet.c') diff --git a/04_dynld_nostd/libgreet.c b/04_dynld_nostd/libgreet.c index 439e236..e697690 100644 --- a/04_dynld_nostd/libgreet.c +++ b/04_dynld_nostd/libgreet.c @@ -1,5 +1,7 @@ // Copyright (c) 2020 Johannes Stoelp +#include + int gCalled = 0; const char* get_greet() { @@ -11,3 +13,11 @@ const char* get_greet2() { ++gCalled; return "Hello 2 from libgreet.so!"; } + +__attribute__((constructor)) static void libinit() { /* static -> generates R_X86_64_RELATIVE relocation */ + pfmt("libgreet.so: libinit\n"); +} + +__attribute__((destructor)) void libfini() { /* non static -> generates R_X86_64_64 relocation */ + pfmt("libgreet.so: libfini\n"); +} -- cgit v1.2.3 From 7da4d2b9cfa1d09991431f849d62a8a8d30f5e51 Mon Sep 17 00:00:00 2001 From: johannst Date: Mon, 26 Apr 2021 21:48:01 +0200 Subject: libgreet/main: updated comments --- 04_dynld_nostd/libgreet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to '04_dynld_nostd/libgreet.c') 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"); } -- cgit v1.2.3