[PATCH] D98445: [ELF] Special case --shuffle-sections=-1 to reverse input sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 15 19:31:13 PDT 2021


MaskRay added a comment.

Thanks for the comments!

In D98445#2621570 <https://reviews.llvm.org/D98445#2621570>, @peter.smith wrote:

> No fundamental objections, although I'm wondering if static constructor order is the main problem it would be better to do something specific. For example reversing the order of the constructors of the same priority while holding the remainder of the program constant. A smaller local change would help rule out other layout changes due to section order change.

Our internal system actually depends on .ctors/.dtors and hasn't migrated to .init_array/.fini_array yet ;-) Doing the migration has low priority, though.
I have thought about `--shuffle-sections .init_array=-1` (`<section-pattern>=<seed>`) to reverse a specific set of sections.
If such an option exists, we may be able to drop our -fno-use-init-array and catch up the toolchain evolution of obsoleting .ctors/.dtors .
I do not know whether it is too specific.

In the meantime, I have filed a feature request on `REVERSE(...)` https://sourceware.org/bugzilla/show_bug.cgi?id=27565
If both `REVERSE(...)` and linker script extension (https://sourceware.org/bugzilla/show_bug.cgi?id=26404) are supported, we can actually do it with a linker script.

> Had an idle thought that it might be possible to do some kind of dependency check. For example trace the relocations from each static constructor and look for common read-write data sections. While not a guarantee of order-dependence it would be a good indicator that there may be some order dependence.

Yes, some kind of dependency based checking may be useful to implement a bettern `--warn-backrefs`. Currently `--warn-backrefs` just catches problems which GNU ld/gold catch.
However, the check is performed with one particular input order so there may be other lurking problems. This is an interesting topic but I haven't thought much on it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98445/new/

https://reviews.llvm.org/D98445



More information about the llvm-commits mailing list