[lld] [LLD][COFF] Prevent merging .bss into shared sections (PR #202817)
Evgenii Kudriashov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 07:57:11 PDT 2026
================
@@ -1716,8 +1724,17 @@ void Writer::mergeSections() {
// whatever section it is being merged into (usually .data) so that the image
// need not actually contain all of the zeros.
auto it = ctx.config.merge.find(".bss");
- if (it != ctx.config.merge.end())
- mergeSection(*it);
+ if (it != ctx.config.merge.end()) {
+ // Resolve the final merge target name following the chain.
+ StringRef toSection = getMergeDestination(it->first, it->second);
----------------
e-kud wrote:
So the idea is to get the final section and check whether it is shared. But we do the same already in `mergeSections`. So I extracted `getMergeDestination` to call it beforehand. Inside there should be only one iteration of `while` loop.
The problem in removing `getMergeDestination` from `mergeSection` is that we have another site calling `mergeSection` (a few lines above). To avoid this double checking what do you think if I put `getMergeDestination` before another call site and add an assert to `mergeSection` if the section, we are merging in, is not final. Or is the assert too strong?
https://github.com/llvm/llvm-project/pull/202817
More information about the llvm-commits
mailing list