LLD: Layout-after and layout-before

+llvmdev

If you only have layout-after, it will run into problems with dead code stripping. (Ex, say A has a layout-after to B and only B is referenced by anything else. Since A is now unreferenced, it can get dead code stripped).

If you only have layout-before, the actual layout is hard because you don’t know what if any atom needs to come next.

That said, yes what we have is too complicated. Maybe this can be merged with the group concept, where for ELF all atoms in a section are by default in some “group”. Having a group keeps them all atoms in a group either all dead or all live. The layout engine just sorts by original address to sort atoms in a group, so the keep their relative position…

-Nick

Hi Rui,

ELF uses layout-after and in-group references now. It no longer uses layout-before.

The reason that two references are used are to make sure garbage collection treats the whole group of atoms together when it wants to Garbage collect an atom.

Thanks

Shankar Easwaran

Thank you for quick responses!

As to dead stripping, if dead stripping is the only pass we need
bi-directional edges, we might want the dead stripping pass to construct
internal data structure by reversing the graph to construct layout-before
edges from layout-after edges. This should be less error prone than
maintaining two reverse-directional edges throughout all passes. Of course
it will make time for dead stripping proportional to the number of all
atoms, rather than live ones. It looks traversing graph is surprisingly
cheep so I guess it wouldn't matter, but it needs investigation.

It's interesting that ELF no longer uses layout-before's. I agree that that
would be simpler than using both layout-after and layout-before.

I'll try to modify the dead-stripping pass as I described above. Any
concerns?

Hi Rui,

How would dead stripping know what atom comes before what other atom ? I think it may be better to use in-group reference as it simplified a lot for ELF.

Thanks

Shankar Easwaran

Hi Rui,

How would dead stripping know what atom comes before what other atom ? I
think it may be better to use in-group reference as it simplified a lot for
ELF.

As I described, the dead stripping pass can create layout-after edges from
layout-before edges by reversing the graph, just as we can do to any
directed graph using a simple graph algorithm.

Thanks