[lld] r263228 - Simplify now that local symbols can use getVA.

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 22 14:21:46 PDT 2016


On Tue, Mar 22, 2016 at 6:36 PM, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
>> For "true" local symbols which can be referenced from the same module
>> only compiler creates two instructions for address loading:
>>
>> lw   $8, 0($gp) # R_MIPS_GOT16
>> addi $8, $8, 0  # R_MIPS_LO16
>>
>> The first instruction loads high 16 bits of the symbol address while
>> the second adds an offset. That allows to reduce number of required
>> GOT entries because only one global offset table entry is necessary
>> for every 64 KBytes of local data.
>>
>> Hidden global symbols can be referenced from other object files. And
>> compiler might do not know that the symbol is hidden. So the compiler
>> creates a single instruction to load the symbol address and expect
>> that the corresponding GOT entry holds complete address of the symbol.
>
> I see. Could you add that as a comment?

Sure. But I do not know what is the best place for it. What about
`GotSection::addEntry`?

> What does the compiler do when the symbol is know to be hidden? I ask
> because the decision for "one entry per symbol" versus "one entry per
> page" seems something that should be decided based on the relocation.
> In fact, a single symbol might require both entries if the compiler
> uses the instruction pair above when it knows the symbol is hidden:
>
> a.c: refers to a know hidden symbol foo: foo needs a page entry in the got.
> b.c: refers to a regular undef foo: foo needs a full address entry in the got.

Compiler considers any global symbol uniformly and generates single
R_MIPS_GOT16 relocation for address loading. It might generate two
instructions and two corresponding relocations if it knows that the
symbols is hidden. And it will work even if the same symbol is
referenced from another object file. But this approach is not used by
unknown (to me) reason. Maybe the idea was to have the only GOT entry
related to the symbol. It is either GOT entry with "page" address or
GOT entry with "full" address.

-- 
Simon Atanasyan


More information about the llvm-commits mailing list