diff mbox series

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

Message ID 20210710202710.192820-1-wxjstz@126.com
State Superseded
Headers show
Series firmware: Detect whether the toolchain supports pie and automatically disable the FW_PIC option | expand

Commit Message

Xiang W July 10, 2021, 8:27 p.m. UTC
Signed-off-by: Xiang W <wxjstz@126.com>
---
 firmware/objects.mk         | 4 +++-
 scripts/toolchain-check-pie | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100755 scripts/toolchain-check-pie

Comments

Bin Meng July 11, 2021, 1:56 a.m. UTC | #1
On Sun, Jul 11, 2021 at 4:27 AM Xiang W <wxjstz@126.com> wrote:

Please write something in the commit message to explain why are we doing this.

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

Please append a patch version in the email title. This way it's easy
to know which patch is the latest version.

> diff --git a/firmware/objects.mk b/firmware/objects.mk
> index ce91c2f..020e1a9 100644
> --- a/firmware/objects.mk
> +++ b/firmware/objects.mk
> @@ -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
> diff --git a/scripts/toolchain-check-pie b/scripts/toolchain-check-pie
> new file mode 100755
> index 0000000..779c0ee
> --- /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
> +       echo 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
> +       echo void _start\(\) \{\} | ${1} -nostdlib -fPIE -Wl,-pie -xc - -o /dev/null 2>/dev/null && echo y || echo n
> +fi

Regards,
Bin
diff mbox series

Patch

diff --git a/firmware/objects.mk b/firmware/objects.mk
index ce91c2f..020e1a9 100644
--- a/firmware/objects.mk
+++ b/firmware/objects.mk
@@ -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
diff --git a/scripts/toolchain-check-pie b/scripts/toolchain-check-pie
new file mode 100755
index 0000000..779c0ee
--- /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
+	echo 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
+	echo void _start\(\) \{\} | ${1} -nostdlib -fPIE -Wl,-pie -xc - -o /dev/null 2>/dev/null && echo y || echo n
+fi