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

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 20:32:06 PST 2016

On Dec 12, 2016 19:57, "Petr Hosek" <phosek at google.com> wrote:

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.

I think Rafael's point is that if a is image relative it would require a
relative relocation to adjust the reference in the first file to the image
base. Since bfd is emitting the relative relocation and gold isn't, that
means that bfd is treating a as image relative and gold is treating it as

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161212/b35563ad/attachment.html>

More information about the llvm-commits mailing list