Message ID | 20210711022824.29915-5-jrtc27@jrtc27.com |
---|---|
State | Accepted |
Headers | show |
Series | Fully support standalone Clang/LLVM toolchains | expand |
在 2021-07-11星期日的 03:28 +0100,Jessica Clarke写道: > Bare-metal GNU ld does not support PIE, so if using it this will > result > in a failure to build. Instead, default to FW_PIC=n if not supported. > Note that an explicit FW_PIC=y is not overriden, to ensure the build > fails rather than silently producing a position-dependent binary. > > Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> > --- > Makefile | 3 +++ > firmware/objects.mk | 2 +- > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/Makefile b/Makefile > index 6b64205..ba06313 100644 > --- a/Makefile > +++ b/Makefile > @@ -106,6 +106,9 @@ ifndef PLATFORM_RISCV_XLEN > endif > endif > > +# Check whether the linker supports creating PIEs > +OPENSBI_LD_PIE := $(shell $(CC) -fPIE -nostdlib -Wl,-pie -x c > /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) For llvm, --target and -fuse-ld need to be added here. Otherwise, this will detect the host instead of what you want > + > # Setup list of objects.mk files > ifdef PLATFORM > platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then > find $(platform_src_dir) -iname "objects.mk" | sort -r; fi) > diff --git a/firmware/objects.mk b/firmware/objects.mk > index 3bc83cd..8da7ca3 100644 > --- a/firmware/objects.mk > +++ b/firmware/objects.mk > @@ -14,7 +14,7 @@ firmware-asflags-y += > firmware-ldflags-y += > > ifndef FW_PIC > -FW_PIC := y > +FW_PIC := $(OPENSBI_LD_PIE) > endif > > ifeq ($(FW_PIC),y) > -- > 2.31.0 > >
On 11 Jul 2021, at 05:03, Xiang W <wxjstz@126.com> wrote: > > 在 2021-07-11星期日的 03:28 +0100,Jessica Clarke写道: >> Bare-metal GNU ld does not support PIE, so if using it this will >> result >> in a failure to build. Instead, default to FW_PIC=n if not supported. >> Note that an explicit FW_PIC=y is not overriden, to ensure the build >> fails rather than silently producing a position-dependent binary. >> >> Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> >> --- >> Makefile | 3 +++ >> firmware/objects.mk | 2 +- >> 2 files changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/Makefile b/Makefile >> index 6b64205..ba06313 100644 >> --- a/Makefile >> +++ b/Makefile >> @@ -106,6 +106,9 @@ ifndef PLATFORM_RISCV_XLEN >> endif >> endif >> >> +# Check whether the linker supports creating PIEs >> +OPENSBI_LD_PIE := $(shell $(CC) -fPIE -nostdlib -Wl,-pie -x c >> /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) > For llvm, --target and -fuse-ld need to be added here. Otherwise, this > will detect the host instead of what you want This is patch 4/6, before LLVM support. Patch 5/6 updates this when adding LLVM support. Jess >> + >> # Setup list of objects.mk files >> ifdef PLATFORM >> platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then >> find $(platform_src_dir) -iname "objects.mk" | sort -r; fi) >> diff --git a/firmware/objects.mk b/firmware/objects.mk >> index 3bc83cd..8da7ca3 100644 >> --- a/firmware/objects.mk >> +++ b/firmware/objects.mk >> @@ -14,7 +14,7 @@ firmware-asflags-y += >> firmware-ldflags-y += >> >> ifndef FW_PIC >> -FW_PIC := y >> +FW_PIC := $(OPENSBI_LD_PIE) >> endif >> >> ifeq ($(FW_PIC),y) >> -- >> 2.31.0 >> >> > >
On Sun, Jul 11, 2021 at 10:29 AM Jessica Clarke <jrtc27@jrtc27.com> wrote: > > Bare-metal GNU ld does not support PIE, so if using it this will result > in a failure to build. Instead, default to FW_PIC=n if not supported. > Note that an explicit FW_PIC=y is not overriden, to ensure the build typo: overridden > fails rather than silently producing a position-dependent binary. > > Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> > --- > Makefile | 3 +++ > firmware/objects.mk | 2 +- > 2 files changed, 4 insertions(+), 1 deletion(-) > Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
On Sun, Jul 11, 2021 at 6:08 PM Bin Meng <bmeng.cn@gmail.com> wrote: > > On Sun, Jul 11, 2021 at 10:29 AM Jessica Clarke <jrtc27@jrtc27.com> wrote: > > > > Bare-metal GNU ld does not support PIE, so if using it this will result > > in a failure to build. Instead, default to FW_PIC=n if not supported. > > Note that an explicit FW_PIC=y is not overriden, to ensure the build > > typo: overridden I have fixed this typo at the time of merging this patch. > > > fails rather than silently producing a position-dependent binary. > > > > Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> > > --- > > Makefile | 3 +++ > > firmware/objects.mk | 2 +- > > 2 files changed, 4 insertions(+), 1 deletion(-) > > > > Reviewed-by: Bin Meng <bmeng.cn@gmail.com> > Tested-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Applied this patch to the riscv/opensbi repo. Thanks, Anup > > -- > opensbi mailing list > opensbi@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/opensbi
diff --git a/Makefile b/Makefile index 6b64205..ba06313 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,9 @@ ifndef PLATFORM_RISCV_XLEN endif endif +# Check whether the linker supports creating PIEs +OPENSBI_LD_PIE := $(shell $(CC) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Setup list of objects.mk files ifdef PLATFORM platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi) diff --git a/firmware/objects.mk b/firmware/objects.mk index 3bc83cd..8da7ca3 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -14,7 +14,7 @@ firmware-asflags-y += firmware-ldflags-y += ifndef FW_PIC -FW_PIC := y +FW_PIC := $(OPENSBI_LD_PIE) endif ifeq ($(FW_PIC),y)
Bare-metal GNU ld does not support PIE, so if using it this will result in a failure to build. Instead, default to FW_PIC=n if not supported. Note that an explicit FW_PIC=y is not overriden, to ensure the build fails rather than silently producing a position-dependent binary. Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> --- Makefile | 3 +++ firmware/objects.mk | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)