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/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 04_dynld_nostd/main.c (limited to '04_dynld_nostd/main.c') diff --git a/04_dynld_nostd/main.c b/04_dynld_nostd/main.c new file mode 100644 index 0000000..ca250ef --- /dev/null +++ b/04_dynld_nostd/main.c @@ -0,0 +1,18 @@ +// Copyright (c) 2020 Johannes Stoelp + +#include +#include + +// API of `libgreet.so`. +extern const char* get_greet(); +extern const char* get_greet2(); + +void _start() { + pfmt("Running _start() @ %s\n", __FILE__); + + // Call function from libgreet.so -> generates PLT entry. + pfmt("get_greet() -> %s\n", get_greet()); + pfmt("get_greet2() -> %s\n", get_greet2()); + + _exit(0); +} -- 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/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to '04_dynld_nostd/main.c') diff --git a/04_dynld_nostd/main.c b/04_dynld_nostd/main.c index ca250ef..a787158 100644 --- a/04_dynld_nostd/main.c +++ b/04_dynld_nostd/main.c @@ -6,13 +6,17 @@ // API of `libgreet.so`. extern const char* get_greet(); extern const char* get_greet2(); +extern int gCalled; void _start() { pfmt("Running _start() @ %s\n", __FILE__); - // Call function from libgreet.so -> generates PLT entry. + // Call function from libgreet.so -> generates PLT relocations. pfmt("get_greet() -> %s\n", get_greet()); pfmt("get_greet2() -> %s\n", get_greet2()); + // Reference global variable from libgreet.so -> generates RELA relocation. + pfmt("libgreet.so called %d times\n", gCalled); + _exit(0); } -- cgit v1.2.3 From 6f7efd7075fcea29922536d8fb1ad810182437cd Mon Sep 17 00:00:00 2001 From: johannst Date: Sun, 25 Apr 2021 23:32:40 +0200 Subject: main: remove exit syscall --- 04_dynld_nostd/main.c | 2 -- 1 file changed, 2 deletions(-) (limited to '04_dynld_nostd/main.c') diff --git a/04_dynld_nostd/main.c b/04_dynld_nostd/main.c index a787158..709fad0 100644 --- a/04_dynld_nostd/main.c +++ b/04_dynld_nostd/main.c @@ -17,6 +17,4 @@ void _start() { // Reference global variable from libgreet.so -> generates RELA relocation. pfmt("libgreet.so called %d times\n", gCalled); - - _exit(0); } -- 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/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to '04_dynld_nostd/main.c') 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 -#include // 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); } -- cgit v1.2.3