Skip to content

Commit

Permalink
[llvm-mc] Don't print initial .text for disassembler
Browse files Browse the repository at this point in the history
```
% echo 90 | llvm-mc -triple=x86_64 --disassemble --hex
	.text
        nop
```

The initial `.text` kludge is due `initSection`, which is actually only
needed by AIX XCOFF for its `getCurrentSectionOnly()` use in
MCAsmStreamer::emitInstruction (https://reviews.llvm.org/D95518). Adjust
MCAsmStreamer::emitInstruction to not trigger failures on

```
echo 7c4303a6 | llvm-mc --cdis --hex --triple=powerpc-aix-ibm-xcoff
```

Pull Request: llvm/llvm-project#120185
  • Loading branch information
MaskRay authored Dec 17, 2024
1 parent 6db1b20 commit 495bd4c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 11 deletions.
5 changes: 1 addition & 4 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,10 +2428,7 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,

void MCAsmStreamer::emitInstruction(const MCInst &Inst,
const MCSubtargetInfo &STI) {
assert(getCurrentSectionOnly() &&
"Cannot emit contents before setting section!");

if (!MAI->usesDwarfFileAndLocDirectives())
if (!MAI->usesDwarfFileAndLocDirectives() && CurFrag)
// Now that a machine instruction has been assembled into this section, make
// a line entry for any .loc directive that has been seen.
MCDwarfLineEntry::make(this, getCurrentSectionOnly());
Expand Down
1 change: 1 addition & 0 deletions llvm/test/MC/Disassembler/AArch64/colored.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# UNSUPPORTED: system-windows
# RUN: llvm-mc -triple=aarch64 -mattr=+all --cdis %s | FileCheck %s --strict-whitespace --match-full-lines

# CHECK-NOT:{{.}}
0xa1 0x00 0x00 0x54
# CHECK: b.ne #20
0x00 0x7c 0x00 0x13
Expand Down
5 changes: 2 additions & 3 deletions llvm/test/MC/Disassembler/ARM/arm-trustzone.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RUN: llvm-mc -triple=armv7-apple-darwin -mcpu=cortex-a8 -disassemble -mattr=-trustzone < %s | FileCheck %s -check-prefix=NOTZ
# RUN: llvm-mc -triple=armv7-apple-darwin -mcpu=cortex-a8 -disassemble -mattr=-trustzone %s 2>&1 | FileCheck %s -check-prefix=NOTZ
# RUN: llvm-mc -triple=armv7-apple-darwin -mcpu=cortex-a8 -disassemble -mattr=trustzone < %s | FileCheck %s -check-prefix=TZ


Expand All @@ -9,8 +9,7 @@
0x7f 0x00 0x60 0xe1
0x70 0x00 0x60 0x01

# NOTZ-NOT: smc #15
# NOTZ-NOT: smceq #0
# NOTZ-COUNT-2: warning: invalid instruction encoding
# TZ: smc #15
# TZ: smceq #0

2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-mc/line_end_with_space.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Test that llvm-mc doesn't crash when disassembling a line that ends with a
# space.
RUN: echo -n ' ' | llvm-mc -disassemble
RUN: echo -n ' ' | llvm-mc -disassemble | count 0
3 changes: 0 additions & 3 deletions llvm/tools/llvm-mc/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
return -1;
}

// Set up initial section manually here
Streamer.initSections(false, STI);

bool ErrorOccurred = false;

// Convert the input to a vector for disassembly.
Expand Down

0 comments on commit 495bd4c

Please sign in to comment.