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

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 9 15:29:56 PST 2016


On Fri, Dec 9, 2016 at 3:14 PM, Petr Hosek <phosek at google.com> wrote:

> There is no DefinedRelative in ELF (or IMAGE_SYM_ABSOLUTE used to
> represent it).
>

 Sorry, I meant DefinedSynthetic with Section == nullptr. See for example
the symbols we create in Writer<ELFT>::addStartEndSymbols().

The image-relative symbols are represented as SHN_ABS in ELF.
>

I actually don't think there is a representation for image-relative symbols
in ELF, so we end up making something up. See the test
case lld/test/ELF/relocatable-symbols.s, we end up using SHN_UNDEF for
*_{start,end}.

Peter


>
> On Fri, Dec 9, 2016 at 2:56 PM Peter Collingbourne <peter at pcc.me.uk>
> wrote:
>
>> So it looks like this is a bug in either your linker script or the linker
>> script parser: we should end up with a DefinedRelative for _BASE. (I'm not
>> an expert in linker scripts, so I'm not sure exactly what the actual
>> semantics of your linker script are.)
>>
>> Peter
>>
>> On Fri, Dec 9, 2016 at 2:50 PM, Petr Hosek <phosek at google.com> wrote:
>>
>> Yes, that's correct.
>>
>> On Fri, Dec 9, 2016 at 2:48 PM Peter Collingbourne <peter at pcc.me.uk>
>> wrote:
>>
>> This appears to be the relevant part of the fuschia linker script:
>>
>> https://github.com/fuchsia-mirror/magenta/blob/
>> fad6801bd5c27e9887e912a3c6883dba463ec3d4/third_party/ulib/
>> musl/ldso/base.ld#L6
>>
>> From the comment it seems like you are intending to create an
>> image-relative symbol, no?
>>
>> Peter
>>
>> On Fri, Dec 9, 2016 at 2:43 PM, Petr Hosek <phosek at google.com> wrote:
>>
>> 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)
>>
>>
>>
>>
>> --
>> --
>> Peter
>>
>>
>>
>>
>> --
>> --
>> Peter
>>
>


-- 
-- 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161209/9bfbd2a6/attachment.html>


More information about the llvm-commits mailing list