SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
int Binding = Sym->getBinding();
InputSectionBase<ELFT> *Sec = getSection(*Sym);
+
if (Binding == STB_LOCAL) {
if (Sym->getType() == STT_FILE)
SourceFile = check(Sym->getName(this->StringTable));
}
StringRef Name = check(Sym->getName(this->StringTable));
+ uint8_t StOther = Sym->st_other;
+ uint8_t Type = Sym->getType();
+ uintX_t Value = Sym->st_value;
+ uintX_t Size = Sym->st_size;
switch (Sym->st_shndx) {
case SHN_UNDEF:
- return elf::Symtab<ELFT>::X->addUndefined(Name, Binding, Sym->st_other,
- Sym->getType(),
- /*CanOmitFromDynSym*/ false, this)
+ return elf::Symtab<ELFT>::X
+ ->addUndefined(Name, Binding, StOther, Type,
+ /*CanOmitFromDynSym=*/false, this)
->body();
case SHN_COMMON:
- if (Sym->st_value == 0 || Sym->st_value >= UINT32_MAX)
+ if (Value == 0 || Value >= UINT32_MAX)
fatal(getFilename(this) + ": common symbol '" + Name +
- "' has invalid alignment: " + Twine(Sym->st_value));
- return elf::Symtab<ELFT>::X->addCommon(Name, Sym->st_size, Sym->st_value,
- Binding, Sym->st_other,
- Sym->getType(), this)
+ "' has invalid alignment: " + Twine(Value));
+ return elf::Symtab<ELFT>::X
+ ->addCommon(Name, Size, Value, Binding, StOther, Type, this)
->body();
}
case STB_WEAK:
case STB_GNU_UNIQUE:
if (Sec == &InputSection<ELFT>::Discarded)
- return elf::Symtab<ELFT>::X->addUndefined(Name, Binding, Sym->st_other,
- Sym->getType(),
- /*CanOmitFromDynSym*/ false,
- this)
+ return elf::Symtab<ELFT>::X
+ ->addUndefined(Name, Binding, StOther, Type,
+ /*CanOmitFromDynSym=*/false, this)
->body();
- return elf::Symtab<ELFT>::X->addRegular(Name, *Sym, Sec, this)->body();
+ return elf::Symtab<ELFT>::X
+ ->addRegular(Name, StOther, Type, Value, Size, Binding, Sec, this)
+ ->body();
}
}
}
template <typename ELFT>
-Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, const Elf_Sym &Sym,
- InputSectionBase<ELFT> *Section,
- InputFile *File) {
- return addRegular(Name, Sym.st_other, Sym.getType(), Sym.st_value,
- Sym.st_size, Sym.getBinding(), Section, File);
-}
-
-template <typename ELFT>
Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, uint8_t StOther,
uint8_t Type, uintX_t Value, uintX_t Size,
uint8_t Binding,
Symbol *addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
uintX_t Value, uintX_t Size, uint8_t Binding,
InputSectionBase<ELFT> *Section, InputFile *File);
- Symbol *addRegular(StringRef Name, const Elf_Sym &Sym,
- InputSectionBase<ELFT> *Section, InputFile *File);
Symbol *addSynthetic(StringRef N, const OutputSectionBase *Section,
uintX_t Value, uint8_t StOther);
}
template <class ELFT>
-static Symbol *addRegular(StringRef Name, InputSectionBase<ELFT> *IS,
+static Symbol *addRegular(StringRef Name, InputSectionBase<ELFT> *Sec,
typename ELFT::uint Value) {
- typename ELFT::Sym LocalHidden = {};
// The linker generated symbols are added as STB_WEAK to allow user defined
// ones to override them.
- LocalHidden.setBindingAndType(STB_WEAK, STT_NOTYPE);
- LocalHidden.setVisibility(STV_HIDDEN);
- LocalHidden.st_value = Value;
- return Symtab<ELFT>::X->addRegular(Name, LocalHidden, IS, nullptr);
+ return Symtab<ELFT>::X->addRegular(Name, STV_HIDDEN, STT_NOTYPE, Value,
+ /*Size=*/0, STB_WEAK, Sec,
+ /*File=*/nullptr);
}
template <class ELFT>