aboutsummaryrefslogtreecommitdiff
path: root/04_dynld_nostd/Makefile
blob: e72dde80569e67ceae5fb3789e35a5a2b65c1d13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright (c) 2020 Johannes Stoelp

COMMON_CFLAGS := -g -O0 -Wall -Wextra \
                 -I../lib/include     \
                 -nostartfiles -nodefaultlibs

run: main
	./$<

main: dynld.so libgreet.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 $@                                   \
	    $(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 $@

libgreet.so: libgreet.c
	@# For now ew only add support for ELF hash tables (DT_HASH).
	@# Therefore we specify the `hash-style` below.
	gcc -o $@                 \
	    $(COMMON_CFLAGS)      \
	    -fPIC -shared         \
	    -Wl,--hash-style=sysv \
	    $^

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