[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 19:57:41 PST 2016

On Mon, Dec 12, 2016 at 7:12 PM Rafael Avila de Espindola <
rafael.espindola at gmail.com> wrote:

> But as a quick experiment, a single file with just
> .global a
> .hidden a
> a = 42
> .quad a
> has no relocations at all, with both mc and gas. That means that the
> .quad is always 42. On the other hand, the file has
>  000000000000002a     0 NOTYPE  GLOBAL HIDDEN   ABS a
> which is contradictory if ABS means image relative. Is that a bug in gas
> and mc?
> If we now use two files, one with
>         .quad a
> and another with
>         .global a
>         .hidden a
>         a = 42
> gold will produce a file with no relocations. BFD will produce a
> R_X86_64_RELATIVE, but it is the odd one here.

You don't need a dynamic relocation in this case because the symbol is
hidden (which is the same as if it was local) as the address can be can be
computed statically at link time (relative to the image base). If you
remove .hidden, then both gas and mc generate relocation as expected
because now the address cannot be determined at link time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161213/752beee9/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/20161213/752beee9/attachment.bin>

More information about the llvm-commits mailing list