[PATCH] D26133: [ELF] Allow relative relocations to absolute symbols in PIC

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 15:51:06 PST 2016


I've made a mistake in my test, the linker script is used as a
linker-script input file, not as a linker script, so the lld invocation
should be:

ld.lld -shared --gc-sections -o %t1 %t.script

That still fails with the same error. You cannot assign to . a
linker-script input file so your solution unfortunately doesn't work. Aside
from the "provide" semantics, it's the same as if it were an ET_REL input
file with no sections and just a symbol table entry:

.globl _BASE
.hidden _BASE
_BASE = 0

I tried that case as well and lld fails with the same error so it's not an
issue with linker script handling.

On Fri, Dec 9, 2016 at 4:27 PM Rafael Avila de Espindola <
rafael.espindola at gmail.com> wrote:

> Petr Hosek <phosek at google.com> writes:
>
> > On Thu, Dec 8, 2016 at 6:32 AM Rafael Avila de Espindola <
> > rafael.espindola at gmail.com> wrote:
> >
> >> It is entirely possible we just have another case where lld gets
> >> confused about a symbol being absolute or not. Can you provide the full
> >> original code in musl that fails with lld?
> >>
> >
> > I missed your response on the list. The original code that fails with lld
> > is pretty much equivalent to the new test case I've added:
> >
> > # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> > # RUN: echo "PROVIDE_HIDDEN(_BASE = 0);" > %t.script
> > # RUN: ld.lld -shared --gc-sections --script %t.script -o %t1 %t
> > # RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t1 |
> > FileCheck %s
> > # CHECK: 0000000000000000     0 NOTYPE  LOCAL  HIDDEN   ABS base
> >
> > .text
> > .globl _start
> > _start:
> >         lea _BASE(%rip),%rax
> >
> > Currently, lld fails with the following error:
> >
> > bin/ld.lld: error: gc-start.o:(.text.internal+0x3): relocation
> > R_X86_64_PC32 cannot refer to absolute symbol '_BASE' defined in
> (internal)
>
> And the error is correct. Given the name of the variable, I assume that
> what you are trying to do is:
>
> . = 0;
> PROVIDE_HIDDEN(_BASE = .);
> ....
>
> That way _BASE is known to be a position in the file.
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161212/397b8eb7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4843 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161212/397b8eb7/attachment.bin>


More information about the llvm-commits mailing list