[llvm-readobj] Decode st_other symbol's flags

The patch supports common STV_xxx visibility flags and MIPS specific
STO_MIPS_xxx flags.

Differential Revision: http://reviews.llvm.org/D18447

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264300 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Simon Atanasyan 2016-03-24 16:10:37 +00:00
parent adb3b8dcbf
commit cc6b0d4dd4
12 changed files with 102 additions and 18 deletions

View File

@ -21,6 +21,6 @@ f2:
// CHECK-LABEL: Name: d1
// CHECK: Other: 0
// CHECK-LABEL: Name: f1
// CHECK: Other: 128
// CHECK: Other [ (0x80)
// CHECK-LABEL: Name: f2
// CHECK: Other: 0

View File

@ -73,10 +73,10 @@ bar:
# OBJ: Other: 0
# OBJ: Name: f_mm_insn_data
# OBJ: Other: 128
# OBJ: Other [ (0x80)
# OBJ: Name: f_mm_insn_instr
# OBJ: Other: 128
# OBJ: Other [ (0x80)
# OBJ: Name: f_normal_insn_data
# OBJ: Other: 0
@ -85,10 +85,10 @@ bar:
# OBJ: Other: 0
# OBJ: Name: o_mm_insn_data
# OBJ: Other: 128
# OBJ: Other [ (0x80)
# OBJ: Name: o_mm_insn_instr
# OBJ: Other: 128
# OBJ: Other [ (0x80)
# OBJ: Name: o_normal_insn_data
# OBJ: Other: 0

View File

@ -3,7 +3,7 @@
# Symbol bar must be marked as micromips.
# CHECK: Name: bar
# CHECK: Other: 128
# CHECK: Other [ (0x80)
.align 2
.type f,@function
.set nomips16
@ -16,7 +16,7 @@ f:
bar = f
# CHECK: Name: foo
# CHECK: Other: 128
# CHECK: Other [ (0x80)
.type o,@object
.set micromips
o:

View File

@ -14,7 +14,9 @@ h:
# CHECK: Name: f
# CHECK: Binding: Local
# CHECK: Type: None
# CHECK: Other: 128
# CHECK: Other [ (0x80)
# CHECK: STO_MIPS_MICROMIPS
# CHECK: ]
# CHECK: Section: .text
# CHECK: }
# CHECK: Symbol {
@ -28,7 +30,9 @@ h:
# CHECK: Name: h
# CHECK: Binding: Local
# CHECK: Type: None
# CHECK: Other: 128
# CHECK: Other [ (0x80)
# CHECK: STO_MIPS_MICROMIPS
# CHECK: ]
# CHECK: Section: .text
# CHECK: }
# CHECK: ]

View File

@ -26,7 +26,9 @@ j:
# CHECK: Name: g
# CHECK: Binding: Local
# CHECK: Type: None
# CHECK: Other: 128
# CHECK: Other [ (0x80)
# CHECK: STO_MIPS_MICROMIPS
# CHECK: ]
# CHECK: Section: .text
# CHECK: }
# CHECK: Symbol {
@ -40,7 +42,9 @@ j:
# CHECK: Name: i
# CHECK: Binding: Local
# CHECK: Type: None
# CHECK: Other: 128
# CHECK: Other [ (0x80)
# CHECK: STO_MIPS_MICROMIPS
# CHECK: ]
# CHECK: Section: .text
# CHECK: }
# CHECK: Symbol {

View File

@ -61,7 +61,8 @@ copy2 = callee2
# CHECK-NEXT: Size: 16
# CHECK-NEXT: Binding: Local
# CHECK-NEXT: Type: Function
# CHECK-NEXT: Other: 96
# CHECK-NEXT: Other [ (0x60)
# CHECK-NEXT: ]
# CHECK-NEXT: Section: .text
# CHECK: Name: callee2
# CHECK-NEXT: Value:
@ -77,7 +78,8 @@ copy2 = callee2
# CHECK-NEXT: Size: 16
# CHECK-NEXT: Binding: Local
# CHECK-NEXT: Type: Function
# CHECK-NEXT: Other: 96
# CHECK-NEXT: Other [ (0x60)
# CHECK-NEXT: ]
# CHECK-NEXT: Section: .text
# CHECK: Name: copy2
# CHECK-NEXT: Value:

View File

@ -9,7 +9,8 @@
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local (0x0)
// CHECK-NEXT: Type: None (0x0)
// CHECK-NEXT: Other: 64
// CHECK-NEXT: Other [ (0x40)
// CHECK-NEXT: ]
// CHECK-NEXT: Section: .group
// CHECK-NEXT: }

View File

