[llvm-readobj] Recognize N_THUMB_DEF as a symbol flag

The right symbol flag mask is ~0x7, not ~0xf.

Also emit string names for the other flags (we were missing some).

Reviewed By: #lld-macho, gkm

Differential Revision: https://reviews.llvm.org/D101548
This commit is contained in:
Jez Ng 2021-04-30 17:39:52 -04:00
parent 4423a7a09b
commit c00fc180ec
5 changed files with 85 additions and 4 deletions

View File

@ -73,6 +73,7 @@
# CHECK-NEXT: Section: (0x0)
# CHECK-NEXT: RefType: UndefinedNonLazy (0x0)
# CHECK-NEXT: Flags [ (0x100)
# CHECK-NEXT: SymbolResolver (0x100)
# CHECK-NEXT: ]
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: }

View File

@ -92,8 +92,9 @@ L_.str:
@ CHECK: Extern
@ CHECK: Type: Section (0xE)
@ CHECK: Section: __text (0x1)
@ CHECK: RefType: 0x8
@ CHECK: Flags [ (0x0)
@ CHECK: RefType: UndefinedNonLazy (0x0)
@ CHECK: Flags [ (0x8)
@ CHECK: ThumbDef (0x8)
@ CHECK: ]
@ CHECK: Value: 0x0
@ CHECK: }

View File

@ -180,6 +180,7 @@
# CHECK-NEXT: RefType: UndefinedNonLazy (0x0)
# CHECK-NEXT: Flags [ (0xFE00)
# CHECK-NEXT: AltEntry (0x200)
# CHECK-NEXT: ColdFunc (0x400)
# CHECK-NEXT: ]
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: }
@ -190,6 +191,7 @@
# CHECK-NEXT: Section: (0x0)
# CHECK-NEXT: RefType: UndefinedNonLazy (0x0)
# CHECK-NEXT: Flags [ (0x100)
# CHECK-NEXT: SymbolResolver (0x100)
# CHECK-NEXT: ]
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: }

View File

@ -0,0 +1,74 @@
## Verify that llvm-readobj can dump the various symbol flags correctly.
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj --syms %t | FileCheck %s
# CHECK: Symbols [
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: _foo (1)
# CHECK-NEXT: Extern
# CHECK-NEXT: Type: Section (0xE)
# CHECK-NEXT: Section: __text (0x1)
# CHECK-NEXT: RefType: UndefinedNonLazy (0x0)
# CHECK-NEXT: Flags [ (0x128)
# CHECK-NEXT: NoDeadStrip (0x20)
# CHECK-NEXT: SymbolResolver (0x100)
# CHECK-NEXT: ThumbDef (0x8)
# CHECK-NEXT: ]
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: }
# CHECK-NEXT: ]
--- !mach-o
FileHeader:
magic: 0xFEEDFACE
cputype: 0xC
cpusubtype: 0x9
filetype: 0x1
ncmds: 2
sizeofcmds: 228
flags: 0x0
LoadCommands:
- cmd: LC_SEGMENT
cmdsize: 124
segname: ''
vmaddr: 0
vmsize: 0
fileoff: 256
filesize: 0
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0
size: 0
offset: 0x100
align: 2
reloff: 0x0
nreloc: 0
flags: 0x80000000
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
content: ''
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 256
nsyms: 1
stroff: 268
strsize: 8
LinkEditData:
NameList:
- n_strx: 1
n_type: 0xF
n_sect: 1
n_desc: 296
n_value: 0
StringTable:
- ''
- _foo
- ''
- ''
...

View File

@ -256,11 +256,14 @@ static const EnumEntry<unsigned> MachOSymbolRefTypes[] = {
};
static const EnumEntry<unsigned> MachOSymbolFlags[] = {
{ "ThumbDef", 0x8 },
{ "ReferencedDynamically", 0x10 },
{ "NoDeadStrip", 0x20 },
{ "WeakRef", 0x40 },
{ "WeakDef", 0x80 },
{ "SymbolResolver", 0x100 },
{ "AltEntry", 0x200 },
{ "ColdFunc", 0x400 },
};
static const EnumEntry<unsigned> MachOSymbolTypes[] = {
@ -651,9 +654,9 @@ void MachODumper::printSymbol(const SymbolRef &Symbol) {
makeArrayRef(MachOSymbolTypes));
}
W.printHex("Section", SectionName, MOSymbol.SectionIndex);
W.printEnum("RefType", static_cast<uint16_t>(MOSymbol.Flags & 0xF),
W.printEnum("RefType", static_cast<uint16_t>(MOSymbol.Flags & 0x7),
makeArrayRef(MachOSymbolRefTypes));
W.printFlags("Flags", static_cast<uint16_t>(MOSymbol.Flags & ~0xF),
W.printFlags("Flags", static_cast<uint16_t>(MOSymbol.Flags & ~0x7),
makeArrayRef(MachOSymbolFlags));
W.printHex("Value", MOSymbol.Value);
}