Skip to content

Commit

Permalink
rcutorture: Make use of nolibc when available
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Willy Tarreau authored and Paul E. McKenney committed Nov 9, 2018
1 parent 66b6f75 commit b94ec36
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tools/testing/selftests/rcutorture/bin/mkinitrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ cd $D
mkdir -p initrd
cd initrd
cat > init.c << '___EOF___'
#ifndef NOLIBC
#include <unistd.h>
#include <sys/time.h>
#endif
volatile unsigned long delaycount;
Expand Down Expand Up @@ -113,7 +115,21 @@ int main(int argc, int argv[])
return 0;
}
___EOF___
${CROSS_COMPILE}gcc -s -static -Os -o init init.c

# build using nolibc on supported archs (smaller executable) and fall
# back to regular glibc on other ones.
if echo -e "#if __x86_64__||__i386__||__i486__||__i586__||__i686__" \
"||__ARM_EABI__||__aarch64__\nyes\n#endif" \
| ${CROSS_COMPILE}gcc -E -nostdlib -xc - \
| grep -q '^yes'; then
# architecture supported by nolibc
${CROSS_COMPILE}gcc -fno-asynchronous-unwind-tables -fno-ident \
-nostdlib -include ../bin/nolibc.h -lgcc -s -static -Os \
-o init init.c
else
${CROSS_COMPILE}gcc -s -static -Os -o init init.c
fi

rm init.c
echo "Done creating a statically linked C-language initrd"

Expand Down

0 comments on commit b94ec36

Please sign in to comment.