[LLVMdev] [lld] Handling ELF section groups/.gnu.linkonce sections.

Nick Kledzik kledzik at apple.com
Wed Oct 30 13:31:37 PDT 2013


On Oct 30, 2013, at 9:13 AM, Shankar Easwaran <shankare at codeaurora.org> wrote:

>>> Solution
>>> A way to accomplish this could be to
>>> 
>>> A) Use the in-group reference along with the layout-after reference. The in-group reference for atoms in the group B are going to contain B as the root of the group.
>>> 
>>> B) Another way is that we could have a Atom attribute coalescedAway() which would be set for all atoms that we want to remove. This would also need in-group references.
>>> 
>>> I am ok with either of the methods (A) or (B) but inclined towards (B).
>> I was thinking both A & B.  That is how I do it with the darwin linker.  When a group is parsed, the signature atom has a "group" reference for all the other atoms in the group.  When the Resolver replaces one atom with another, it looks to see if the atom has any group references, and if so, marks all those atoms as coalesced away.
> Thanks Nick, I think the coalesce attribute of the atom should not be preserved in the native file right, as this is only a derived attribute after reading the ELF files, isnt it ?

There is no coalesced attribute in the Atom model.  The Resolver needs to keep track of which atoms got overridden with another atom, so they can be removed from the merged file.  That is what I meant by “mark as coalesced away”.  In lld, this is done via a replacement map in the SymbolTable object.  

The replacement map works well for what it does so far where just individual atoms are replaced with individual atoms by name (e.g. a mergeAsWeak atom is overridden/replaced with another one).   But when you are doing group based replacement, there is the issue of what to do if there are references to an atom in a group that is not the signature atom.  If the replacement group has a similar atom (by name), it is easy to redirect (in the replacement map) to the new atom.  But if the new group does not have such an atom, we need to error.  That means the replacement map needs an entry for each atom in a group which has been replaced and replacer atom may need to be some sentinel that there is no replacement, and updateReferences() will need to detect those and error out.

Also, the native and yaml will need a way to encode these groups.  If the in-memory model is that the signature atom in a group has a special reference kind to each other atom in the group, those references need to representable in the native and yaml formats.

-Nick



More information about the llvm-dev mailing list