Useful for detecting static initialization order fiasco.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
lld/test/ELF/shuffle-sections-init-fini.s | ||
---|---|---|
1 | This test passes for me without any code changes. | |
11 | I think this tests nothing. If you have the same result with different seeds, it probably means that What I think can be done to test it: # COMMON: Hex dump of section '.init_array' # WITHOUT-NEXT: ff0100 # WITH-NOT: ff0100 ... | |
17 | You do not need "unique" here it seems. |
lld/test/ELF/shuffle-sections-init-fini.s | ||
---|---|---|
11 | Random funtion implementations are different across platforms. We may have to create a large number of sections to ensure the result will be different. |
lld/ELF/Writer.cpp | ||
---|---|---|
1364 | This will break code that uses init_priority, no? I think we can only shuffle sections of equal priority. |
lld/ELF/Writer.cpp | ||
---|---|---|
1364 | Priorities are respected. Sections with the same priority can be shuffled. See the test below, .init_array.1 is the first. # CHECK: Hex dump of section '.init_array' # CHECK-NEXT: 0x{{[0-9a-f]+}} ff # ORDERED-SAME: 000102 03040506 0708090a 0b # SHUFFLED-NOT: 000102 03040506 0708090a 0b |
lld/ELF/Writer.cpp | ||
---|---|---|
1364 | Oh, I see. I was somehow reading a return after sortISDBySectionOrder, sorry. What about the script->hasSectionsCommand case? Don't we have to skip sortISDBySectionOrder in when it is true? |
lld/ELF/Writer.cpp | ||
---|---|---|
1364 | I think we can also sort for the script->hasSectionsCommand case. All priorities are ignored. All SHT_INIT_ARRAY sections are shuffled together. Added a test case. |
lld/ELF/Writer.cpp | ||
---|---|---|
1364 | Sounds reasonable. When using sections the linker script is probably what is responsible for producing the right order and we only sort inside each ISD. This LGTM, but should probably also get approved by someone more recently active in lld. |
LGTM
lld/test/ELF/shuffle-sections-init-fini.s | ||
---|---|---|
11 | Yes, I think it is fine for now. As far I understand std::mt19937 (i.e. a random number engine based on Mersenne Twister algorithm) should produce the same result on different platforms, because implementation should base on the same algorithm. |
This will break code that uses init_priority, no?
I think we can only shuffle sections of equal priority.