aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-07-02 10:58:24 -0700
committerGitHub <noreply@github.com>2024-07-02 10:58:24 -0700
commitfdd319655359b005889abf40d1d8a54fbd56059e (patch)
tree38f2d1e6f6c0a5de6df90efcbbbf28c2f91b42e7 /llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
parente852725e5d517195de247f30b62ad2c56717958a (diff)
downloadllvm-fdd319655359b005889abf40d1d8a54fbd56059e.zip
llvm-fdd319655359b005889abf40d1d8a54fbd56059e.tar.gz
llvm-fdd319655359b005889abf40d1d8a54fbd56059e.tar.bz2
[ELF] Make start/stop symbols retain associated discardable output sections
An empty output section specified in the `SECTIONS` command (e.g. `empty : { *(empty) }`) may be discarded. Due to phase ordering, we might define `__start_empty`/`__stop_empty` symbols with incorrect section indexes (usually benign, but could go out of bounds and cause `readelf -s` to print `BAD`). ``` finalizeSections addStartStopSymbols // __start_empty is defined // __start_empty is added to .symtab sortSections adjustOutputSections // `empty` is discarded writeSections // __start_empty is Defined with an invalid section index ``` Loaders use `st_value` members of the start/stop symbols and expect no "undefined symbol" linker error, but do not particularly care whether the symbols are defined or undefined. Let's retain the associated empty output section so that start/stop symbols will have correct section indexes. The approach allows us to remove `LinkerScript::isDiscarded` (https://reviews.llvm.org/D114179). Also delete the `findSection(".text")` special case from https://reviews.llvm.org/D46200, which is unnecessary even before this patch (`elfHeader` would be fine even with very large executables). Note: we should be careful not to unnecessarily retain .ARM.exidx, which would create an empty PT_ARM_EXIDX. ~40 tests would need to be updated. --- An alternative is to discard the empty output section and keep the start/stop symbols undefined. This approach needs more code and requires `LinkerScript::isDiscarded` before we discard empty sections in ``adjustOutputSections`. Pull Request: https://github.com/llvm/llvm-project/pull/96343
Diffstat (limited to 'llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp')
0 files changed, 0 insertions, 0 deletions