Skip to content

Commit

Permalink
[llvm-readobj] Decode st_other symbol's flags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
atanasyan committed Mar 24, 2016
1 parent adb3b8d commit cc6b0d4
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/MC/Mips/elf_st_other.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions test/MC/Mips/insn-directive.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/MC/Mips/micromips-alias.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +16,7 @@ f:
bar = f

# CHECK: Name: foo
# CHECK: Other: 128
# CHECK: Other [ (0x80)
.type o,@object
.set micromips
o:
Expand Down
8 changes: 6 additions & 2 deletions test/MC/Mips/micromips-label-test-sections.s
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: ]
Expand Down
8 changes: 6 additions & 2 deletions test/MC/Mips/micromips-label-test.s
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions test/MC/PowerPC/ppc64-localentry.s
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion test/MC/PowerPC/st-other-crash.s
Original file line number Diff line number Diff line change
Expand Up @@ -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: }

Expand Down
14 changes: 11 additions & 3 deletions test/Object/yaml2obj-elf-symbol-visibility.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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: }

Expand Down
Binary file added test/tools/llvm-readobj/Inputs/st-other.obj.elf-mips
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions test/tools/llvm-readobj/mips-st-other.test
Original file line number Diff line number Diff line change
@@ -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: ]
42 changes: 41 additions & 1 deletion tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit cc6b0d4

Please sign in to comment.