This is an archive of the discontinued LLVM Phabricator instance.

[lld][elf2] Sort output sections.
AbandonedPublic

Authored by Bigcheese on Sep 29 2015, 5:12 PM.

Details

Reviewers
espindola
Summary

Sort by:
ALLOC
ALLOC && NOBITS
ALLOC & EXEC
ALLOC & EXEC && NOBITS
ALLOC & WRITE
ALLOC & WRITE && NOBITS
<nothing> (ignoring NOBITS)

The dynamic section is finalized early because it adds strings to the dynamic string table, which comes before the dynamic table.

Diff Detail

Event Timeline

Bigcheese updated this revision to Diff 36052.Sep 29 2015, 5:12 PM
Bigcheese retitled this revision from to [lld][elf2] Sort output sections..
Bigcheese updated this object.
Bigcheese added a reviewer: rafael.
Bigcheese added a subscriber: llvm-commits.
rafael added inline comments.Sep 30 2015, 2:27 PM
ELF/Writer.cpp
398

No auto.
Rank

400

The rules that we must have are that

alloc is before non-alloc
read-only is the first (to combine with the first page)

The rest of the order is arbitrary, correct? Add a comment about it one way or the other.

411

There are 8 possible values.

The ones that are missing are

SHF_EXECINSTR:
SHF_WRITE:
SHF_EXECINSTR | SHF_WRITE:

It might be more explicit to just list them all.

415

Why is this relevant?

We need to put SHF_ALLOC first to reduce how much needs to be allocated and make sure debug info doesn't change actual code.

Other than that convertSectionFlagsToPHDRFlags (and therefore the creation of new PT_LOADs) only looks at SHF_WRITE and SHF_EXECINSTR, so looks like your rank function takes care of all cases.

Bigcheese marked an inline comment as done.Sep 30 2015, 2:45 PM
Bigcheese added inline comments.
ELF/Writer.cpp
398

This is a lambda, it has an unutterable type.

411

Explicitly list them as an error?

415

There's a testcase that creates a non allocated nobits section. If we don't ignore that, it ends up being placed after the section string table, which then causes an assert because the string table is finalized before the non allocated section's name is added.

rafael edited edge metadata.Sep 30 2015, 2:56 PM
rafael added a subscriber: rafael.

This is a lambda, it has an unutterable type.

Never mind, I read it as return value.

On the other hand, if it is a function it should be a verb (computeRank).

It might be more explicit to just list them all.

Explicitly list them as an error?

Yes, and drop the default.

There's a testcase that creates a non allocated nobits section. If we don't ignore that, it ends up being placed after the section string table, which then causes an assert because the string table is finalized before the non allocated section's name is added.

This is probably not the place to work around it. Definitely not
without a comment. I will debug it a bit.

Bigcheese updated this revision to Diff 36157.Sep 30 2015, 4:14 PM
Bigcheese edited edge metadata.

Resolve comments.

The patch can be simplified a bit (see attached).

Any reason you still had the SHT_NOBITS logic? If so it would need a
comment, and would be even better to have it in another patch, no?

In any case. The attached variation LGTM.

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 10:58 AM
Bigcheese abandoned this revision.Nov 14 2019, 1:09 PM