This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix incorrect sorting of .init_array / .fini_array sections
ClosedPublic

Authored by atanasyan on May 28 2014, 10:58 PM.

Details

Summary

The main problem is in the predicate passed to the std::stable_sort(). This predicate always returns false if both section's names do not start with .init_array or .fini_array prefixes. In short, it does not define a strict weak ordering. Suppose we have the following sections:

.A .init_array.1 .init_array.2

The predicate states that:

not .init_array.1 < .A
not .A < .init_array.2
but .init_array.1 < .init_array.2 !!!

The second problem is that .init_array section without number should go last in the list. Not it has the lowest priority '0' and goes first.

The patch fix both of the problems.

Diff Detail

Event Timeline

atanasyan updated this revision to Diff 9906.May 28 2014, 10:58 PM
atanasyan retitled this revision from to [ELF] Fix incorrect sorting of .init_array / .fini_array sections.
atanasyan updated this object.
atanasyan edited the test plan for this revision. (Show Details)
atanasyan added reviewers: Bigcheese, shankarke, ruiu.
atanasyan added a subscriber: Unknown Object (MLST).
ruiu accepted this revision.May 28 2014, 11:07 PM
ruiu edited edge metadata.

LGTM. I remember I once fixed a similar issue in LayoutPass whose
compare function was not strict weak ordering.

This revision is now accepted and ready to land.May 28 2014, 11:07 PM
atanasyan closed this revision.May 29 2014, 10:38 PM

Thanks for review.

Closed by commit rL209875.