[llvm] r321681 - [llvm-objcopy] Add support for visibility
Jake Ehrlich via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 2 15:01:24 PST 2018
Author: jakehehrlich
Date: Tue Jan 2 15:01:24 2018
New Revision: 321681
URL: http://llvm.org/viewvc/llvm-project?rev=321681&view=rev
Log:
[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.
Modified:
llvm/trunk/test/tools/llvm-objcopy/symbol-copy.test
llvm/trunk/tools/llvm-objcopy/Object.cpp
llvm/trunk/tools/llvm-objcopy/Object.h
Modified: llvm/trunk/test/tools/llvm-objcopy/symbol-copy.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/symbol-copy.test?rev=321681&r1=321680&r2=321681&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/symbol-copy.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/symbol-copy.test Tue Jan 2 15:01:24 2018
@@ -28,11 +28,22 @@ Symbols:
Section: .text
Value: 0x1000
Size: 4
- - Name: foo
+ - Name: bam
Type: STT_FUNC
Section: .text
+ Value: 0x1001
+ Size: 4
+ Visibility: STV_HIDDEN
+ - Name: foo
+ Type: STT_FUNC
Section: .text
Value: 0x1004
+ - Name: faz
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0x2002
+ Size: 2
+ Visibility: STV_INTERNAL
- Name: bar
Type: STT_OBJECT
Section: .data
@@ -64,6 +75,17 @@ Symbols:
#CHECK-NEXT: Section: .text
#CHECK-NEXT: }
#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: bam
+#CHECK-NEXT: Value: 0x1001
+#CHECK-NEXT: Size: 4
+#CHECK-NEXT: Binding: Global
+#CHECK-NEXT: Type: Function
+#CHECK-NEXT: Other [
+#CHECK-NEXT: STV_HIDDEN
+#CHECK-NEXT: ]
+#CHECK-NEXT: Section: .text
+#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
#CHECK-NEXT: Name: foo
#CHECK-NEXT: Value: 0x1004
#CHECK-NEXT: Size: 0
@@ -73,6 +95,17 @@ Symbols:
#CHECK-NEXT: Section: .text
#CHECK-NEXT: }
#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: faz
+#CHECK-NEXT: Value: 0x2002
+#CHECK-NEXT: Size: 2
+#CHECK-NEXT: Binding: Global
+#CHECK-NEXT: Type: Object
+#CHECK-NEXT: Other [
+#CHECK-NEXT: STV_INTERNAL
+#CHECK-NEXT: ]
+#CHECK-NEXT: Section: .data
+#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
#CHECK-NEXT: Name: bar
#CHECK-NEXT: Value: 0x2000
#CHECK-NEXT: Size: 4
Modified: llvm/trunk/tools/llvm-objcopy/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.cpp?rev=321681&r1=321680&r2=321681&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/Object.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/Object.cpp Tue Jan 2 15:01:24 2018
@@ -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(Strin
Sym.ShndxType = SYMBOL_SIMPLE_INDEX;
}
Sym.Value = Value;
+ Sym.Visibility = Visibility;
Sym.Size = Sz;
Sym.Index = Symbols.size();
Symbols.emplace_back(llvm::make_unique<Symbol>(Sym));
@@ -221,6 +223,7 @@ void SymbolTableSectionImpl<ELFT>::write
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<ELFT>::initSymbolTable(const
}
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);
}
}
Modified: llvm/trunk/tools/llvm-objcopy/Object.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.h?rev=321681&r1=321680&r2=321681&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/Object.h (original)
+++ llvm/trunk/tools/llvm-objcopy/Object.h Tue Jan 2 15:01:24 2018
@@ -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;
More information about the llvm-commits
mailing list