-
Notifications
You must be signed in to change notification settings - Fork 16
/
ld.in
84 lines (72 loc) · 2.27 KB
/
ld.in
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
set -e
fail () { echo >&2 "stunt ld: $*"; exit 127; }
noshift () { fail "no arg for $a"; }
ALLARGS=$*
CC=${REALCC:-cc}
LD=${LD:-ld}
OBJCOPY=${OBJCOPY:-objcopy}
LIBC=false
while [ $# != 0 ]; do
a=$1; shift
case "$a" in
-m)
march="$1"; shift || noshift
outargs="$outargs $a $march"
;;
-o)
outfile="$1"; shift || noshift
;;
--as-needed|--no-as-needed)
;;
--stunt-intermediate)
inter1="$1"; shift || noshift
inter2="$1"; shift || noshift
;;
-lgcc|-lgcc_s)
# added later
;;
-L*|-l*|-*|--whole-archive|--no-whole-archive)
outargs="$outargs $a"
;;
*crt1.o|*crti.o|*crtbegin.o)
CRTS="${CRTS} $a"
;;
*crtend.o|*crtn.o)
CRTE="${CRTE} $a"
;;
*.o|*.ro|*.a)
INFILES="${INFILES} $a"
;;
*)
outargs="$outargs $a"
;;
esac
done
if [ x"$outfile" = x ]; then outfile=a.out; fi
# -lrt not always needed TODO work out at build time
UNAME=$(uname -s)
[ ${UNAME} = Linux ] && DLFLAG="-ldl -lrt"
LIBRARY_PATH=@PATH@/hostlib/lib
RUMPCLIENT="-L${LIBRARY_PATH} -Wl,-R${LIBRARY_PATH} -lrumpclient ${DLFLAG}"
LIBC=@PATH@/rump/lib/libc.a
TMPFILE1=$(mktemp /tmp/XXXXXXXXXXX).o
TMPFILE2=$(mktemp /tmp/XXXXXXXXXXX).o
TMPFILE3=$(mktemp /tmp/XXXXXXXXXXX).o
TMPFILE4=$(mktemp /tmp/XXXXXXXXXXX).o
${CC} ${LDFLAGS} -Wl,-r -nostdlib ${INFILES} -o ${TMPFILE1}
${OBJCOPY} --redefine-syms=@PATH@/host.map ${TMPFILE1} ${TMPFILE2}
${CC} ${LDFLAGS} -Wl,-r ${TMPFILE2} @PATH@/netbsd_init.o -nostdlib ${LIBC} -o ${TMPFILE3} 2>/dev/null
${OBJCOPY} --redefine-syms=@PATH@/namespace.map ${TMPFILE3}
${OBJCOPY} --redefine-syms=@PATH@/extra.map ${TMPFILE3}
${OBJCOPY} --redefine-syms=@PATH@/rump.map ${TMPFILE3}
${OBJCOPY} --redefine-syms=@PATH@/weakasm.map ${TMPFILE3}
${OBJCOPY} --redefine-syms=@PATH@/readwrite.map ${TMPFILE3}
${OBJCOPY} --redefine-syms=@PATH@/emul.map ${TMPFILE3}
${OBJCOPY} --redefine-syms=@PATH@/netbsd.map ${TMPFILE3}
${CC} ${LDFLAGS} -Wl,-r -nostdlib -Wl,-dc ${TMPFILE3} @PATH@/readwrite.o -o ${TMPFILE4} 2>/dev/null
${OBJCOPY} --redefine-syms=@PATH@/errno.map ${TMPFILE4}
${OBJCOPY} -w --localize-symbol='*' ${TMPFILE4}
${OBJCOPY} -w --globalize-symbol='_netbsd_*' ${TMPFILE4}
${CC} ${LDFLAGS} ${TMPFILE4} @PATH@/emul.o @PATH@/rumpclient.o @PATH@/remoteinit.o ${RUMPCLIENT} -o ${outfile}
rm ${TMPFILE1} ${TMPFILE2} ${TMPFILE3} ${TMPFILE4}