Currently lld creates a single section to collect all commons. There is no way
to separate commons based on file name patterns. The following linker script
construct does not work because commons are allocated before section placement
is done and the only synthesized BssSection that holds all commons has no file
associated with it:
SECTIONS { .common_0 : { *file0.o(COMMON) }}
This patch changes the allocation of commons to create a section per common
symbol and let the section logic do the layout.
Differential revision: https://reviews.llvm.org/D37489
llvm-svn: 312796
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 1df5a73..1f20657 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -299,9 +299,9 @@
Add(InX::BuildId);
}
- InX::Common = createCommonSection<ELFT>();
- if (InX::Common)
- Add(InX::Common);
+ auto Commons = createCommonSections();
+ for (InputSection *S : Commons)
+ Add(S);
InX::Bss = make<BssSection>(".bss");
Add(InX::Bss);