llvm.org GIT mirror llvm / 802fe93
Use pointers to iterate over symbols. While here, don't report a dummy symbol for relocations that don't have symbols. We used to says such relocations were for the first defined symbol, but now we return end_symbols(). The llvm-readobj output change agrees with otool. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180214 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
4 changed file(s) with 92 addition(s) and 84 deletion(s). Raw diff Collapse all Expand all
215215 return O->getData().substr(Offset, 1).data();
216216 }
217217
218 static const char *getSymbolTableEntryPtr(const MachOObjectFile *O,
219 DataRefImpl DRI) {
220 macho::SymtabLoadCommand S = O->getSymtabLoadCommand();
221
222 unsigned Index = DRI.d.b;
223
224 unsigned SymbolTableEntrySize = O->is64Bit() ?
225 sizeof(macho::Symbol64TableEntry) :
226 sizeof(macho::SymbolTableEntry);
227
228 uint64_t Offset = S.SymbolTableOffset + Index * SymbolTableEntrySize;
229 return getPtr(O, Offset);
230 }
231
232218 static SymbolTableEntryBase
233219 getSymbolTableEntryBase(const MachOObjectFile *O, DataRefImpl DRI) {
234 const char *P = getSymbolTableEntryPtr(O, DRI);
220 const char *P = reinterpret_cast(DRI.p);
235221 return getStruct(O, P);
236222 }
237223
419405
420406 error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb,
421407 SymbolRef &Res) const {
422 Symb.d.b++;
408 unsigned SymbolTableEntrySize = is64Bit() ?
409 sizeof(macho::Symbol64TableEntry) :
410 sizeof(macho::SymbolTableEntry);
411 Symb.p += SymbolTableEntrySize;
423412 Res = SymbolRef(Symb, this);
424413 return object_error::success;
425414 }
493482 }
494483 // Unfortunately symbols are unsorted so we need to touch all
495484 // symbols from load command
496 macho::SymtabLoadCommand Symtab = getSymtabLoadCommand();
497 DRI.d.b = 0;
498 while (DRI.d.b <= Symtab.NumSymbolTableEntries) {
485 error_code ec;
486 for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E;
487 I.increment(ec)) {
488 DataRefImpl DRI = I->getRawDataRefImpl();
499489 Entry = getSymbolTableEntryBase(this, DRI);
500490 getSymbolAddress(DRI, Value);
501491 if (Entry.SectionIndex == SectionIndex && Value > BeginOffset)
502492 if (!EndOffset || Value < EndOffset)
503493 EndOffset = Value;
504 DRI.d.b++;
505494 }
506495 if (!EndOffset) {
507496 uint64_t Size;
828817 macho::RelocationEntry RE = getRelocation(Rel);
829818 uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE);
830819 bool isExtern = getPlainRelocationExternal(RE);
831
820 if (!isExtern) {
821 Res = *end_symbols();
822 return object_error::success;
823 }
824
825 macho::SymtabLoadCommand S = getSymtabLoadCommand();
826 unsigned SymbolTableEntrySize = is64Bit() ?
827 sizeof(macho::Symbol64TableEntry) :
828 sizeof(macho::SymbolTableEntry);
829 uint64_t Offset = S.SymbolTableOffset + SymbolIdx * SymbolTableEntrySize;
832830 DataRefImpl Sym;
833 if (isExtern) {
834 Sym.d.b = SymbolIdx;
835 }
831 Sym.p = reinterpret_cast(getPtr(this, Offset));
836832 Res = SymbolRef(Sym, this);
837833 return object_error::success;
838834 }
11591155 }
11601156
11611157 symbol_iterator MachOObjectFile::begin_symbols() const {
1162 // DRI.d.a = segment number; DRI.d.b = symbol index.
11631158 DataRefImpl DRI;
1159 if (!SymtabLoadCmd)
1160 return symbol_iterator(SymbolRef(DRI, this));
1161
1162 macho::SymtabLoadCommand Symtab = getSymtabLoadCommand();
1163 DRI.p = reinterpret_cast(getPtr(this, Symtab.SymbolTableOffset));
11641164 return symbol_iterator(SymbolRef(DRI, this));
11651165 }
11661166
11671167 symbol_iterator MachOObjectFile::end_symbols() const {
11681168 DataRefImpl DRI;
1169 if (SymtabLoadCmd) {
1170 macho::SymtabLoadCommand Symtab = getSymtabLoadCommand();
1171 DRI.d.b = Symtab.NumSymbolTableEntries;
1172 }
1169 if (!SymtabLoadCmd)
1170 return symbol_iterator(SymbolRef(DRI, this));
1171
1172 macho::SymtabLoadCommand Symtab = getSymtabLoadCommand();
1173 unsigned SymbolTableEntrySize = is64Bit() ?
1174 sizeof(macho::Symbol64TableEntry) :
1175 sizeof(macho::SymbolTableEntry);
1176 unsigned Offset = Symtab.SymbolTableOffset +
1177 Symtab.NumSymbolTableEntries * SymbolTableEntrySize;
1178 DRI.p = reinterpret_cast(getPtr(this, Offset));
11731179 return symbol_iterator(SymbolRef(DRI, this));
11741180 }
11751181
13681374
13691375 macho::SymbolTableEntry
13701376 MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const {
1371 const char *P = getSymbolTableEntryPtr(this, DRI);
1377 const char *P = reinterpret_cast(DRI.p);
13721378 return getStruct(this, P);
13731379 }
13741380
13751381 macho::Symbol64TableEntry
13761382 MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const {
1377 const char *P = getSymbolTableEntryPtr(this, DRI);
1383 const char *P = reinterpret_cast(DRI.p);
13781384 return getStruct(this, P);
13791385 }
13801386
3333 MACHO-I386-NEXT: Section __text {
3434 MACHO-I386-NEXT: 0x18 1 2 1 GENERIC_RELOC_VANILLA 0 _SomeOtherFunction
3535 MACHO-I386-NEXT: 0x13 1 2 1 GENERIC_RELOC_VANILLA 0 _puts
36 MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 _main
37 MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 _main
36 MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 -
37 MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 -
3838 MACHO-I386-NEXT: }
3939 MACHO-I386-NEXT: ]
4040
4848
4949 MACHO-PPC: Relocations [
5050 MACHO-PPC-NEXT: Section __text {
51 MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 _b
52 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 _b
53 MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 _b
54 MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 _b
55 MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 _b
51 MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 -
52 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 -
53 MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 -
54 MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 -
55 MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 -
5656 MACHO-PPC-NEXT: }
5757 MACHO-PPC-NEXT: Section __picsymbolstub1 {
58 MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 _b
59 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 _b
60 MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 _b
61 MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 _b
58 MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 -
59 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 -
60 MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 -
61 MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 -
6262 MACHO-PPC-NEXT: }
6363 MACHO-PPC-NEXT: Section __la_symbol_ptr {
6464 MACHO-PPC-NEXT: 0x0 0 2 1 PPC_RELOC_VANILLA 0 dyld_stub_binding_helper
6767
6868 MACHO-PPC64: Relocations [
6969 MACHO-PPC64-NEXT: Section __text {
70 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 _b
71 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 _b
72 MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 _b
73 MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 _b
74 MACHO-PPC64-NEXT: 0x18 1 2 0 0 _b
70 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 -
71 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 -
72 MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 -
73 MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 -
74 MACHO-PPC64-NEXT: 0x18 1 2 0 0 -
7575 MACHO-PPC64-NEXT: }
7676 MACHO-PPC64-NEXT: Section __picsymbolstub1 {
77 MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 _b
78 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 _b
79 MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 _b
80 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 _b
77 MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 -
78 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 -
79 MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 -
80 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 -
8181 MACHO-PPC64-NEXT: }
8282 MACHO-PPC64-NEXT: Section __la_symbol_ptr {
8383 MACHO-PPC64-NEXT: 0x0 0 3 1 0 dyld_stub_binding_helper
9393 MACHO-ARM-NEXT: Length: 2
9494 MACHO-ARM-NEXT: Extern: N/A
9595 MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
96 MACHO-ARM-NEXT: Symbol: _b
96 MACHO-ARM-NEXT: Symbol: -
9797 MACHO-ARM-NEXT: Scattered: 1
9898 MACHO-ARM-NEXT: }
9999 MACHO-ARM-NEXT: Relocation {
102102 MACHO-ARM-NEXT: Length: 2
103103 MACHO-ARM-NEXT: Extern: N/A
104104 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
105 MACHO-ARM-NEXT: Symbol: _b
105 MACHO-ARM-NEXT: Symbol: -
106106 MACHO-ARM-NEXT: Scattered: 1
107107 MACHO-ARM-NEXT: }
108108 MACHO-ARM-NEXT: Relocation {
129129 MACHO-ARM-NEXT: Length: 1
130130 MACHO-ARM-NEXT: Extern: 0
131131 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
132 MACHO-ARM-NEXT: Symbol: _b
132 MACHO-ARM-NEXT: Symbol: -
133133 MACHO-ARM-NEXT: Scattered: 0
134134 MACHO-ARM-NEXT: }
135135 MACHO-ARM-NEXT: Relocation {
147147 MACHO-ARM-NEXT: Length: 0
148148 MACHO-ARM-NEXT: Extern: 0
149149 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
150 MACHO-ARM-NEXT: Symbol: _b
150 MACHO-ARM-NEXT: Symbol: -
151151 MACHO-ARM-NEXT: Scattered: 0
152152 MACHO-ARM-NEXT: }
153153 MACHO-ARM-NEXT: Relocation {
156156 MACHO-ARM-NEXT: Length: 2
157157 MACHO-ARM-NEXT: Extern: N/A
158158 MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
159 MACHO-ARM-NEXT: Symbol: _b
159 MACHO-ARM-NEXT: Symbol: -
160160 MACHO-ARM-NEXT: Scattered: 1
161161 MACHO-ARM-NEXT: }
162162 MACHO-ARM-NEXT: Relocation {
165165 MACHO-ARM-NEXT: Length: 2
166166 MACHO-ARM-NEXT: Extern: N/A
167167 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
168 MACHO-ARM-NEXT: Symbol: _b
168 MACHO-ARM-NEXT: Symbol: -
169169 MACHO-ARM-NEXT: Scattered: 1
170170 MACHO-ARM-NEXT: }
171171 MACHO-ARM-NEXT: }
160160 MACHO-I386-NEXT: Relocations [
161161 MACHO-I386-NEXT: 0x18 1 2 1 GENERIC_RELOC_VANILLA 0 _SomeOtherFunction
162162 MACHO-I386-NEXT: 0x13 1 2 1 GENERIC_RELOC_VANILLA 0 _puts
163 MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 _main
164 MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 _main
163 MACHO-I386-NEXT: 0xB 0 2 n/a GENERIC_RELOC_LOCAL_SECTDIFF 1 -
164 MACHO-I386-NEXT: 0x0 0 2 n/a GENERIC_RELOC_PAIR 1 -
165165 MACHO-I386-NEXT: ]
166166 MACHO-I386-NEXT: Symbols [
167167 MACHO-I386-NEXT: Symbol {
274274 MACHO-PPC-NEXT: Reserved1: 0x0
275275 MACHO-PPC-NEXT: Reserved2: 0x0
276276 MACHO-PPC-NEXT: Relocations [
277 MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 _b
278 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 _b
279 MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 _b
280 MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 _b
281 MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 _b
277 MACHO-PPC-NEXT: 0x24 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 -
278 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 -
279 MACHO-PPC-NEXT: 0x1C 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 -
280 MACHO-PPC-NEXT: 0x58 0 2 n/a PPC_RELOC_PAIR 1 -
281 MACHO-PPC-NEXT: 0x18 1 2 0 PPC_RELOC_BR24 0 -
282282 MACHO-PPC-NEXT: ]
283283 MACHO-PPC-NEXT: Symbols [
284284 MACHO-PPC-NEXT: Symbol {
316316 MACHO-PPC-NEXT: Reserved1: 0x0
317317 MACHO-PPC-NEXT: Reserved2: 0x20
318318 MACHO-PPC-NEXT: Relocations [
319 MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 _b
320 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 _b
321 MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 _b
322 MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 _b
319 MACHO-PPC-NEXT: 0x14 0 2 n/a PPC_RELOC_LO16_SECTDIFF 1 -
320 MACHO-PPC-NEXT: 0x0 0 2 n/a PPC_RELOC_PAIR 1 -
321 MACHO-PPC-NEXT: 0xC 0 2 n/a PPC_RELOC_HA16_SECTDIFF 1 -
322 MACHO-PPC-NEXT: 0x20 0 2 n/a PPC_RELOC_PAIR 1 -
323323 MACHO-PPC-NEXT: ]
324324 MACHO-PPC-NEXT: Symbols [
325325 MACHO-PPC-NEXT: ]
429429 MACHO-PPC64-NEXT: Reserved1: 0x0
430430 MACHO-PPC64-NEXT: Reserved2: 0x0
431431 MACHO-PPC64-NEXT: Relocations [
432 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 _b
433 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 _b
434 MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 _b
435 MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 _b
436 MACHO-PPC64-NEXT: 0x18 1 2 0 0 _b
432 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 -
433 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 -
434 MACHO-PPC64-NEXT: 0x1C 0 2 n/a 1 -
435 MACHO-PPC64-NEXT: 0x58 0 2 n/a 1 -
436 MACHO-PPC64-NEXT: 0x18 1 2 0 0 -
437437 MACHO-PPC64-NEXT: ]
438438 MACHO-PPC64-NEXT: Symbols [
439439 MACHO-PPC64-NEXT: Symbol {
471471 MACHO-PPC64-NEXT: Reserved1: 0x0
472472 MACHO-PPC64-NEXT: Reserved2: 0x20
473473 MACHO-PPC64-NEXT: Relocations [
474 MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 _b
475 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 _b
476 MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 _b
477 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 _b
474 MACHO-PPC64-NEXT: 0x14 0 2 n/a 1 -
475 MACHO-PPC64-NEXT: 0x0 0 2 n/a 1 -
476 MACHO-PPC64-NEXT: 0xC 0 2 n/a 1 -
477 MACHO-PPC64-NEXT: 0x24 0 2 n/a 1 -
478478 MACHO-PPC64-NEXT: ]
479479 MACHO-PPC64-NEXT: Symbols [
480480 MACHO-PPC64-NEXT: ]
589589 MACHO-ARM-NEXT: Length: 2
590590 MACHO-ARM-NEXT: Extern: N/A
591591 MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
592 MACHO-ARM-NEXT: Symbol: _b
592 MACHO-ARM-NEXT: Symbol: -
593593 MACHO-ARM-NEXT: Scattered: 1
594594 MACHO-ARM-NEXT: }
595595 MACHO-ARM-NEXT: Relocation {
598598 MACHO-ARM-NEXT: Length: 2
599599 MACHO-ARM-NEXT: Extern: N/A
600600 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
601 MACHO-ARM-NEXT: Symbol: _b
601 MACHO-ARM-NEXT: Symbol: -
602602 MACHO-ARM-NEXT: Scattered: 1
603603 MACHO-ARM-NEXT: }
604604 MACHO-ARM-NEXT: Relocation {
625625 MACHO-ARM-NEXT: Length: 1
626626 MACHO-ARM-NEXT: Extern: 0
627627 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
628 MACHO-ARM-NEXT: Symbol: _b
628 MACHO-ARM-NEXT: Symbol: -
629629 MACHO-ARM-NEXT: Scattered: 0
630630 MACHO-ARM-NEXT: }
631631 MACHO-ARM-NEXT: Relocation {
643643 MACHO-ARM-NEXT: Length: 0
644644 MACHO-ARM-NEXT: Extern: 0
645645 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
646 MACHO-ARM-NEXT: Symbol: _b
646 MACHO-ARM-NEXT: Symbol: -
647647 MACHO-ARM-NEXT: Scattered: 0
648648 MACHO-ARM-NEXT: }
649649 MACHO-ARM-NEXT: Relocation {
652652 MACHO-ARM-NEXT: Length: 2
653653 MACHO-ARM-NEXT: Extern: N/A
654654 MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
655 MACHO-ARM-NEXT: Symbol: _b
655 MACHO-ARM-NEXT: Symbol: -
656656 MACHO-ARM-NEXT: Scattered: 1
657657 MACHO-ARM-NEXT: }
658658 MACHO-ARM-NEXT: Relocation {
661661 MACHO-ARM-NEXT: Length: 2
662662 MACHO-ARM-NEXT: Extern: N/A
663663 MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
664 MACHO-ARM-NEXT: Symbol: _b
664 MACHO-ARM-NEXT: Symbol: -
665665 MACHO-ARM-NEXT: Scattered: 1
666666 MACHO-ARM-NEXT: }
667667 MACHO-ARM-NEXT: ]
344344 if (error(RelI->getOffset(Offset))) return;
345345 if (error(RelI->getTypeName(RelocName))) return;
346346 if (error(RelI->getSymbol(Symbol))) return;
347 if (error(Symbol.getName(SymbolName))) return;
347 if (symbol_iterator(Symbol) != Obj->end_symbols() &&
348 error(Symbol.getName(SymbolName)))
349 return;
348350
349351 DataRefImpl DR = RelI->getRawDataRefImpl();
350352 macho::RelocationEntry RE = Obj->getRelocation(DR);