forked from libhugetlbfs/libhugetlbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ld.hugetlbfs
executable file
·130 lines (118 loc) · 3.33 KB
/
ld.hugetlbfs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /bin/bash
# Paranoid check to make sure we don't reinvoke ourselves, effectively
# making a fork()bomb
if [ -n "$LD_HUGETLBFS_RECURSION" ]; then
exit 99
fi
export LD_HUGETLBFS_RECURSION=1
### SET DEFAULT LDSCRIPT PATH HERE ###
if [ -z "$HUGETLB_LDSCRIPT_PATH" ]; then
# Assume this script is running from the libhugetlbfs source tree,
# and look for the ldscripts accordingly
HUGETLB_LDSCRIPT_PATH=$(dirname $(readlink $0))/ldscripts
fi
### SET CUSTOM_LDSCRIPTS HERE ###
if [ -z "$CUSTOM_LDSCRIPTS" ]; then
# Assume this script is running from the libhugetlbfs source tree,
# and set CUSTOM_LDSCRIPTS to default "yes"
CUSTOM_LDSCRIPTS="yes"
fi
# Try to figure out what's the underlying linker to invoke
if [ -z "$LD" ]; then
for x in $(which -a ld); do
if [ "$x" != "$0" ]; then
LD="$x"
break
fi
done
fi
i=0
while [ -n "$1" ]; do
arg="$1"
case "$arg" in
-m*)
EMU="${arg#-m}"
args[$i]="$arg"
i=$[i+1]
if [ -z "$EMU" ]; then
shift
EMU="$1"
args[$i]="$1"
i=$[i+1]
fi
;;
--hugetlbfs-link=*)
if [ -z "$HUGETLB_DEPRECATED_LINK" ]; then
echo -n "ld.hugetlbfs: --hugetlbfs-link is deprecated. " 1>&2
echo "Migrate to --hugetlbfs-align." 1>&2
fi
HTLB_LINK="${arg#--hugetlbfs-link=}"
;;
--hugetlbfs-script-path=*)
HUGETLB_LDSCRIPT_PATH="${arg#--hugetlbfs-script-path=}"
;;
--hugetlbfs-align)
HTLB_ALIGN="slice"
;;
--)
args=("${args[@]}" "$@")
break
;;
*)
args[$i]="$arg"
i=$[i+1]
;;
esac
shift
done
if [ -n "$HTLB_LINK" ]; then
if [ "$CUSTOM_LDSCRIPTS" == "no" ]; then
echo -n "ld.hugetlbfs: --hugetlbfs-link is not supported on this " 1>&2
echo "platform. Use --hugetlbfs-align instead." 1>&2
fi
HTLB_ALIGN="" # --hugetlbfs-link overrides --hugetlbfs-align
LDSCRIPT="$EMU.x$HTLB_LINK"
HTLBOPTS="-T${HUGETLB_LDSCRIPT_PATH}/${LDSCRIPT}"
fi
# if -m is not present on command line
if [ -z "$EMU" ]; then
if [ -n "$LDEMULATION" ]; then
# try env. variable
EMU="$LDEMULATION"
else
# pick first supported
EMU="$(ld -V | sed -n '/Supported emulations/{n;p}' | tr -d ' ')"
fi
fi
# if -m is not present on command line
if [ -z "$EMU" ]; then
if [ -n "$LDEMULATION" ]; then
# try env. variable
EMU="$LDEMULATION"
else
# pick first supported
EMU="$(ld -V | sed -n '/Supported emulations/{n;p}' | tr -d ' ')"
fi
fi
MB=$((1024*1024))
case "$EMU" in
elf32ppclinux|elf64ppc) HPAGE_SIZE=$((16*$MB)) SLICE_SIZE=$((256*$MB)) ;;
elf64lppc) HPAGE_SIZE=$((16*$MB)) SLICE_SIZE=$((256*$MB)) ;;
elf_i386|elf_x86_64) HPAGE_SIZE=$((4*$MB)) SLICE_SIZE=$HPAGE_SIZE ;;
elf_s390|elf64_s390) HPAGE_SIZE=$((1*$MB)) SLICE_SIZE=$HPAGE_SIZE ;;
armelf*_linux_eabi|aarch64elf*|aarch64linux*)
hpage_kb=$(cat /proc/meminfo | grep Hugepagesize: | awk '{print $2}')
HPAGE_SIZE=$((hpage_kb * 1024))
SLICE_SIZE=$HPAGE_SIZE ;;
esac
if [ "$HTLB_ALIGN" == "slice" ]; then
HTLBOPTS="-zcommon-page-size=$SLICE_SIZE -zmax-page-size=$SLICE_SIZE"
HTLBOPTS="$HTLBOPTS -lhugetlbfs"
# targeting the ARM platform one needs to explicitly set the text segment offset
# otherwise it will be NULL.
case "$EMU" in
armelf*_linux_eabi|aarch64elf*|aarch64linux*) HTLBOPTS="$HTLBOPTS -Ttext-segment=$SLICE_SIZE" ;;
elf_i386) HTLBOPTS="$HTLBOPTS -Ttext-segment=0x08000000" ;;
esac
fi
${LD} "${args[@]}" ${HTLBOPTS}