Skip to content

Commit

Permalink
Internalize symbols in comdats.
Browse files Browse the repository at this point in the history
We were dropping the CanOmitFromDynSym bit when creating undefined
symbols because of comdat.

llvm-svn: 272812
  • Loading branch information
espindola committed Jun 15, 2016
1 parent 6100adf commit cc70da3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lld/ELF/InputFiles.cpp
Expand Up @@ -351,7 +351,8 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
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
Expand All @@ -368,7 +369,8 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
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();
}
Expand Down Expand Up @@ -589,12 +591,12 @@ Symbol *BitcodeFile::createSymbol(const DenseSet<const Comdat *> &KeptComdats,
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.
Expand Down
5 changes: 3 additions & 2 deletions lld/ELF/SymbolTable.cpp
Expand Up @@ -220,17 +220,18 @@ std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Existing,

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;
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/SymbolTable.h
Expand Up @@ -59,7 +59,7 @@ template <class ELFT> class SymbolTable {

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);
Expand Down
11 changes: 11 additions & 0 deletions lld/test/ELF/lto/unnamed-addr-comdat.ll
@@ -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
@foo = linkonce_odr unnamed_addr constant i32 42, comdat

; CHECK: @foo = internal unnamed_addr constant i32 42, comdat

0 comments on commit cc70da3

Please sign in to comment.