@ -26,7 +26,9 @@
# OBJ-NEXT: Size: 4
# OBJ-NEXT: Binding: Global (0x1)
# OBJ-NEXT: Type: Object (0x1)
# OBJ-NEXT: Other: 1
# OBJ-NEXT: Other [ (0x1)
# OBJ-NEXT: STV_INTERNAL
# OBJ-NEXT: ]
# OBJ-NEXT: Section: .data (0x1)
# OBJ-NEXT: }
# OBJ-NEXT: Symbol {
@ -35,7 +37,9 @@
# OBJ-NEXT: Size: 4
# OBJ-NEXT: Binding: Global (0x1)
# OBJ-NEXT: Type: Object (0x1)
# OBJ-NEXT: Other: 2
# OBJ-NEXT: Other [ (0x2)
# OBJ-NEXT: STV_HIDDEN
# OBJ-NEXT: ]
# OBJ-NEXT: Section: .data (0x1)
# OBJ-NEXT: }
# OBJ-NEXT: Symbol {
@ -44,7 +48,11 @@
# OBJ-NEXT: Size: 4
# OBJ-NEXT: Binding: Global (0x1)
# OBJ-NEXT: Type: Object (0x1)
# OBJ-NEXT: Other: 163
# OBJ-NEXT: Other [ (0xA3)
# OBJ-NEXT: STO_MIPS_MICROMIPS
# OBJ-NEXT: STO_MIPS_PIC
# OBJ-NEXT: STV_PROTECTED
# OBJ-NEXT: ]
# OBJ-NEXT: Section: .data (0x1)
# OBJ-NEXT: }

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,25 @@
RUN: llvm-readobj -symbols %p/Inputs/st-other.obj.elf-mips \
RUN: | FileCheck -check-prefix=MREG %s
RUN: llvm-readobj -symbols %p/Inputs/st-other.obj.elf-mips16 \
RUN: | FileCheck -check-prefix=M16 %s
MREG: Name: foo
MREG-NEXT: Value: 0x0
MREG-NEXT: Size: 0
MREG-NEXT: Binding: Global
MREG-NEXT: Type: None
MREG-NEXT: Other [ (0x29)
MREG-NEXT: STO_MIPS_PIC (0x20)
MREG-NEXT: STO_MIPS_PLT (0x8)
MREG-NEXT: STV_INTERNAL (0x1)
MREG-NEXT: ]
M16: Name: foo
M16-NEXT: Value: 0x0
M16-NEXT: Size: 0
M16-NEXT: Binding: Global
M16-NEXT: Type: None
M16-NEXT: Other [ (0xF1)
M16-NEXT: STO_MIPS_MIPS16 (0xF0)
M16-NEXT: STV_INTERNAL (0x1)
M16-NEXT: ]

View File

@ -1128,6 +1128,25 @@ static const EnumEntry<unsigned> ElfHeaderMipsFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R6)
};
static const EnumEntry<unsigned> ElfSymOtherFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, STV_INTERNAL),
LLVM_READOBJ_ENUM_ENT(ELF, STV_HIDDEN),
LLVM_READOBJ_ENUM_ENT(ELF, STV_PROTECTED)
};
static const EnumEntry<unsigned> ElfMipsSymOtherFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL),
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT),
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PIC),
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MICROMIPS)
};
static const EnumEntry<unsigned> ElfMips16SymOtherFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL),
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT),
LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MIPS16)
};
template <typename ELFT>
ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, StreamWriter &Writer)
: ObjDumper(Writer), Obj(Obj) {
@ -2883,7 +2902,28 @@ void LLVMStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol,
W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes));
else
W.printEnum("Type", SymbolType, makeArrayRef(ElfSymbolTypes));
W.printNumber("Other", Symbol->st_other);
if (Symbol->st_other == 0)
// Usually st_other flag is zero. Do not pollute the output
// by flags enumeration in that case.
W.printNumber("Other", 0);
else {
std::vector<EnumEntry<unsigned>> SymOtherFlags(std::begin(ElfSymOtherFlags),
std::end(ElfSymOtherFlags));
if (Obj->getHeader()->e_machine == EM_MIPS) {
// Someones in their infinite wisdom decided to make STO_MIPS_MIPS16
// flag overlapped with other ST_MIPS_xxx flags. So consider both
// cases separately.
if ((Symbol->st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16)
SymOtherFlags.insert(SymOtherFlags.end(),
std::begin(ElfMips16SymOtherFlags),
std::end(ElfMips16SymOtherFlags));
else
SymOtherFlags.insert(SymOtherFlags.end(),
std::begin(ElfMipsSymOtherFlags),
std::end(ElfMipsSymOtherFlags));
}
W.printFlags("Other", Symbol->st_other, makeArrayRef(SymOtherFlags), 0x3u);
}
W.printHex("Section", SectionName, SectionIndex);
}