summaryrefslogtreecommitdiffstats
path: root/lld/ELF/SyntheticSections.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-01-24 03:41:20 +0000
committerRui Ueyama <ruiu@google.com>2017-01-24 03:41:20 +0000
commitb2a23cf3c08cee45614f27eb2c6d044e506aa6a6 (patch)
treeb5a39d198e1afea7aa31d0db136cd674940f9328 /lld/ELF/SyntheticSections.cpp
parenteb440a14a56f3b40ab6881adfe0665d53722af7d (diff)
downloadbcm5719-llvm-b2a23cf3c08cee45614f27eb2c6d044e506aa6a6.tar.gz
bcm5719-llvm-b2a23cf3c08cee45614f27eb2c6d044e506aa6a6.zip
Do not allocate space for common symbols with -r
Currently ld.lld -r allocates space for common symbols, whereas ld.bfd -r doesn't. As a result the OpenBSD makefile bits for creating libraries fail as they use ld -X -r to strip local symbols, which results in duplicate symbol errors because space for the common symbols has been allocated. The diff also implements the --define-commons option such that allocation of commons can be forced even if -r is used. Patch by Mark Kettenis. llvm-svn: 292878
Diffstat (limited to 'lld/ELF/SyntheticSections.cpp')
-rw-r--r--lld/ELF/SyntheticSections.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 12748560fa5..c048886c98f 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -59,6 +59,9 @@ template <class ELFT> InputSection<ELFT> *elf::createCommonSection() {
ArrayRef<uint8_t>(), "COMMON");
Ret->Live = true;
+ if (!Config->DefineCommon)
+ return Ret;
+
// Sort the common symbols by alignment as an heuristic to pack them better.
std::vector<DefinedCommon *> Syms = getCommonSymbols<ELFT>();
std::stable_sort(Syms.begin(), Syms.end(),
@@ -1164,10 +1167,14 @@ void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) {
ESym->setVisibility(Body->symbol()->Visibility);
ESym->st_value = Body->getVA<ELFT>();
- if (const OutputSectionBase *OutSec = getOutputSection(Body))
+ if (const OutputSectionBase *OutSec = getOutputSection(Body)) {
ESym->st_shndx = OutSec->SectionIndex;
- else if (isa<DefinedRegular<ELFT>>(Body))
+ } else if (isa<DefinedRegular<ELFT>>(Body)) {
ESym->st_shndx = SHN_ABS;
+ } else if (isa<DefinedCommon>(Body)) {
+ ESym->st_shndx = SHN_COMMON;
+ ESym->st_value = cast<DefinedCommon>(Body)->Alignment;
+ }
if (Config->EMachine == EM_MIPS) {
// On MIPS we need to mark symbol which has a PLT entry and requires
@@ -1199,6 +1206,8 @@ SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) {
break;
}
case SymbolBody::DefinedCommonKind:
+ if (!Config->DefineCommon)
+ return nullptr;
return In<ELFT>::Common->OutSec;
case SymbolBody::SharedKind: {
auto &SS = cast<SharedSymbol<ELFT>>(*Sym);
OpenPOWER on IntegriCloud