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

Bin Meng bmeng.cn at gmail.com
Sun Jul 11 06:05:16 PDT 2021


On Sun, Jul 11, 2021 at 10:29 AM Jessica Clarke <jrtc27 at jrtc27.com> wrote:
>
> 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, unlike GCC
> which will unconditionally forward it on and potentially result in a

It seems GCC driver does not unconditionally forward it to the linker, see:

$ riscv64-unknown-elf-gcc -fPIE -nostdlib -x c /dev/null -o /dev/null
2>&1 && echo y
/opt/riscv-unknown-elf/lib/gcc/riscv64-unknown-elf/10.1.0/../../../../riscv64-unknown-elf/bin/ld:
warning: cannot find entry symbol _start; defaulting to
0000000000010040
y

But

$ riscv64-unknown-elf-gcc -fPIE -nostdlib -Wl,-pie -x c /dev/null -o
/dev/null 2>&1 && echo y
/opt/riscv-unknown-elf/lib/gcc/riscv64-unknown-elf/10.1.0/../../../../riscv64-unknown-elf/bin/ld:
-pie not supported
collect2: error: ld returned 1 exit status

So regarding bare-metal triple, GCC driver and  clang driver behave
the same way. It's just GNU bare-metal ld does not support PIE, while
LLD supports.

So we need to revise the above commit message.

> linker error. However, LLD does support it, and manually forwarding it
> on works as desired, so do so to fully support FW_PIC with Clang and
> LLD.
>
> Signed-off-by: Jessica Clarke <jrtc27 at jrtc27.com>
> ---
>  firmware/objects.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Regards,
Bin



More information about the opensbi mailing list