diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-04-17 23:47:17 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-04-17 23:47:17 +0200 |
commit | 287f736e614a2931f57e9aabf42105e3cf3e8992 (patch) | |
tree | bfc6c69d4b09b37706a1ef9ae62dc98fe11c714f /04_dynld_nostd/Makefile | |
parent | 4fa1f03150ddaa56cf58b11809182ef4ef2b6abd (diff) | |
download | dynld-287f736e614a2931f57e9aabf42105e3cf3e8992.tar.gz dynld-287f736e614a2931f57e9aabf42105e3cf3e8992.zip |
04: able to map dependency & resolve reolcs and execture main program (initial commit)
Diffstat (limited to '04_dynld_nostd/Makefile')
-rw-r--r-- | 04_dynld_nostd/Makefile | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/04_dynld_nostd/Makefile b/04_dynld_nostd/Makefile new file mode 100644 index 0000000..8cd9d35 --- /dev/null +++ b/04_dynld_nostd/Makefile @@ -0,0 +1,60 @@ +# Copyright (c) 2020 Johannes Stoelp + +COMMON_CFLAGS := -g -O0 -Wall -Wextra \ + -I../lib/include \ + -nostartfiles -nodefaultlibs + +run: main + ./$< + +main: dynld.so main.c ../lib/libcommon.a + @# For now ew only add support for ELF hash tables (DT_HASH). + @# Therefore we specify the `hash-style` below. + gcc -o libgreet.so \ + $(COMMON_CFLAGS) \ + -fPIC -shared \ + -Wl,--hash-style=sysv \ + libgreet.c + + @if readelf -W -S libgreet.so | grep plt >& /dev/null; then \ + echo "ERROR: libgreet.so contains PLT while we don't support relocation calls in libgreet.so!"; \ + echo " All function calls in libgreet.so must be statically resolved!"; \ + exit 1; \ + fi + + @# For now ew only add support for ELF hash tables (DT_HASH). + @# Therefore we specify the `hash-style` below. + 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 $@ + +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 -W -S $@ | grep plt >& /dev/null; then \ + echo "ERROR: $@ contains PLT while we don't support relocation calls in $@!"; \ + echo " All function calls in $@ must be statically resolved!"; \ + exit 1; \ + fi + +../lib/libcommon.a: + make -C ../lib + +clean: + rm -f main libgreet.so + rm -f dynld.so |