From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: Leif Lindholm <leif.lindholm@linaro.org>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>,
"Gao, Liming" <liming.gao@intel.com>
Subject: Re: [PATCH] BaseTools/GenFw AARCH64: fix up GOT based relative relocations
Date: Wed, 4 Sep 2019 07:22:13 -0700 [thread overview]
Message-ID: <CAKv+Gu9DUOSggMYr+UbADN0Lm4AL570FggyTy-io1FW=jZnFdw@mail.gmail.com> (raw)
In-Reply-To: <CAKv+Gu95W4Su85CgPEOuGowCtB_xXpOjC4n9ZzC1fAn2AdQVAQ@mail.gmail.com>
On Wed, 4 Sep 2019 at 05:01, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
> On Wed, 4 Sep 2019 at 04:49, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> >
> > On Tue, Sep 03, 2019 at 09:17:33PM -0700, Ard Biesheuvel wrote:
> > > We take great care to avoid GOT based relocations in EDK2 executables,
> > > primarily because they are pointless - we don't care about things like
> > > the CoW footprint or relocations that target read-only sections, and so
> > > GOT entries only bloat the binary.
> > >
> > > However, in some cases (e.g., when building the relocatable PrePi SEC
> > > module in ArmVirtPkg with the CLANG38 toolchain), we may end up with
> > > some GOT based relocations nonetheless, which break the build since
> > > GenFw does not know how to deal with them.
> > >
> > > The relocations emitted in this case are ADRP/LDR instruction pairs
> > > that are annotated as GOT based, which means that it is the linker's
> > > job to emit the GOT entry and tag it with an appropriate dynamic
> > > relocation that ensures that the correct absolute value is stored into
> > > the GOT entry when the executable is loaded. This dynamic relocation
> > > not visible to GenFw, and so populating the PE/COFF relocation section
> > > for these entries is non-trivial.
> > >
> > > Since each ADRP/LDR pair refers to a single symbol that is local to the
> > > binary (given that shared libraries are not supported), we can actually
> > > convert the ADRP/LDR pair into an ADRP/ADD pair that produces the symbol
> > > address directly rather than loading it from memory. This leaves the
> > > GOT entry in the binary, but since it is now unused, it is no longer
> > > necessary to emit a PE/COFF relocation entry for it.
> > >
> > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> >
> > This is a very neat fix. My only concern is that I am not able to
> > reproduce the issue on my local Buster with clang7 (default). Is it
> > reproducible with clang8?
> >
>
> I managed to reproduce it on Ubuntu Bionic with clang 6. It may also
> be related to the version of ld.gold or the LLVM gold plugin.
>
> You should be able to test this patch for correctness by stripping the
> no-pie/no-pic options from the GCC5 command line, and checking any
> produced .dll with readelf -r to see whether any GOT based relocations
> were emitted, and whether the resulting binary still runs. I will do
> the same locally.
>
This worked for me, so I am fairly confident that this change is correct.
Once we have this change in, I'll double check whether the produced
CLANG38 ArmVirtQemuKernel images work as expected.
next prev parent reply other threads:[~2019-09-04 14:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-04 4:17 [PATCH] BaseTools/GenFw AARCH64: fix up GOT based relative relocations Ard Biesheuvel
2019-09-04 11:49 ` Leif Lindholm
2019-09-04 12:01 ` Ard Biesheuvel
2019-09-04 14:22 ` Ard Biesheuvel [this message]
2019-09-04 14:35 ` [edk2-devel] " Liming Gao
2019-09-04 15:37 ` Leif Lindholm
2019-09-04 16:10 ` Ard Biesheuvel
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-list 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='CAKv+Gu9DUOSggMYr+UbADN0Lm4AL570FggyTy-io1FW=jZnFdw@mail.gmail.com' \
--to=devel@edk2.groups.io \
/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