[llvm] [AArch64, ELF] Omit initial $d of non-text sections (PR #99580)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 23:17:44 PDT 2024
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/99580
>From 659e8798644d4b7d99c0456e3ed5de88483d229d Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 18 Jul 2024 15:13:03 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
.../MCTargetDesc/AArch64ELFStreamer.cpp | 14 +++-
.../test/MC/AArch64/mapping-across-sections.s | 25 ++++--
llvm/test/MC/AArch64/size-directive.s | 2 +-
llvm/test/MC/ELF/AArch64/cfi.s | 81 ++++++++++---------
4 files changed, 72 insertions(+), 50 deletions(-)
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
index 7dba22c066dcd..83f40228c4ff0 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
@@ -184,11 +184,17 @@ class AArch64ELFStreamer : public MCELFStreamer {
MappingSymbolCounter(0), LastEMS(EMS_None) {}
void changeSection(MCSection *Section, uint32_t Subsection = 0) override {
- // We have to keep track of the mapping symbol state of any sections we
- // use. Each one should start off as EMS_None, which is provided as the
- // default constructor by DenseMap::lookup.
+ // We have to keep track of the mapping symbol state of any sections we use.
+ // Text sections start as EMS_None because the ABI requires that a section
+ // that contains instructions must have a mapping symbol defined at the
+ // beginning. Non-text sections can start as EMS_Data, since they can only
+ // contain instructions in erroneous cases.
LastMappingSymbols[getPreviousSection().first] = LastEMS;
- LastEMS = LastMappingSymbols.lookup(Section);
+ auto It = LastMappingSymbols.find(Section);
+ if (It != LastMappingSymbols.end())
+ LastEMS = It->second;
+ else
+ LastEMS = Section->isText() ? EMS_None : EMS_Data;
MCELFStreamer::changeSection(Section, Subsection);
}
diff --git a/llvm/test/MC/AArch64/mapping-across-sections.s b/llvm/test/MC/AArch64/mapping-across-sections.s
index 053deb760dcfd..6b5e2b21e41b0 100644
--- a/llvm/test/MC/AArch64/mapping-across-sections.s
+++ b/llvm/test/MC/AArch64/mapping-across-sections.s
@@ -7,22 +7,37 @@
.section .wibble
add w0, w0, w0
-// A setion should be able to start with a $d
- .section .starts_data
+// A new text setion should be able to start with a $d
+ .section .starts_data,"ax"
.word 42
// Changing back to .text should not emit a redundant $x
.text
add w0, w0, w0
+// Non-text sections do not need the initial $d.
+ .section .data,"aw"
+ .word 42
+
+ .text
+ add w0, w0, w0
+
+// Instructions in error scenarios could cause emission of $x and $d.
+ .section .rodata,"a"
+ .word 42
+ add w0, w0, w0
+ .word 42
+
// With all those constraints, we want:
// + .text to have $x at 0 and no others
// + .wibble to have $x at 0
// + .starts_data to have $d at 0
-// CHECK: 0000000000000000 l .text 0000000000000000 $x
-// CHECK-NEXT: 0000000000000000 l .wibble 0000000000000000 $x
-// CHECK-NEXT: 0000000000000000 l .starts_data 0000000000000000 $d
+// CHECK: 0000000000000000 l .text 0000000000000000 $x.0
+// CHECK-NEXT: 0000000000000000 l .wibble 0000000000000000 $x.1
+// CHECK-NEXT: 0000000000000000 l .starts_data 0000000000000000 $d.2
+// CHECK-NEXT: 0000000000000004 l .rodata 0000000000000000 $x.3
+// CHECK-NEXT: 0000000000000008 l .rodata 0000000000000000 $d.4
// CHECK-NOT: ${{[adtx]}}
diff --git a/llvm/test/MC/AArch64/size-directive.s b/llvm/test/MC/AArch64/size-directive.s
index 0b19cda4eaa1e..77243875dd78a 100644
--- a/llvm/test/MC/AArch64/size-directive.s
+++ b/llvm/test/MC/AArch64/size-directive.s
@@ -32,7 +32,7 @@ aarch64_size:
// CHECK-OBJ-NEXT: )
// SYMS: Type Bind Vis Ndx Name
-// SYMS: NOTYPE LOCAL DEFAULT 3 $d.0
+// SYMS: NOTYPE LOCAL DEFAULT UND
// SYMS-NEXT: FUNC GLOBAL DEFAULT 3 aarch64_size
// SYMS-NEXT: NOTYPE GLOBAL DEFAULT UND half_word
// SYMS-NEXT: NOTYPE GLOBAL DEFAULT UND full_word
diff --git a/llvm/test/MC/ELF/AArch64/cfi.s b/llvm/test/MC/ELF/AArch64/cfi.s
index 033c8d9c04094..fcf980863821e 100644
--- a/llvm/test/MC/ELF/AArch64/cfi.s
+++ b/llvm/test/MC/ELF/AArch64/cfi.s
@@ -354,14 +354,15 @@ f37:
// CHECK-NEXT: 06D0: 24000000 00000000 04000000 00000000 |$...............|
// CHECK-NEXT: )
// CHECK-NEXT: }
-// CHECK: Section {
-// CHECK: Name: .rela.eh_frame (15)
+// CHECK-NEXT: Section {
+// CHECK-NEXT: Index: 4
+// CHECK-NEXT: Name: .rela.eh_frame (15)
// CHECK-NEXT: Type: SHT_RELA (0x4)
// CHECK-NEXT: Flags [ (0x40)
// CHECK-NEXT: SHF_INFO_LINK (0x40)
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
-// CHECK-NEXT: Offset: 0xBA0
+// CHECK-NEXT: Offset: 0xB88
// CHECK-NEXT: Size: 1752
// CHECK-NEXT: Link: 5
// CHECK-NEXT: Info: 3
@@ -446,111 +447,111 @@ f37:
// CHECK-NEXT: 0000: 1C000000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0010: 8C000000 00000000 48000000 00000000 |........H.......|
// CHECK-NEXT: 0020: 05010000 01000000 08000000 00000000 |................|
-// CHECK-NEXT: 0030: 51000000 00000000 02010000 28000000 |Q...........(...|
+// CHECK-NEXT: 0030: 51000000 00000000 02010000 27000000 |Q...........'...|
// CHECK-NEXT: 0040: 00000000 00000000 78000000 00000000 |........x.......|
// CHECK-NEXT: 0050: 05010000 01000000 00000000 00000000 |................|
-// CHECK-NEXT: 0060: 81000000 00000000 02010000 28000000 |............(...|
+// CHECK-NEXT: 0060: 81000000 00000000 02010000 27000000 |............'...|
// CHECK-NEXT: 0070: 00000000 00000000 9B000000 00000000 |................|
-// CHECK-NEXT: 0080: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0080: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0090: B0000000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 00A0: 0C000000 00000000 B9000000 00000000 |................|
-// CHECK-NEXT: 00B0: 03010000 28000000 00000000 00000000 |....(...........|
-// CHECK-NEXT: 00C0: CF000000 00000000 01010000 29000000 |............)...|
+// CHECK-NEXT: 00B0: 03010000 27000000 00000000 00000000 |....'...........|
+// CHECK-NEXT: 00C0: CF000000 00000000 01010000 28000000 |............(...|
// CHECK-NEXT: 00D0: 00000000 00000000 E4000000 00000000 |................|
// CHECK-NEXT: 00E0: 05010000 01000000 04000000 00000000 |................|
-// CHECK-NEXT: 00F0: ED000000 00000000 02010000 28000000 |............(...|
+// CHECK-NEXT: 00F0: ED000000 00000000 02010000 27000000 |............'...|
// CHECK-NEXT: 0100: 00000000 00000000 06010000 00000000 |................|
-// CHECK-NEXT: 0110: 03010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0110: 03010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0120: 14010000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0130: 10000000 00000000 32010000 00000000 |........2.......|
-// CHECK-NEXT: 0140: 02010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0140: 02010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0150: 44010000 00000000 05010000 01000000 |D...............|
// CHECK-NEXT: 0160: 14000000 00000000 62010000 00000000 |........b.......|
-// CHECK-NEXT: 0170: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0170: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0180: 78010000 00000000 05010000 01000000 |x...............|
// CHECK-NEXT: 0190: 18000000 00000000 96010000 00000000 |................|
-// CHECK-NEXT: 01A0: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 01A0: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 01B0: AC010000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 01C0: 28000000 00000000 CA010000 00000000 |(...............|
-// CHECK-NEXT: 01D0: 03010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 01D0: 03010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 01E0: D8010000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 01F0: 1C000000 00000000 F6010000 00000000 |................|
-// CHECK-NEXT: 0200: 02010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0200: 02010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0210: 08020000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0220: 20000000 00000000 26020000 00000000 | .......&.......|
-// CHECK-NEXT: 0230: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0230: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0240: 3C020000 00000000 05010000 01000000 |<...............|
// CHECK-NEXT: 0250: 24000000 00000000 5A020000 00000000 |$.......Z.......|
-// CHECK-NEXT: 0260: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0260: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0270: 70020000 00000000 05010000 01000000 |p...............|
// CHECK-NEXT: 0280: 2C000000 00000000 8E020000 00000000 |,...............|
-// CHECK-NEXT: 0290: 06010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0290: 06010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 02A0: 9C020000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 02B0: 30000000 00000000 BA020000 00000000 |0...............|
-// CHECK-NEXT: 02C0: 05010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 02C0: 05010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 02D0: CC020000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 02E0: 34000000 00000000 EA020000 00000000 |4...............|
-// CHECK-NEXT: 02F0: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 02F0: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0300: 00030000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0310: 38000000 00000000 1E030000 00000000 |8...............|
-// CHECK-NEXT: 0320: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0320: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0330: 34030000 00000000 05010000 01000000 |4...............|
// CHECK-NEXT: 0340: 48000000 00000000 52030000 00000000 |H.......R.......|
-// CHECK-NEXT: 0350: 06010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0350: 06010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0360: 60030000 00000000 05010000 01000000 |`...............|
// CHECK-NEXT: 0370: 3C000000 00000000 7E030000 00000000 |<.......~.......|
-// CHECK-NEXT: 0380: 05010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0380: 05010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0390: 90030000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 03A0: 40000000 00000000 AE030000 00000000 |@...............|
-// CHECK-NEXT: 03B0: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 03B0: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 03C0: C4030000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 03D0: 44000000 00000000 E2030000 00000000 |D...............|
-// CHECK-NEXT: 03E0: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 03E0: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 03F0: F8030000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0400: 4C000000 00000000 16040000 00000000 |L...............|
-// CHECK-NEXT: 0410: 03010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0410: 03010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0420: 24040000 00000000 05010000 01000000 |$...............|
// CHECK-NEXT: 0430: 50000000 00000000 42040000 00000000 |P.......B.......|
-// CHECK-NEXT: 0440: 02010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0440: 02010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0450: 54040000 00000000 05010000 01000000 |T...............|
// CHECK-NEXT: 0460: 54000000 00000000 72040000 00000000 |T.......r.......|
-// CHECK-NEXT: 0470: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0470: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0480: 88040000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0490: 58000000 00000000 A6040000 00000000 |X...............|
-// CHECK-NEXT: 04A0: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 04A0: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 04B0: BC040000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 04C0: 68000000 00000000 DA040000 00000000 |h...............|
-// CHECK-NEXT: 04D0: 03010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 04D0: 03010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 04E0: E8040000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 04F0: 5C000000 00000000 06050000 00000000 |\...............|
-// CHECK-NEXT: 0500: 02010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0500: 02010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0510: 18050000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0520: 60000000 00000000 36050000 00000000 |`.......6.......|
-// CHECK-NEXT: 0530: 01010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0530: 01010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0540: 4C050000 00000000 05010000 01000000 |L...............|
// CHECK-NEXT: 0550: 64000000 00000000 6A050000 00000000 |d.......j.......|
-// CHECK-NEXT: 0560: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0560: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0570: 80050000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0580: 6C000000 00000000 9E050000 00000000 |l...............|
-// CHECK-NEXT: 0590: 06010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0590: 06010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 05A0: AC050000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 05B0: 70000000 00000000 CA050000 00000000 |p...............|
-// CHECK-NEXT: 05C0: 05010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 05C0: 05010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 05D0: DC050000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 05E0: 74000000 00000000 FA050000 00000000 |t...............|
-// CHECK-NEXT: 05F0: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 05F0: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0600: 10060000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 0610: 78000000 00000000 2E060000 00000000 |x...............|
-// CHECK-NEXT: 0620: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0620: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0630: 44060000 00000000 05010000 01000000 |D...............|
// CHECK-NEXT: 0640: 88000000 00000000 62060000 00000000 |........b.......|
-// CHECK-NEXT: 0650: 06010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0650: 06010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0660: 70060000 00000000 05010000 01000000 |p...............|
// CHECK-NEXT: 0670: 7C000000 00000000 8E060000 00000000 ||...............|
-// CHECK-NEXT: 0680: 05010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 0680: 05010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 0690: A0060000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 06A0: 80000000 00000000 BE060000 00000000 |................|
-// CHECK-NEXT: 06B0: 04010000 29000000 00000000 00000000 |....)...........|
+// CHECK-NEXT: 06B0: 04010000 28000000 00000000 00000000 |....(...........|
// CHECK-NEXT: 06C0: D4060000 00000000 05010000 01000000 |................|
// CHECK-NEXT: 06D0: 84000000 00000000 |........|
// CHECK-NEXT: )
More information about the llvm-commits
mailing list