<div dir="ltr">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:<div><br></div><div>ld.lld -shared --gc-sections -o %t1 %t.script</div><div><br></div><div>That still fails with the same error. You cannot assign to . a linker-script input file so your solution unfortunately doesn't work. <span style="color:rgb(33,33,33);font-size:13px">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:</span><div class="gmail_extra gmail_msg" style="color:rgb(33,33,33);font-size:13px"><br class="gmail_msg"></div><div class="gmail_extra gmail_msg" style="color:rgb(33,33,33)"><div class="gmail_extra gmail_msg" style="font-size:13px">.globl _BASE</div><div class="gmail_extra gmail_msg" style="font-size:13px">.hidden _BASE</div><div class="gmail_extra gmail_msg" style="font-size:13px">_BASE = 0</div><div class="gmail_extra gmail_msg" style="font-size:13px"><br></div><div class="gmail_extra gmail_msg">I tried that case as well and lld fails with the same error so it's not an issue with linker script handling.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 9, 2016 at 4:27 PM Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Petr Hosek <<a href="mailto:phosek@google.com" class="gmail_msg" target="_blank">phosek@google.com</a>> writes:<br class="gmail_msg">
<br class="gmail_msg">
> On Thu, Dec 8, 2016 at 6:32 AM Rafael Avila de Espindola <<br class="gmail_msg">
> <a href="mailto:rafael.espindola@gmail.com" class="gmail_msg" target="_blank">rafael.espindola@gmail.com</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
>> It is entirely possible we just have another case where lld gets<br class="gmail_msg">
>> confused about a symbol being absolute or not. Can you provide the full<br class="gmail_msg">
>> original code in musl that fails with lld?<br class="gmail_msg">
>><br class="gmail_msg">
><br class="gmail_msg">
> I missed your response on the list. The original code that fails with lld<br class="gmail_msg">
> is pretty much equivalent to the new test case I've added:<br class="gmail_msg">
><br class="gmail_msg">
> # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br class="gmail_msg">
> # RUN: echo "PROVIDE_HIDDEN(_BASE = 0);" > %t.script<br class="gmail_msg">
> # RUN: ld.lld -shared --gc-sections --script %t.script -o %t1 %t<br class="gmail_msg">
> # RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t1 |<br class="gmail_msg">
> FileCheck %s<br class="gmail_msg">
> # CHECK: 0000000000000000     0 NOTYPE  LOCAL  HIDDEN   ABS base<br class="gmail_msg">
><br class="gmail_msg">
> .text<br class="gmail_msg">
> .globl _start<br class="gmail_msg">
> _start:<br class="gmail_msg">
>         lea _BASE(%rip),%rax<br class="gmail_msg">
><br class="gmail_msg">
> Currently, lld fails with the following error:<br class="gmail_msg">
><br class="gmail_msg">
> bin/ld.lld: error: gc-start.o:(.text.internal+0x3): relocation<br class="gmail_msg">
> R_X86_64_PC32 cannot refer to absolute symbol '_BASE' defined in (internal)<br class="gmail_msg">
<br class="gmail_msg">
And the error is correct. Given the name of the variable, I assume that<br class="gmail_msg">
what you are trying to do is:<br class="gmail_msg">
<br class="gmail_msg">
. = 0;<br class="gmail_msg">
PROVIDE_HIDDEN(_BASE = .);<br class="gmail_msg">
....<br class="gmail_msg">
<br class="gmail_msg">
That way _BASE is known to be a position in the file.<br class="gmail_msg">
<br class="gmail_msg">
Cheers,<br class="gmail_msg">
Rafael<br class="gmail_msg">
</blockquote></div></div></div>