@@ -16,7 +16,9 @@ firmware-ldflags-y +=
ifndef FW_PIC
FW_PIC := y
endif
-
+ifeq ($(FW_PIC),y)
+FW_PIC := $(shell scripts/toolchain-check-pie $(CC))
+endif
ifeq ($(FW_PIC),y)
firmware-genflags-y += -DFW_PIC
firmware-asflags-y += -fpic
new file mode 100755
@@ -0,0 +1,22 @@
+#! /bin/bash
+
+CC=$1
+f=$(mktemp)
+mv ${f} ${f}.S
+f=${f}.S
+
+cat << EOF >${f}
+ .section .entry, "ax", %progbits
+ .align 3
+ .globl _start
+_start:
+ j _start
+EOF
+
+if ${CC} --version | head -n 1 | grep clang 2>&1 >/dev/null; then
+ ${CC} --target=riscv64 -fuse-ld=lld -mno-relax -nostdlib -fPIE -Wl,-pie ${f} -o /dev/null 2>/dev/null && echo y || echo n
+else
+ ${CC} -nostdlib -fPIE -Wl,-pie ${f} -o /dev/null 2>/dev/null && echo y || echo n
+fi
+
+rm ${f}
Signed-off-by: Xiang W <wxjstz@126.com> --- firmware/objects.mk | 4 +++- scripts/toolchain-check-pie | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 scripts/toolchain-check-pie