This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Better handling of _GLOBAL_OFFSET_TABLE_
AbandonedPublic

Authored by evgeny777 on Jun 21 2017, 9:17 AM.

Details

Summary

We have several pieces of assembly code which have something like following

.Lablel:
    _GLOBAL_OFFSET_TABLE_ - .Label

it works fine with ld/gold, but fails to link with lld (relocation cannot refer to absolute symbol)

Also this patch sets correct value for _GLOBAL_OFFSET_TABLE_, this is why one of existing test changed.

Diff Detail

Event Timeline

evgeny777 created this revision.Jun 21 2017, 9:17 AM
ruiu edited edge metadata.Jun 21 2017, 9:22 AM

Do you have any program that actually needs this change?

ELF/Symbols.h
321

Got -> GlobalOffsetTable

Yeah, otherwise I wouldn't bother doing this (but I can't share proprietary sources unfortunately).
Do you see any other issues, except name?

ruiu added a comment.Jun 21 2017, 10:36 AM

I don't have any further comments, but can you please update the patch?

ELF/Relocations.cpp
402

Add a comment saying that a relative relocation against the beginning of .got can always be computed at link-time as each ELF module has its own .got section.

pcc added a subscriber: pcc.Jun 21 2017, 10:47 AM
pcc added inline comments.
ELF/Writer.cpp
830–831

I think that if you create this symbol with addOptionalRegular you won't need a special case in Relocations.cpp.

Peter, I tried doing this, but it forces dynamic reloc to .Label, which can reside in RO section.

pcc added a comment.Jun 21 2017, 10:51 AM

Peter, I tried doing this, but it forces dynamic reloc to .Label, which can reside in RO section.

Does it help to set visibility to hidden?

Does it help to set visibility to hidden?

As you may noticed addOptionalRegular sets visibility to hidden by default. In my experiments I tried creating _GLOBAL_OFFSET_TABLE_ in a following way:

addOptionalRegular("_GLOBAL_OFFSET_TABLE_", InX::Got, 0, STV_HIDDEN, STB_LOCAL);

What troubles me with this approach is that the following can't be linked (ld/gold work fine):

ldr r0, =_GLOBAL_OFFSET_TABLE_

And one of lld test cases also fails.

evgeny777 updated this revision to Diff 103553.Jun 22 2017, 4:07 AM

Updated with a comment requested by @ruiu

evgeny777 abandoned this revision.Jan 31 2018, 6:56 AM