From 21028856626186a2caee8fb76b58ab8aa0f449ac Mon Sep 17 00:00:00 2001 From: Jake Ehrlich Date: Tue, 2 Jan 2018 23:01:24 +0000 Subject: [llvm-objcopy] Add support for visibility I have no clue how this was missed when symbol table support was added. This change ensures that the visibility of symbols is preserved by default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321681 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objcopy/Object.cpp | 7 +++++-- tools/llvm-objcopy/Object.h | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/llvm-objcopy/Object.cpp b/tools/llvm-objcopy/Object.cpp index d5dfcac40e4..9e82448187e 100644 --- a/tools/llvm-objcopy/Object.cpp +++ b/tools/llvm-objcopy/Object.cpp @@ -141,7 +141,8 @@ uint16_t Symbol::getShndx() const { void SymbolTableSection::addSymbol(StringRef Name, uint8_t Bind, uint8_t Type, SectionBase *DefinedIn, uint64_t Value, - uint16_t Shndx, uint64_t Sz) { + uint8_t Visibility, uint16_t Shndx, + uint64_t Sz) { Symbol Sym; Sym.Name = Name; Sym.Binding = Bind; @@ -154,6 +155,7 @@ void SymbolTableSection::addSymbol(StringRef Name, uint8_t Bind, uint8_t Type, Sym.ShndxType = SYMBOL_SIMPLE_INDEX; } Sym.Value = Value; + Sym.Visibility = Visibility; Sym.Size = Sz; Sym.Index = Symbols.size(); Symbols.emplace_back(llvm::make_unique(Sym)); @@ -221,6 +223,7 @@ void SymbolTableSectionImpl::writeSection(FileOutputBuffer &Out) const { Sym->st_name = Symbol->NameIndex; Sym->st_value = Symbol->Value; Sym->st_size = Symbol->Size; + Sym->st_other = Symbol->Visibility; Sym->setBinding(Symbol->Binding); Sym->setType(Symbol->Type); Sym->st_shndx = Symbol->getShndx(); @@ -425,7 +428,7 @@ void Object::initSymbolTable(const object::ELFFile &ElfFile, } SymTab->addSymbol(Name, Sym.getBinding(), Sym.getType(), DefSection, - Sym.getValue(), Sym.st_shndx, Sym.st_size); + Sym.getValue(), Sym.st_other, Sym.st_shndx, Sym.st_size); } } diff --git a/tools/llvm-objcopy/Object.h b/tools/llvm-objcopy/Object.h index b04b0c1a641..639f0f29ceb 100644 --- a/tools/llvm-objcopy/Object.h +++ b/tools/llvm-objcopy/Object.h @@ -193,6 +193,7 @@ struct Symbol { uint64_t Size; uint8_t Type; uint64_t Value; + uint8_t Visibility; uint16_t getShndx() const; }; @@ -207,8 +208,8 @@ protected: public: void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; } void addSymbol(StringRef Name, uint8_t Bind, uint8_t Type, - SectionBase *DefinedIn, uint64_t Value, uint16_t Shndx, - uint64_t Sz); + SectionBase *DefinedIn, uint64_t Value, uint8_t Visibility, + uint16_t Shndx, uint64_t Sz); void addSymbolNames(); const SectionBase *getStrTab() const { return SymbolNames; } const Symbol *getSymbolByIndex(uint32_t Index) const; -- cgit v1.2.3