summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/OutputSections.cpp20
-rw-r--r--lld/ELF/OutputSections.h2
2 files changed, 14 insertions, 8 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 95238db7de8..96d6a413adf 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -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>;
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index 5b7b3baad3c..974ac34a31a 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -180,6 +180,8 @@ private:
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;
OpenPOWER on IntegriCloud