Skip to content

Commit

Permalink
[ELF2] Extract calculation of symbol binding as a separate function.
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D13910

llvm-svn: 250855
  • Loading branch information
Igor Kudrin committed Oct 20, 2015
1 parent 06ce8a4 commit 853b88d
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lld/ELF/OutputSections.cpp
Original file line number Diff line number Diff line change
@@ -789,23 +789,17 @@ void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) {
break;
}

unsigned char Binding = Body->isWeak() ? STB_WEAK : STB_GLOBAL;
unsigned char Type = STT_NOTYPE;
uintX_t Size = 0;
if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) {
const Elf_Sym &InputSym = EBody->Sym;
Binding = InputSym.getBinding();
Type = InputSym.getType();
Size = InputSym.st_size;
}

unsigned char Visibility = Body->getMostConstrainingVisibility();
if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
Binding = STB_LOCAL;

ESym->setBindingAndType(Binding, Type);
ESym->setBindingAndType(getSymbolBinding(Body), Type);
ESym->st_size = Size;
ESym->setVisibility(Visibility);
ESym->setVisibility(Body->getMostConstrainingVisibility());
ESym->st_value = getSymVA<ELFT>(*Body);

if (Section)
@@ -824,6 +818,16 @@ void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) {
});
}

template <class ELFT>
uint8_t SymbolTableSection<ELFT>::getSymbolBinding(SymbolBody *Body) {
uint8_t Visibility = Body->getMostConstrainingVisibility();
if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
return STB_LOCAL;
if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body))
return EBody->Sym.getBinding();
return Body->isWeak() ? STB_WEAK : STB_GLOBAL;
}

namespace lld {
namespace elf2 {
template class OutputSectionBase<ELF32LE>;
2 changes: 2 additions & 0 deletions lld/ELF/OutputSections.h
Original file line number Diff line number Diff line change
@@ -180,6 +180,8 @@ class SymbolTableSection final : public OutputSectionBase<ELFT> {
void writeLocalSymbols(uint8_t *&Buf);
void writeGlobalSymbols(uint8_t *Buf);

static uint8_t getSymbolBinding(SymbolBody *Body);

SymbolTable<ELFT> &Table;
StringTableSection<ELFT> &StrTabSec;
unsigned NumVisible = 0;

0 comments on commit 853b88d

Please sign in to comment.