Skip to content

Commit 495bd4c

Browse files
authored
[llvm-mc] Don't print initial .text for disassembler
``` % 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: #120185
1 parent 6db1b20 commit 495bd4c

File tree

5 files changed

+5
-11
lines changed

5 files changed

+5
-11
lines changed

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,10 +2428,7 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
24282428

24292429
void MCAsmStreamer::emitInstruction(const MCInst &Inst,
24302430
const MCSubtargetInfo &STI) {
2431-
assert(getCurrentSectionOnly() &&
2432-
"Cannot emit contents before setting section!");
2433-
2434-
if (!MAI->usesDwarfFileAndLocDirectives())
2431+
if (!MAI->usesDwarfFileAndLocDirectives() && CurFrag)
24352432
// Now that a machine instruction has been assembled into this section, make
24362433
// a line entry for any .loc directive that has been seen.
24372434
MCDwarfLineEntry::make(this, getCurrentSectionOnly());

llvm/test/MC/Disassembler/AArch64/colored.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# UNSUPPORTED: system-windows
22
# RUN: llvm-mc -triple=aarch64 -mattr=+all --cdis %s | FileCheck %s --strict-whitespace --match-full-lines
33

4+
# CHECK-NOT:{{.}}
45
0xa1 0x00 0x00 0x54
56
# CHECK: b.ne #20
67
0x00 0x7c 0x00 0x13
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: llvm-mc -triple=armv7-apple-darwin -mcpu=cortex-a8 -disassemble -mattr=-trustzone < %s | FileCheck %s -check-prefix=NOTZ
1+
# RUN: llvm-mc -triple=armv7-apple-darwin -mcpu=cortex-a8 -disassemble -mattr=-trustzone %s 2>&1 | FileCheck %s -check-prefix=NOTZ
22
# RUN: llvm-mc -triple=armv7-apple-darwin -mcpu=cortex-a8 -disassemble -mattr=trustzone < %s | FileCheck %s -check-prefix=TZ
33

44

@@ -9,8 +9,7 @@
99
0x7f 0x00 0x60 0xe1
1010
0x70 0x00 0x60 0x01
1111

12-
# NOTZ-NOT: smc #15
13-
# NOTZ-NOT: smceq #0
12+
# NOTZ-COUNT-2: warning: invalid instruction encoding
1413
# TZ: smc #15
1514
# TZ: smceq #0
1615

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Test that llvm-mc doesn't crash when disassembling a line that ends with a
22
# space.
3-
RUN: echo -n ' ' | llvm-mc -disassemble
3+
RUN: echo -n ' ' | llvm-mc -disassemble | count 0

llvm/tools/llvm-mc/Disassembler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
168168
return -1;
169169
}
170170

171-
// Set up initial section manually here
172-
Streamer.initSections(false, STI);
173-
174171
bool ErrorOccurred = false;
175172

176173
// Convert the input to a vector for disassembly.

0 commit comments

Comments
 (0)