ref: 50b61aefb480b94a4a4dd69c6ffb05addc2912a3
parent: c324923f5d3acc16627e14e71f6ba0c75d8084d9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Sep 2 05:35:28 EDT 2018
[tests/libc] Detect pie compilers Some compilers have pie enabled by default, and it builds a wrong executable. This patch fixes the problem detecting if pie is enabled in the compiler. This patch is known to work only in OpenBSD, new patches about this are expected.
--- a/lib/c/target/amd64-sysv-openbsd/Makefile
+++ b/lib/c/target/amd64-sysv-openbsd/Makefile
@@ -4,7 +4,7 @@
include $(PROJECTDIR)/rules.mk
SYSNAME = amd64-sysv-openbsd
-SCC_CFLAGS = -g -fno-stack-protector -static -nostdinc -I$(INCDIR) -I$(INCDIR)/bits/amd64-sysv/ -I.
+SCC_CFLAGS = -g -nopie -fno-stack-protector -static -nostdinc -I$(INCDIR) -I$(INCDIR)/bits/amd64-sysv/ -I.
SYSOBJ = raise.o signal.o _sigaction.o
include syscall.mk
--- a/tests/libc/execute/cc.sh
+++ b/tests/libc/execute/cc.sh
@@ -37,5 +37,10 @@
lib=$root/lib/scc/${abi}-${sys}
obj=${1%.c}.o
-gcc -g -fno-stack-protector --freestanding -std=c99 -static -nostdinc -I$inc -I$arch_inc -c $1
-ld -g -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc -o $out
+if ! gcc -nopie 2>&1 | grep unrecogn >/dev/null
+then
+ pie=-nopie
+fi
+
+gcc -g $pie -fno-stack-protector --freestanding -std=c99 -static -nostdinc -I$inc -I$arch_inc -c $1
+ld -g $pie -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc -o $out