[llvm] 9814675 - [SPARC] Support the .seg directive (#209001)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 02:07:23 PDT 2026
Author: Kirill A. Korinsky
Date: 2026-07-30T05:07:18-04:00
New Revision: 98146752c8a6a7b3b3af1f0820f2f530aee5b925
URL: https://github.com/llvm/llvm-project/commit/98146752c8a6a7b3b3af1f0820f2f530aee5b925
DIFF: https://github.com/llvm/llvm-project/commit/98146752c8a6a7b3b3af1f0820f2f530aee5b925.diff
LOG: [SPARC] Support the .seg directive (#209001)
Support the legacy .seg directive used by SunOS SPARC assembly. Map
"text", "data", "data1", and "bss" to their corresponding MC sections,
using subsection 1 for "data1".
Added:
llvm/test/MC/Sparc/Directives/seg.s
Modified:
llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index f6b8e0af67150..c6be2489e66ac 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -39,6 +39,7 @@
#include <cassert>
#include <cstdint>
#include <memory>
+#include <string>
using namespace llvm;
@@ -1044,6 +1045,27 @@ ParseStatus SparcAsmParser::parseDirective(AsmToken DirectiveID) {
Parser.eatToEndOfStatement();
return ParseStatus::Success;
}
+ if (IDVal == ".seg") {
+ std::string Name;
+ if (Parser.parseEscapedString(Name) || Parser.parseEOL())
+ return ParseStatus::Failure;
+
+ MCSection *Section;
+ uint32_t Subsection = 0;
+ const MCObjectFileInfo *MCOFI = getContext().getObjectFileInfo();
+ if (Name == "text") {
+ Section = MCOFI->getTextSection();
+ } else if (Name == "data" || Name == "data1") {
+ Section = MCOFI->getDataSection();
+ Subsection = Name == "data1" ? 1 : 0;
+ } else if (Name == "bss") {
+ Section = MCOFI->getBSSSection();
+ } else {
+ return Error(DirectiveID.getLoc(), "unknown segment type");
+ }
+ getStreamer().switchSection(Section, Subsection);
+ return ParseStatus::Success;
+ }
// Let the MC layer to handle other directives.
return ParseStatus::NoMatch;
diff --git a/llvm/test/MC/Sparc/Directives/seg.s b/llvm/test/MC/Sparc/Directives/seg.s
new file mode 100644
index 0000000000000..e4ff6e55861fc
--- /dev/null
+++ b/llvm/test/MC/Sparc/Directives/seg.s
@@ -0,0 +1,36 @@
+! RUN: llvm-mc -triple=sparc -filetype=obj %s -o - \
+! RUN: | llvm-readobj -S --sd - | FileCheck %s
+! RUN: llvm-mc -triple=sparcv9 -filetype=obj %s -o - \
+! RUN: | llvm-readobj -S --sd - | FileCheck %s
+! RUN: not llvm-mc -triple=sparc --defsym ERR=1 %s -o /dev/null 2>&1 \
+! RUN: | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
+
+! CHECK: Name: .text
+! CHECK: SectionData (
+! CHECK-NEXT: 0000: 01
+
+! CHECK: Name: .data
+! CHECK: SectionData (
+! CHECK-NEXT: 0000: 02030405
+
+! CHECK: Name: .bss
+! CHECK-NEXT: Type: SHT_NOBITS
+! CHECK: Size: 6
+
+.seg "data1"
+.byte 4
+.seg "data"
+.byte 2
+.seg "text"
+.byte 1
+.seg "data1"
+.byte 5
+.seg "data"
+.byte 3
+.seg "bss"
+.zero 6
+
+.ifdef ERR
+! ERR: :[[#@LINE+1]]:1: error: unknown segment type
+.seg "rodata"
+.endif
More information about the llvm-commits
mailing list