Files
clang-p2996/llvm/test/tools/llvm-objdump/ELF/data-vs-code-priority.s
Simon Tatham 8e29f3f1c3 [llvm-objdump] Handle multiple syms at same addr in disassembly.
The main disassembly loop in llvm-objdump works by iterating through
the symbols in a code section, and for each one, dumping the range of
the section from that symbol to the next. If there's another symbol
defined at the same location, then that range will have length 0, and
llvm-objdump will skip over the symbol entirely.

As a result, llvm-objdump will only show the last of the symbols
defined at that address. Not only that, but the other symbols won't
even be checked against the `--disassemble-symbol` list. So if you
have two symbols `foo` and `bar` defined in the same place, then one
of `--disassemble-symbol=foo` and `--disassemble-symbol=bar` will
generate an error message and no disassembly.

I think a better approach in that situation is to prioritise display
of the symbol the user actually asked for. Also, if the user
specifically asks for disassembly of //both// of two symbols defined
at the same address, the best response I can think of is to
disassemble the code once, preceded by both symbol names.

This involves teaching llvm-objdump to be able to display more than
one symbol name at the head of a disassembled section, which also
makes it possible to implement a `--show-all-symbols` option to
display //every// symbol defined in the code, not just the most
preferred one at each address.

This change also turns out to fix a bug in which `--disassemble-all`
on a mixed Arm/Thumb ELF file would fail to switch disassembly states
between Arm and Thumb functions, because the mapping symbols were
accidentally ignored.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D131589
2022-08-24 15:08:12 +01:00

67 lines
1.7 KiB
ArmAsm

@ REQUIRES: arm-registered-target
// Test that code symbols take priority over data symbols if both are
// defined at the same address during disassembly.
//
// In the past, llvm-objdump would select the alphabetically last
// symbol at each address. To demonstrate that it's now choosing by
// symbol type, we define pairs of code and data symbols at the same
// address in such a way that the code symbol and data symbol each
// have a chance to appear alphabetically last. Also, we test that
// both STT_FUNC and STT_NOTYPE are regarded as code symbols.
@ RUN: llvm-mc -triple armv8a-unknown-linux -filetype=obj %s -o %t.o
@ RUN: llvm-objdump --triple armv8a -d %t.o | FileCheck %s
// Ensure that all four instructions in the section are disassembled
// rather than dumped as data, and that in each case, the code symbol
// is displayed before the disassembly, and not the data symbol at the
// same address.
@ CHECK: Disassembly of section .text:
@ CHECK-EMPTY:
@ CHECK-NEXT: <A1function>:
@ CHECK-NEXT: movw r0, #1
@ CHECK-EMPTY:
@ CHECK-NEXT: <B2function>:
@ CHECK-NEXT: movw r0, #2
@ CHECK-EMPTY:
@ CHECK-NEXT: <A3notype>:
@ CHECK-NEXT: movw r0, #3
@ CHECK-EMPTY:
@ CHECK-NEXT: <B4notype>:
@ CHECK-NEXT: movw r0, #4
.text
.globl A1function
.globl B2function
.globl A3notype
.globl B4notype
.globl B1object
.globl A2object
.globl B3object
.globl A4object
.type A1function,%function
.type B2function,%function
.type A3notype,%notype
.type B4notype,%notype
.type B1object,%object
.type A2object,%object
.type B3object,%object
.type A4object,%object
A1function:
B1object:
movw r0, #1
A2object:
B2function:
movw r0, #2
A3notype:
B3object:
movw r0, #3
A4object:
B4notype:
movw r0, #4