[llvm] 495bd4c - [llvm-mc] Don't print initial .text for disassembler

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 23:38:51 PST 2024


Author: Fangrui Song
Date: 2024-12-16T23:38:48-08:00
New Revision: 495bd4c255a0eb0e5b4fef5240eddc5fded1911b

URL: https://github.com/llvm/llvm-project/commit/495bd4c255a0eb0e5b4fef5240eddc5fded1911b
DIFF: https://github.com/llvm/llvm-project/commit/495bd4c255a0eb0e5b4fef5240eddc5fded1911b.diff

LOG: [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: https://github.com/llvm/llvm-project/pull/120185

Added: 
    

Modified: 
    llvm/lib/MC/MCAsmStreamer.cpp
    llvm/test/MC/Disassembler/AArch64/colored.txt
    llvm/test/MC/Disassembler/ARM/arm-trustzone.txt
    llvm/test/tools/llvm-mc/line_end_with_space.test
    llvm/tools/llvm-mc/Disassembler.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index d48b384f21cbce..5084fc1d919969 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -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());

diff  --git a/llvm/test/MC/Disassembler/AArch64/colored.txt b/llvm/test/MC/Disassembler/AArch64/colored.txt
index 3293de8a8748f4..1379c552d85cc3 100644
--- a/llvm/test/MC/Disassembler/AArch64/colored.txt
+++ b/llvm/test/MC/Disassembler/AArch64/colored.txt
@@ -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

diff  --git a/llvm/test/MC/Disassembler/ARM/arm-trustzone.txt b/llvm/test/MC/Disassembler/ARM/arm-trustzone.txt
index 92d5d6b2907228..5f1e577f6729a5 100644
--- a/llvm/test/MC/Disassembler/ARM/arm-trustzone.txt
+++ b/llvm/test/MC/Disassembler/ARM/arm-trustzone.txt
@@ -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
 
 
@@ -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
 

diff  --git a/llvm/test/tools/llvm-mc/line_end_with_space.test b/llvm/test/tools/llvm-mc/line_end_with_space.test
index 5ad5a8382edfae..b9f44afc43bb4d 100644
--- a/llvm/test/tools/llvm-mc/line_end_with_space.test
+++ b/llvm/test/tools/llvm-mc/line_end_with_space.test
@@ -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

diff  --git a/llvm/tools/llvm-mc/Disassembler.cpp b/llvm/tools/llvm-mc/Disassembler.cpp
index 30577fe631d62e..16897054fbea8a 100644
--- a/llvm/tools/llvm-mc/Disassembler.cpp
+++ b/llvm/tools/llvm-mc/Disassembler.cpp
@@ -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.


        


More information about the llvm-commits mailing list