Thread (24 messages) 24 messages, 4 authors, 2021-07-21
STALE1799d

[PATCH v4 3/5] firmware: Explicitly pass -pie to the linker, not just the driver

From: Bin Meng <hidden>
Date: 2021-07-10 08:53:00

On Sat, Jul 10, 2021 at 10:56 AM Bin Meng [off-list ref] wrote:
On Sat, Jul 10, 2021 at 3:35 AM Jessica Clarke [off-list ref] wrote:
quoted
When using Clang with a bare-metal triple, -pie does not get passed to
the linker as it's not normally a thing that makes sense. However, in
our case it is, and manually forwarding it on works as desired, so do so
to fully support FW_PIC with Clang, including when linking with LLD.
---
 firmware/objects.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/firmware/objects.mk b/firmware/objects.mk
index ce91c2f..3bc83cd 100644
--- a/firmware/objects.mk
+++ b/firmware/objects.mk
@@ -21,7 +21,7 @@ ifeq ($(FW_PIC),y)
 firmware-genflags-y += -DFW_PIC
 firmware-asflags-y  += -fpic
 firmware-cflags-y   += -fPIE -pie
-firmware-ldflags-y  +=  -Wl,--no-dynamic-linker
+firmware-ldflags-y  +=  -Wl,--no-dynamic-linker -Wl,-pie
 endif
Does this manual forwarding also work for GNU ld? If so, I think we
don't need to detect bare-metal triple and turn off FW_PIC in
Makefile?
I just built a riscv64-unknown-elf-gcc toolchain and used it to build
the current HEAD of opensbi/master. Indeed it's broken that pie is not
supported with the bare-metal triple.

The GNU ld simply complains:

 ELF       platform/generic/firmware/payloads/test.elf
/opt/riscv-unknown-elf/lib/gcc/riscv64-unknown-elf/10.1.0/../../../../riscv64-unknown-elf/bin/ld.bfd:
-pie not supported

Regards,
Bin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help