[lld] dc9be4e - [LLD][ELF] Skip non-inputsections to avoid invalid cast in Arm BE8 handling (#188154)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 02:16:59 PDT 2026
Author: Simi Pallipurath
Date: 2026-04-02T10:16:54+01:00
New Revision: dc9be4ee30d07060a21273bdf8c64e4f34165562
URL: https://github.com/llvm/llvm-project/commit/dc9be4ee30d07060a21273bdf8c64e4f34165562
DIFF: https://github.com/llvm/llvm-project/commit/dc9be4ee30d07060a21273bdf8c64e4f34165562.diff
LOG: [LLD][ELF] Skip non-inputsections to avoid invalid cast in Arm BE8 handling (#188154)
This patch fixes https://github.com/llvm/llvm-project/issues/187033
In BE8 mode, instruction bytes are reversed for sections containing
code. This logic currently assumes that arm mapping symbols (e.g. $a,
$t, $d) are always associated with InputSections.
However, mapping symbols can also be defined in other section types such
as mergeable sections (SHF_MERGE). These are not represented as
InputSection, and attempting to cast them using
cast_if_present<InputSection> results in an assertion failure.
Added:
lld/test/ELF/arm-be8-data-mapsym.s
Modified:
lld/ELF/Arch/ARM.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index f55da7afb891e..e0b2f321264b5 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1183,7 +1183,7 @@ void elf::addArmInputSectionMappingSymbols(Ctx &ctx) {
if (!isArmMapSymbol(def) && !isDataMapSymbol(def) &&
!isThumbMapSymbol(def))
continue;
- if (auto *sec = cast_if_present<InputSection>(def->section))
+ if (auto *sec = dyn_cast_if_present<InputSection>(def->section))
if (sec->flags & SHF_EXECINSTR)
sectionMap[sec].push_back(def);
}
diff --git a/lld/test/ELF/arm-be8-data-mapsym.s b/lld/test/ELF/arm-be8-data-mapsym.s
new file mode 100644
index 0000000000000..e48ad6ec53203
--- /dev/null
+++ b/lld/test/ELF/arm-be8-data-mapsym.s
@@ -0,0 +1,19 @@
+/// REQUIRES: arm
+/// ARM big-endian(BE-8) reversal needs to account for explicit mapping
+/// symbols in data sections not represented as an InputSection. SHF_MERGE sections
+/// are an example of such a section.
+
+// RUN: llvm-mc -filetype=obj -triple=armv7aeb-none-linux-gnueabi %s -o %t.o
+// RUN: ld.lld --be8 %t.o -shared -o %t
+// RUN: llvm-readelf -S -x .merge %t | FileCheck %s
+
+// CHECK: Hex dump of section '.merge':
+// CHECK-NEXT: 0x0000014d 11223344
+
+.section .merge, "aM", %progbits, 4
+/// GNU assembler adds a mapping symbol for this SHF_MERGE data section.
+/// Clang integrated assembler uses the implicit $d from the section type,
+/// so add one manually to match GNU assembler output.
+.local $d.1
+$d.1:
+ .word 0x11223344
More information about the llvm-commits
mailing list