[llvm] [llvm-objcopy] Handle SHF_ALLOC relocation sections in relocatable files (PR #227204)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 01:23:38 PDT 2026
================
@@ -0,0 +1,42 @@
+## In a relocatable file, an SHF_ALLOC relocation section (e.g. .klp.rela.* in
+## Linux livepatch modules) is a static relocation section: its symbol indexes
+## are updated and the symbols it references are kept.
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-strip --strip-unneeded %t -o %t1
+# RUN: llvm-readelf -Sr -s %t1 | FileCheck %s
+# RUN: yaml2obj -DTYPE=SHT_CREL %s -o %t.crel
+# RUN: llvm-strip --strip-unneeded %t.crel -o %t1.crel
+# RUN: llvm-readelf -Sr -s %t1.crel | FileCheck %s
+
+# CHECK: [ 2] .klp.rela.vmlinux.text {{RELA|CREL}} {{.*}} AI 3 1
+# CHECK-NEXT: [ 3] .symtab
+# CHECK: R_X86_64_PC32 {{.*}} b + 0
+# CHECK: Symbol table '.symtab' contains 2 entries:
+# CHECK: 1: {{.*}} UND b
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Content: "e800000000"
+ - Name: .klp.rela.vmlinux.text
+ Type: [[TYPE=SHT_RELA]]
+ Flags: [ SHF_ALLOC, SHF_INFO_LINK ]
+ Link: .symtab
+ Info: .text
+ Relocations:
+ - Offset: 1
+ Symbol: b
+ Type: R_X86_64_PC32
+Symbols:
+ - Name: l
+ Section: .text
+ - Name: b
----------------
jh7370 wrote:
Nit: could you change the names to be a bit more specific, e.g. "referenced" and "unreferenced" or similar, please? I think that would help a little with the test input readability.
https://github.com/llvm/llvm-project/pull/227204
More information about the llvm-commits
mailing list