[lld] r272812 - Internalize symbols in comdats.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 15 10:56:10 PDT 2016
Author: rafael
Date: Wed Jun 15 12:56:10 2016
New Revision: 272812
URL: http://llvm.org/viewvc/llvm-project?rev=272812&view=rev
Log:
Internalize symbols in comdats.
We were dropping the CanOmitFromDynSym bit when creating undefined
symbols because of comdat.
Added:
lld/trunk/test/ELF/lto/unnamed-addr-comdat.ll
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=272812&r1=272811&r2=272812&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Jun 15 12:56:10 2016
@@ -351,7 +351,8 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
switch (Sym->st_shndx) {
case SHN_UNDEF:
return elf::Symtab<ELFT>::X
- ->addUndefined(Name, Binding, Sym->st_other, Sym->getType(), this)
+ ->addUndefined(Name, Binding, Sym->st_other, Sym->getType(),
+ /*CanOmitFromDynSym*/ false, this)
->body();
case SHN_COMMON:
return elf::Symtab<ELFT>::X
@@ -368,7 +369,8 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
case STB_GNU_UNIQUE:
if (Sec == &InputSection<ELFT>::Discarded)
return elf::Symtab<ELFT>::X
- ->addUndefined(Name, Binding, Sym->st_other, Sym->getType(), this)
+ ->addUndefined(Name, Binding, Sym->st_other, Sym->getType(),
+ /*CanOmitFromDynSym*/ false, this)
->body();
return elf::Symtab<ELFT>::X->addRegular(Name, *Sym, Sec)->body();
}
@@ -589,12 +591,12 @@ Symbol *BitcodeFile::createSymbol(const
if (const Comdat *C = GV->getComdat())
if (!KeptComdats.count(C))
return Symtab<ELFT>::X->addUndefined(NameRef, Binding, Visibility, Type,
- this);
+ CanOmitFromDynSym, this);
const Module &M = Obj.getModule();
if (Flags & BasicSymbolRef::SF_Undefined)
return Symtab<ELFT>::X->addUndefined(NameRef, Binding, Visibility, Type,
- this);
+ CanOmitFromDynSym, this);
if (Flags & BasicSymbolRef::SF_Common) {
// FIXME: Set SF_Common flag correctly for module asm symbols, and expose
// size and alignment.
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=272812&r1=272811&r2=272812&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Jun 15 12:56:10 2016
@@ -220,17 +220,18 @@ std::string SymbolTable<ELFT>::conflictM
template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {
return addUndefined(Name, STB_GLOBAL, STV_DEFAULT, /*Type*/ 0,
- /*File*/ nullptr);
+ /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
}
template <class ELFT>
Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name, uint8_t Binding,
uint8_t StOther, uint8_t Type,
+ bool CanOmitFromDynSym,
InputFile *File) {
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) =
- insert(Name, Type, StOther & 3, /*CanOmitFromDynSym*/ false,
+ insert(Name, Type, StOther & 3, CanOmitFromDynSym,
/*IsUsedInRegularObj*/ !File || !isa<BitcodeFile>(File), File);
if (WasInserted) {
S->Binding = Binding;
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=272812&r1=272811&r2=272812&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Wed Jun 15 12:56:10 2016
@@ -59,7 +59,7 @@ public:
Symbol *addUndefined(StringRef Name);
Symbol *addUndefined(StringRef Name, uint8_t Binding, uint8_t StOther,
- uint8_t Type, InputFile *File);
+ uint8_t Type, bool CanOmitFromDynSym, InputFile *File);
Symbol *addRegular(StringRef Name, const Elf_Sym &Sym,
InputSectionBase<ELFT> *Section);
Added: lld/trunk/test/ELF/lto/unnamed-addr-comdat.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/unnamed-addr-comdat.ll?rev=272812&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/unnamed-addr-comdat.ll (added)
+++ lld/trunk/test/ELF/lto/unnamed-addr-comdat.ll Wed Jun 15 12:56:10 2016
@@ -0,0 +1,11 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -save-temps -shared
+; RUN: llvm-dis %t.so.lto.bc -o - | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+$foo = comdat any
+ at foo = linkonce_odr unnamed_addr constant i32 42, comdat
+
+; CHECK: @foo = internal unnamed_addr constant i32 42, comdat
More information about the llvm-commits
mailing list