aboutsummaryrefslogtreecommitdiff
path: root/04_dynld_nostd/Makefile
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-04-28 23:08:45 +0200
committerjohannst <johannes.stoelp@gmail.com>2021-04-28 23:08:45 +0200
commitd367355eb4c3569d422034b69737d8dc7022e13e (patch)
treef9f6768228235f4712466d65edeb0b745d904833 /04_dynld_nostd/Makefile
parentcf97ecd5b52c2f7a8953fd1674742d46fd15418a (diff)
parentfc137e7d0263a0fe908ca1a150e34a9c8b9902d4 (diff)
downloaddynld-d367355eb4c3569d422034b69737d8dc7022e13e.tar.gz
dynld-d367355eb4c3569d422034b69737d8dc7022e13e.zip
Merge branch 'dev04'
Diffstat (limited to '04_dynld_nostd/Makefile')
-rw-r--r--04_dynld_nostd/Makefile63
1 files changed, 63 insertions, 0 deletions
diff --git a/04_dynld_nostd/Makefile b/04_dynld_nostd/Makefile
new file mode 100644
index 0000000..e4dceb1
--- /dev/null
+++ b/04_dynld_nostd/Makefile
@@ -0,0 +1,63 @@
+# Copyright (c) 2020 Johannes Stoelp
+
+COMMON_CFLAGS := -g -O0 -Wall -Wextra \
+ -I../lib/include \
+ -nostartfiles -nodefaultlibs
+
+run: main
+ ./$<
+
+# Build the example user program.
+#
+# We explicitly set the dynamic linker to `dynld.so` and use the ELF hash table
+# (DT_HASH), as we didn't implement support for the GNU hash table in our
+# dynamic linker.
+main: dynld.so libgreet.so main.c ../lib/libcommon.a
+ gcc -o $@ \
+ $(COMMON_CFLAGS) \
+ -L$(CURDIR) -lgreet \
+ -Wl,--dynamic-linker=$(CURDIR)/dynld.so \
+ -Wl,--hash-style=sysv \
+ -no-pie \
+ $(filter %.c %.a, $^)
+
+ #readelf -W --dynamic $@
+ #readelf -W --program-headers $@
+ #objdump --disassemble -j .plt -M intel $@
+ #objdump --disassemble=_start -M intel $@
+
+# Build the example shared library.
+#
+# We explicitly use the ELF hash table (DT_HASH), as we didn't implement
+# support for the GNU hash table in our dynamic linker.
+libgreet.so: libgreet.c
+ gcc -o $@ \
+ $(COMMON_CFLAGS) \
+ -fPIC -shared \
+ -Wl,--hash-style=sysv \
+ $^
+
+# Build the dynamic linker.
+#
+# We assert that the dynamic linker doesn't contain any relocations as we
+# didn't implement support to resolve its own relocations.
+dynld.so: dynld.S dynld.c ../lib/libcommon.a
+ gcc -o $@ \
+ $(COMMON_CFLAGS) \
+ -fPIC -static-pie \
+ -fvisibility=hidden \
+ -Wl,--entry=dl_start \
+ -Wl,--no-allow-shlib-undefined \
+ $^
+
+ @if ! readelf -r $@ | grep 'There are no relocations in this file' >& /dev/null; then \
+ echo "ERROR: $@ contains relocations while we don't support relocations in $@!"; \
+ exit 1; \
+ fi
+
+../lib/libcommon.a:
+ make -C ../lib
+
+clean:
+ rm -f main libgreet.so
+ rm -f dynld.so