llvm.org GIT mirror llvm / 2102885
[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 Jake Ehrlich 2 years ago
3 changed file(s) with 42 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2727 Section: .text
2828 Value: 0x1000
2929 Size: 4
30 - Name: bam
31 Type: STT_FUNC
32 Section: .text
33 Value: 0x1001
34 Size: 4
35 Visibility: STV_HIDDEN
3036 - Name: foo
3137 Type: STT_FUNC
3238 Section: .text
33 Section: .text
3439 Value: 0x1004
40 - Name: faz
41 Type: STT_OBJECT
42 Section: .data
43 Value: 0x2002
44 Size: 2
45 Visibility: STV_INTERNAL
3546 - Name: bar
3647 Type: STT_OBJECT
3748 Section: .data
6374 #CHECK-NEXT: Section: .text
6475 #CHECK-NEXT: }
6576 #CHECK-NEXT: Symbol {
77 #CHECK-NEXT: Name: bam
78 #CHECK-NEXT: Value: 0x1001
79 #CHECK-NEXT: Size: 4
80 #CHECK-NEXT: Binding: Global
81 #CHECK-NEXT: Type: Function
82 #CHECK-NEXT: Other [
83 #CHECK-NEXT: STV_HIDDEN
84 #CHECK-NEXT: ]
85 #CHECK-NEXT: Section: .text
86 #CHECK-NEXT: }
87 #CHECK-NEXT: Symbol {
6688 #CHECK-NEXT: Name: foo
6789 #CHECK-NEXT: Value: 0x1004
6890 #CHECK-NEXT: Size: 0
7092 #CHECK-NEXT: Type: Function
7193 #CHECK-NEXT: Other: 0
7294 #CHECK-NEXT: Section: .text
95 #CHECK-NEXT: }
96 #CHECK-NEXT: Symbol {
97 #CHECK-NEXT: Name: faz
98 #CHECK-NEXT: Value: 0x2002
99 #CHECK-NEXT: Size: 2
100 #CHECK-NEXT: Binding: Global
101 #CHECK-NEXT: Type: Object
102 #CHECK-NEXT: Other [
103 #CHECK-NEXT: STV_INTERNAL
104 #CHECK-NEXT: ]
105 #CHECK-NEXT: Section: .data
73106 #CHECK-NEXT: }
74107 #CHECK-NEXT: Symbol {
75108 #CHECK-NEXT: Name: bar
140140
141141 void SymbolTableSection::addSymbol(StringRef Name, uint8_t Bind, uint8_t Type,
142142 SectionBase *DefinedIn, uint64_t Value,
143 uint16_t Shndx, uint64_t Sz) {
143 uint8_t Visibility, uint16_t Shndx,
144 uint64_t Sz) {
144145 Symbol Sym;
145146 Sym.Name = Name;
146147 Sym.Binding = Bind;
153154 Sym.ShndxType = SYMBOL_SIMPLE_INDEX;
154155 }
155156 Sym.Value = Value;
157 Sym.Visibility = Visibility;
156158 Sym.Size = Sz;
157159 Sym.Index = Symbols.size();
158160 Symbols.emplace_back(llvm::make_unique(Sym));
220222 Sym->st_name = Symbol->NameIndex;
221223 Sym->st_value = Symbol->Value;
222224 Sym->st_size = Symbol->Size;
225 Sym->st_other = Symbol->Visibility;
223226 Sym->setBinding(Symbol->Binding);
224227 Sym->setType(Symbol->Type);
225228 Sym->st_shndx = Symbol->getShndx();
424427 }
425428
426429 SymTab->addSymbol(Name, Sym.getBinding(), Sym.getType(), DefSection,
427 Sym.getValue(), Sym.st_shndx, Sym.st_size);
430 Sym.getValue(), Sym.st_other, Sym.st_shndx, Sym.st_size);
428431 }
429432 }
430433
192192 uint64_t Size;
193193 uint8_t Type;
194194 uint64_t Value;
195 uint8_t Visibility;
195196
196197 uint16_t getShndx() const;
197198 };
206207 public:
207208 void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; }
208209 void addSymbol(StringRef Name, uint8_t Bind, uint8_t Type,
209 SectionBase *DefinedIn, uint64_t Value, uint16_t Shndx,
210 uint64_t Sz);
210 SectionBase *DefinedIn, uint64_t Value, uint8_t Visibility,
211 uint16_t Shndx, uint64_t Sz);
211212 void addSymbolNames();
212213 const SectionBase *getStrTab() const { return SymbolNames; }
213214 const Symbol *getSymbolByIndex(uint32_t Index) const;