diff mbox series

[v5] firmware: Detect whether the toolchain supports pie and automatically disable the FW_PIC option

Message ID 20210711041650.217653-1-wxjstz@126.com
State Not Applicable
Headers show
Series [v5] firmware: Detect whether the toolchain supports pie and automatically disable the FW_PIC option | expand

Commit Message

Xiang W July 11, 2021, 4:16 a.m. UTC
The previous version opensbi enable the FW_PIC option by default, but
not all toolchains can support pie. This makes some toolchain report erroes
when compiling. This patch whill check whether the toolchain supports FW_PIC
and disable FW_PIC.

Signed-off-by: Xiang W <wxjstz@126.com>
---
 firmware/objects.mk         | 4 ++++
 scripts/toolchain-check-pie | 7 +++++++
 2 files changed, 11 insertions(+)
 create mode 100755 scripts/toolchain-check-pie

Comments

Xiang W July 12, 2021, 1:27 a.m. UTC | #1
在 2021-07-11星期日的 12:16 +0800,Xiang W写道:
> The previous version opensbi enable the FW_PIC option by default, but
> not all toolchains can support pie. This makes some toolchain report
> erroes
> when compiling. This patch whill check whether the toolchain supports
> FW_PIC
> and disable FW_PIC.
> 
> Signed-off-by: Xiang W <wxjstz@126.com>
This patch can be discarded, Jessica Clarke has implemented this
feature
> ---
>  firmware/objects.mk         | 4 ++++
>  scripts/toolchain-check-pie | 7 +++++++
>  2 files changed, 11 insertions(+)
>  create mode 100755 scripts/toolchain-check-pie
> 
> diff --git a/firmware/objects.mk b/firmware/objects.mk
> index ce91c2f..f8ee394 100644
> --- a/firmware/objects.mk
> +++ b/firmware/objects.mk
> @@ -17,6 +17,10 @@ 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
> diff --git a/scripts/toolchain-check-pie b/scripts/toolchain-check-
> pie
> new file mode 100755
> index 0000000..559dc42
> --- /dev/null
> +++ b/scripts/toolchain-check-pie
> @@ -0,0 +1,7 @@
> +#! /bin/bash
> +
> +if ${1} --version | head -n 1 | grep clang 2>&1 >/dev/null; then
> +       printf "void _start() {}" | ${1} --target=riscv64 -fuse-
> ld=lld -mno-relax -nostdlib -fPIE -Wl,-pie -xc - -o /dev/null
> 2>/dev/null && echo y || echo n
> +else
> +       printf "void _start() {}" | ${1} -nostdlib -fPIE -Wl,-pie -xc
> - -o /dev/null 2>/dev/null && echo y || echo n
> +fi
diff mbox series

Patch

diff --git a/firmware/objects.mk b/firmware/objects.mk
index ce91c2f..f8ee394 100644
--- a/firmware/objects.mk
+++ b/firmware/objects.mk
@@ -17,6 +17,10 @@  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
diff --git a/scripts/toolchain-check-pie b/scripts/toolchain-check-pie
new file mode 100755
index 0000000..559dc42
--- /dev/null
+++ b/scripts/toolchain-check-pie
@@ -0,0 +1,7 @@ 
+#! /bin/bash
+
+if ${1} --version | head -n 1 | grep clang 2>&1 >/dev/null; then
+	printf "void _start() {}" | ${1} --target=riscv64 -fuse-ld=lld -mno-relax -nostdlib -fPIE -Wl,-pie -xc - -o /dev/null 2>/dev/null && echo y || echo n
+else
+	printf "void _start() {}" | ${1} -nostdlib -fPIE -Wl,-pie -xc - -o /dev/null 2>/dev/null && echo y || echo n
+fi