[llvm] [llvm-objcopy, test] Reorganize reserved st_shndx tests (PR #228664)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 22:59:05 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/228664
Rename section-index-unsupported.test to reserved-shndx.test, fold
unsupported-machine-specific-shndx.test into it, and enhance it.
>From 9b30c2d14a0cb3ef43d62a19783bc0e32c98b7ca Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 2 Oct 2026 22:26:16 -0700
Subject: [PATCH] [llvm-objcopy,test] Reorganize reserved st_shndx tests
Rename section-index-unsupported.test to reserved-shndx.test, fold
unsupported-machine-specific-shndx.test into it, and enhance it.
---
.../llvm-objcopy/ELF/reserved-shndx.test | 33 +++++++++++++++++++
.../ELF/section-index-unsupported.test | 15 ---------
.../unsupported-machine-specific-shndx.test | 17 ----------
3 files changed, 33 insertions(+), 32 deletions(-)
create mode 100644 llvm/test/tools/llvm-objcopy/ELF/reserved-shndx.test
delete mode 100644 llvm/test/tools/llvm-objcopy/ELF/section-index-unsupported.test
delete mode 100644 llvm/test/tools/llvm-objcopy/ELF/unsupported-machine-specific-shndx.test
diff --git a/llvm/test/tools/llvm-objcopy/ELF/reserved-shndx.test b/llvm/test/tools/llvm-objcopy/ELF/reserved-shndx.test
new file mode 100644
index 00000000000000..ba9f2ae3c756d1
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/reserved-shndx.test
@@ -0,0 +1,33 @@
+## Processor-specific values supported for e_machine are preserved.
+# RUN: yaml2obj -DMACHINE=EM_MIPS -DINDEX=SHN_MIPS_SCOMMON %s -o %t.mips
+# RUN: llvm-objcopy %t.mips %t1
+# RUN: llvm-readelf -s %t1 | FileCheck %s --check-prefix=KEEP -DNDX='PRC[0xff03]'
+
+# KEEP: 1: {{.*}} [[NDX]] sym
+
+## Other values are rejected, except SHN_ABS and SHN_COMMON, and a few processor-specific values.
+# RUN: yaml2obj -DINDEX=SHN_HEXAGON_SCOMMON %s -o %t2
+# RUN: not llvm-objcopy %t2 /dev/null 2>&1 | FileCheck %s --check-prefix=ERR -DINDEX=65280
+# RUN: yaml2obj -DINDEX=SHN_MIPS_SCOMMON %s -o %t2
+# RUN: not llvm-objcopy %t2 /dev/null 2>&1 | FileCheck %s --check-prefix=ERR -DINDEX=65283
+# RUN: yaml2obj -DTYPE=ET_EXEC -DINDEX=SHN_HIPROC %s -o %t2
+# RUN: not llvm-objcopy %t2 /dev/null 2>&1 | FileCheck %s --check-prefix=ERR -DINDEX=65311
+## [SHN_LOOS, SHN_HIOS] is OS-specific.
+# RUN: yaml2obj -DINDEX=SHN_LOOS %s -o %t2
+# RUN: not llvm-objcopy %t2 /dev/null 2>&1 | FileCheck %s --check-prefix=ERR -DINDEX=65312
+## 0xff40 is in (SHN_HIOS, SHN_ABS), which has no defined meaning.
+# RUN: yaml2obj -DINDEX=0xff40 %s -o %t2
+# RUN: not llvm-objcopy %t2 /dev/null 2>&1 | FileCheck %s --check-prefix=ERR -DINDEX=65344
+
+# ERR: error: symbol 'sym' has unsupported value greater than or equal to SHN_LORESERVE: [[INDEX]]
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: [[TYPE=ET_REL]]
+ Machine: [[MACHINE=EM_X86_64]]
+Symbols:
+ - Name: sym
+ Index: [[INDEX]]
+ Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-objcopy/ELF/section-index-unsupported.test b/llvm/test/tools/llvm-objcopy/ELF/section-index-unsupported.test
deleted file mode 100644
index 8479d00c24852e..00000000000000
--- a/llvm/test/tools/llvm-objcopy/ELF/section-index-unsupported.test
+++ /dev/null
@@ -1,15 +0,0 @@
-# RUN: yaml2obj %s -o %t
-# RUN: not llvm-objcopy %t %t2 2>&1 >/dev/null | FileCheck %s
-
-!ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_EXEC
- Machine: EM_X86_64
-Symbols:
- - Name: test
- Index: 0xff05
- Binding: STB_GLOBAL
-
-# CHECK: symbol 'test' has unsupported value greater than or equal to SHN_LORESERVE: 65285
diff --git a/llvm/test/tools/llvm-objcopy/ELF/unsupported-machine-specific-shndx.test b/llvm/test/tools/llvm-objcopy/ELF/unsupported-machine-specific-shndx.test
deleted file mode 100644
index 78494e8b3c30a2..00000000000000
--- a/llvm/test/tools/llvm-objcopy/ELF/unsupported-machine-specific-shndx.test
+++ /dev/null
@@ -1,17 +0,0 @@
-# RUN: yaml2obj %s -o %t -DMACHINE=HEXAGON
-# RUN: not llvm-objcopy %t %t2 2>&1 >/dev/null | FileCheck %s -DINDEX=65280
-# RUN: yaml2obj %s -o %t -DMACHINE=MIPS
-# RUN: not llvm-objcopy %t %t2 2>&1 >/dev/null | FileCheck %s -DINDEX=65283
-
-!ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_EXEC
- Machine: EM_X86_64
-Symbols:
- - Name: test
- Index: SHN_[[MACHINE]]_SCOMMON
- Binding: STB_GLOBAL
-
-# CHECK: symbol 'test' has unsupported value greater than or equal to SHN_LORESERVE: [[INDEX]]
More information about the llvm-commits
mailing list