Skip to content

[llvm-mc] Don't print initial .text for disassembler #120185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Dec 17, 2024

% 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

Created using spr 1.3.5-bogner
@llvmbot llvmbot added backend:AArch64 mc Machine (object) code labels Dec 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-aarch64

Author: Fangrui Song (MaskRay)

Changes

Omit the initial .text for --disassemble.

% echo 90 | myllvm-mc -triple=x86_64 --disassemble --hex
        nop

Full diff: https://github.com/llvm/llvm-project/pull/120185.diff

3 Files Affected:

  • (modified) llvm/test/MC/Disassembler/AArch64/colored.txt (+1)
  • (modified) llvm/test/tools/llvm-mc/line_end_with_space.test (+1-1)
  • (modified) llvm/tools/llvm-mc/Disassembler.cpp (+1-1)
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	�[0;31m#20�[0m
 0x00 0x7c 0x00 0x13
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..d02445e21e4c31 100644
--- a/llvm/tools/llvm-mc/Disassembler.cpp
+++ b/llvm/tools/llvm-mc/Disassembler.cpp
@@ -169,7 +169,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
   }
 
   // Set up initial section manually here
-  Streamer.initSections(false, STI);
+  Streamer.switchSectionNoPrint(Ctx.getObjectFileInfo()->getTextSection());
 
   bool ErrorOccurred = false;
 

@MaskRay MaskRay changed the title [llvm-mc] Don't print initial .text [llvm-mc] Don't print initial .text for disassembler Dec 17, 2024
Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Created using spr 1.3.5-bogner
MaskRay added a commit that referenced this pull request Dec 17, 2024
Created using spr 1.3.5-bogner
@MaskRay MaskRay merged commit 495bd4c into main Dec 17, 2024
5 of 8 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/llvm-mc-dont-print-initial-text branch December 17, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants