[PATCH v6] elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASE
H.J. Lu
hjl.tools@gmail.com
Sat Mar 6 01:00:23 GMT 2021
On Fri, Mar 5, 2021 at 4:11 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Mar 05, 2021 at 10:26:35AM -0800, H.J. Lu wrote:
> > On Fri, Mar 5, 2021 at 5:57 AM Alan Modra <amodra@gmail.com> wrote:
> > > This doesn't look like the right place to set up a reference to
> > > __executable_start. Doing so in a new check_relocs in pei-x86_64.c
> > > that tests for an ELF output would be better. I'm not suggesting that
> > > you run over relocs looking for R_AMD64_IMAGEBASE, that could be done
> > > but seems unnecessary.
> >
> > check_relocs is too late. We need to do it in load_symbols (). Otherwise,
> > __executable_start won't be defined. I added pex64_link_add_symbols to
> > do it.
>
> Ah, I was forgetting that check_relocs now runs much later. Even so,
> I would have thought that the PROVIDE would define the symbol? The
> question is academic, I'm happy with pex64_link_add_symbols.
>
> > Here is the v5 patch. OK for master?
>
> OK with three further changes.
> 1) The R_AMD64_IMAGEBASE handling should to be inside the
> output_bfd == NULL block. It is wrong to apply the image base
> adjustment to the section for relocatable linking. Doing so would
> effectively change the reloc addend.
Fixed.
> 2) I worry about the abort, which I think you might hit if trying to
> link PE objects into a pie. One possible fix would be to change
> the bfd_link_pde in pex64_link_add_symbols to !bfd_link_relocatable.
> That might just be sweeping a problem under the rug, so an
> alternative fix would be to remove the abort and instead return
> with bfd_reloc_dangerous. Either fix is fine with me.
Changed to return bfd_reloc_dangerous.
> 3) No need to check for bfd_target_elf_flavour in set_output_arch.
>
The check is needed for
./ld-new -z norelro
-L/export/gnu/import/git/gitlab/x86-binutils/ld/testsuite/ld-elf -T
pr21884.t -o tmpdir/dump tmpdir/pr21884a.o tmpdir/pr21884b.o
Executing on host: sh -c {./ld-new -z norelro
-L/export/gnu/import/git/gitlab/x86-binutils/ld/testsuite/ld-elf -T
pr21884.t -o tmpdir/dump tmpdir/pr21884a.o tmpdir/pr21884b.o 2>&1}
/dev/null dump.tmp (timeout = 300)
spawn [open ...]^M
sh: line 1: 1894243 Segmentation fault (core dumped) ./ld-new -z
norelro -L/export/gnu/import/git/gitlab/x86-binutils/ld/testsuite/ld-elf
-T pr21884.t -o tmpdir/dump tmpdir/pr21884a.o tmpdir/pr21884b.o 2>&1
failed with: <sh: line 1: 1894243 Segmentation fault (core
dumped) ./ld-new -z norelro
-L/export/gnu/import/git/gitlab/x86-binutils/ld/testsuite/ld-elf -T
pr21884.t -o tmpdir/dump tmpdir/pr21884a.o tmpdir/pr21884b.o 2>&1>, no
expected output
FAIL: ld-elf/pr21884
This is the patch I am checking in.
Thanks.
--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v6-0001-elf-x86-64-Subtract-__ImageBase-for-R_AMD64_IMAGE.patch
Type: text/x-patch
Size: 20543 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20210305/3bc508b5/attachment-0001.bin>
More information about the Binutils
mailing list