From: Xiang W <wxjstz@126.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v4 3/5] firmware: Explicitly pass -pie to the linker, not just the driver
Date: Sun, 11 Jul 2021 02:27:26 +0800 [thread overview]
Message-ID: <fc4911e90817a414ae990e00935f4c9956a2c466.camel@126.com> (raw)
In-Reply-To: <A567F574-6592-43A1-989D-E209D7B1BD0E@jrtc27.com>
? 2021-07-10???? 19:10 +0100?Jessica Clarke???
> On 10 Jul 2021, at 19:07, Xiang W <wxjstz@126.com> wrote:
> >
> > ? 2021-07-10???? 20:26 +0530?Anup Patel???
> > > On Sat, Jul 10, 2021 at 7:13 PM Bin Meng <bmeng.cn@gmail.com>
> > > wrote:
> > > >
> > > > On Sat, Jul 10, 2021 at 9:38 PM Anup Patel
> > > > <anup@brainfault.org>
> > > > wrote:
> > > > >
> > > > > On Sat, Jul 10, 2021 at 6:13 PM Bin Meng <bmeng.cn@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > Hi Anup,
> > > > > >
> > > > > > On Sat, Jul 10, 2021 at 6:42 PM Anup Patel
> > > > > > <anup@brainfault.org> wrote:
> > > > > > >
> > > > > > > Hi Bin,
> > > > > > >
> > > > > > > On Sat, Jul 10, 2021 at 2:23 PM Bin Meng <
> > > > > > > bmeng.cn at gmail.com>
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > On Sat, Jul 10, 2021 at 10:56 AM Bin Meng <
> > > > > > > > bmeng.cn at gmail.com> wrote:
> > > > > > > > >
> > > > > > > > > On Sat, Jul 10, 2021 at 3:35 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. 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
> > > > > > >
> > > > > > > The firmware/objects.mk is doing the following:
> > > > > > >
> > > > > > > ifndef FW_PIC
> > > > > > > FW_PIC := y
> > > > > > > endif
> > > > > > >
> > > > > > > Instead of above, we should set FW_PIC=y only when the
> > > > > > > underlying
> > > > > > > toolchain supports pie.
> > > > > > >
> > > > > >
> > > > > > Agree.
> > > > > >
> > > > > > > We need a patch for this to be merged before we can merge
> > > > > > > this
> > > > > > > series. Can you send such a patch ? If not then I can
> > > > > > > send
> > > > > > > it.
> > > > > >
> > > > > > Do you have some reliable ways to check whether a toolchain
> > > > > > supports PIE?
> > > > >
> > > > > How about checking "-linux-" in CROSS_COMPILE prefix ? If
> > > > > it's
> > > > > available then
> > > > > we set FW_PIC=y else we set FW_PIC=n.
> > > >
> > > > That works for cross-compile toolchains. But how about native
> > > > toolchains (building OpenSBI on a RISC-V machine)?
> > >
> > > Yes, it will not work for native compilation of OpenSBI.
> > >
> > > >
> > > > > I did not find any info in the "${CROSS_COMPILE}gcc -v"
> > > > > output.
> > > >
> > > > Me neither.
> > > >
> > > > >
> > > > > Maybe also add some comment in objects.mk that GCC bare-metal
> > > > > toolchain
> > > > > does not have PIE enabled.
> > > >
> > > > Or we can just document if using bare-metal toolchain FW_PIC
> > > > has to
> > > > be
> > > > set to n in the build.
> > >
> > > Sounds good.
> > >
> > > We should document it under section "Required Toolchain" of top-
> > > level
> > > README.md. Basically, we prefer toolchains with PIE support and
> > > for
> > > toolchains not having PIE users have to pass the "FW_PIC=n"
> > > option.
> > >
> > > Also, we should replace references of bare-metal toolchain prefix
> > > with
> > > linux toolchain prefix everywhere in documentation.
> > >
> > > Regards,
> > > Anup
> > We can add the following code to the makefile to detect pie support
> >
> > pie_support=$(shell $(CC) -nostdlib -fPIE -Wl,-pie /dev/null
> > 2>/dev/null && echo y || echo n)
>
> That doesn?t work, /dev/null is not a valid object file so this will
> always fail with any toolchain.
I have tested it, so that the following commands no longer report
errors
CROSS_COMPILE=riscv64-unknown-elf- make PLATFORM=generic
Xiang W
>
> Jess
next prev parent reply other threads:[~2021-07-10 18:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-09 19:34 [PATCH v4 0/5] Fully support standalone Clang/LLVM toolchains Jessica Clarke
2021-07-09 19:34 ` [PATCH v4 1/5] fw_base: Don't mark fw_platform_init as both global and weak Jessica Clarke
2021-07-10 2:30 ` Bin Meng
2021-07-09 19:34 ` [PATCH v4 2/5] fw_base: Put data in .data rather than .text Jessica Clarke
2021-07-10 2:52 ` Bin Meng
2021-07-09 19:34 ` [PATCH v4 3/5] firmware: Explicitly pass -pie to the linker, not just the driver Jessica Clarke
2021-07-10 2:56 ` Bin Meng
2021-07-10 8:53 ` Bin Meng
2021-07-10 10:41 ` Anup Patel
2021-07-10 12:43 ` Bin Meng
2021-07-10 13:38 ` Anup Patel
2021-07-10 13:43 ` Bin Meng
2021-07-10 14:56 ` Anup Patel
2021-07-10 18:07 ` Xiang W
2021-07-10 18:10 ` Jessica Clarke
2021-07-10 18:27 ` Xiang W [this message]
2021-07-10 18:34 ` Jessica Clarke
2021-07-09 19:34 ` [PATCH v4 4/5] Makefile: Support building with Clang and LLVM binutils Jessica Clarke
2021-07-10 13:23 ` Bin Meng
2021-07-11 13:53 ` Bin Meng
2021-07-21 5:49 ` Jessica Clarke
2021-07-21 7:40 ` Bin Meng
2021-07-09 19:34 ` [PATCH v4 5/5] Drop dependency on libgcc by importing part of FreeBSD's libquad Jessica Clarke
2021-07-09 21:00 ` [PATCH v4 0/5] Fully support standalone Clang/LLVM toolchains Jessica Clarke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fc4911e90817a414ae990e00935f4c9956a2c466.camel@126.com \
--to=wxjstz@126.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox