[llvm] [ELF][Objcopy] Dont corrupt symbol table when `--update-section` is called for ELF files (PR #170462)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 12 08:02:32 PST 2026
================
@@ -0,0 +1,120 @@
+# REQUIRES: x86-registered-target
----------------
jh7370 wrote:
1. I think the test name might be better as `update-section-not-in-segment.test`, because that is the code path that is currently broken. The corrupt symbol table is the symptom, rather than the behaviour being tested.
2. I'm not sure I follow why your test is so elaborate, when, at least for a basic build on Windows, I can see the failure with the input I posted in the issue. The following test looks like it should be sufficient:
```
## Show that when updating a section not in a segment, symbols still correctly
## refer to the updated section.
# RUN: echo -n 11223344 > %t.data
# RUN: yaml2obj %s -o %t.in
# RUN: llvm-objcopy --update-section=.foo=%t.data %t.in %t.out
# RUN: llvm-readelf --symbols %t.out | FileCheck %s
# CHECK: Num: {{.*}} Ndx Name
# CHECK: 1: {{.*}} 1 sym
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .foo
Type: SHT_PROGBITS
Size: 0x10
Symbols:
- Name: sym
Type: STT_FUNC
Value: 0x1
Section: .foo
```
Without your patch, this test fails, since the section index referred to by the `sym` symbol is bogus (the section it references in memory doesn't have a valid index). Of course, it's possible this won't always be the case (since the memory might conveniently have the "right" value). However, as it fails at least under some configurations, it's sufficient for the purposes we have. Furthermore, there are build bots that run the lit test suite with sanitizers enabled and this test should definitely fail under this configuration.
If you want to be a little more robust/clear, you could also dump the sections and show that the .foo section index is the same as the section index referred to by the symbol entry.
https://github.com/llvm/llvm-project/pull/170462
More information about the llvm-commits
mailing list