Skip to content

Commit b94ec36

Browse files
wtarreauPaul E. McKenney
authored andcommitted
rcutorture: Make use of nolibc when available
This reduces the size of the init executable from ~800 kB to ~800 bytes on x86_64. This is only implemented for x86_64, i386, arm and arm64. Others not tested. Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 66b6f75 commit b94ec36

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎tools/testing/selftests/rcutorture/bin/mkinitrd.sh‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ cd $D
8282
mkdir -p initrd
8383
cd initrd
8484
cat > init.c << '___EOF___'
85+
#ifndef NOLIBC
8586
#include <unistd.h>
8687
#include <sys/time.h>
88+
#endif
8789
8890
volatile unsigned long delaycount;
8991
@@ -113,7 +115,21 @@ int main(int argc, int argv[])
113115
return 0;
114116
}
115117
___EOF___
116-
${CROSS_COMPILE}gcc -s -static -Os -o init init.c
118+
119+
# build using nolibc on supported archs (smaller executable) and fall
120+
# back to regular glibc on other ones.
121+
if echo -e "#if __x86_64__||__i386__||__i486__||__i586__||__i686__" \
122+
"||__ARM_EABI__||__aarch64__\nyes\n#endif" \
123+
| ${CROSS_COMPILE}gcc -E -nostdlib -xc - \
124+
| grep -q '^yes'; then
125+
# architecture supported by nolibc
126+
${CROSS_COMPILE}gcc -fno-asynchronous-unwind-tables -fno-ident \
127+
-nostdlib -include ../bin/nolibc.h -lgcc -s -static -Os \
128+
-o init init.c
129+
else
130+
${CROSS_COMPILE}gcc -s -static -Os -o init init.c
131+
fi
132+
117133
rm init.c
118134
echo "Done creating a statically linked C-language initrd"
119135

0 commit comments

Comments
 (0)