This is an archive of the discontinued LLVM Phabricator instance.

[lld] Define DefinedAtom::sectionSize.
ClosedPublic

Authored by ruiu on Feb 27 2015, 5:20 PM.

Details

Summary

Merge::mergeByLargestSection is half-baked since it's defined
in terms of section size, there's no way to get the section size
of an atom.

Currently we work around the issue by traversing the layout edges
to both directions and calculate the sum of all atoms reachable.
I wrote that code but I knew it's hacky. It's even not guaranteed
to work. If you add layout edges before the core linking, it
miscalculates a size.

Also it's of course slow. It's basically a linked list traversal.

In this patch I added DefinedAtom::sectionSize so that we can use
that for mergeByLargestSection. I'm not very happy to add a new
field to DefinedAtom base class, but I think it's legitimate since
mergeByLargestSection is defined for section size, and the section
size is currently just missing.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 20919.Feb 27 2015, 5:20 PM
ruiu retitled this revision from to [lld] Define DefinedAtom::sectionSize..
ruiu updated this object.
ruiu edited the test plan for this revision. (Show Details)
ruiu added a project: lld.
ruiu added a subscriber: Unknown Object (MLST).

in my opinion this is a shared attribute for all atoms that belong to a section. Can we store this information for the atom in the context? The other way is to add a Reference to store the size. If the idea is to add all format specific attributes in the Atom I am fine but we need to discuss on llvmdev before adding those features.

Anyways this patch is not complete as it's missing YAML Support and native file format support.

Thats a nice comparison, Ruiu. Once the YAML/Native code is changed, this LGTM. I have a usecase for section size for ELF too for internal purposes.

ruiu updated this revision to Diff 21080.Mar 2 2015, 9:13 PM
  • Added code for Native and YAML.

Other than the above mentioned comments code LGTM

include/lld/Core/DefinedAtom.h
239

Why are we mentioning the purpose if this function here. We could drop this comment.

lib/ReaderWriter/Native/ReaderNative.cpp
49

Can you add a new line before this function

This revision is now accepted and ready to land.Mar 3 2015, 5:16 AM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r231290.