From e0c67abf26febfdecd106fec37d7c51bb13741bf Mon Sep 17 00:00:00 2001 From: Felix Kellenbenz <107758057+felixkellenbenz@users.noreply.github.com> Date: Wed, 24 Jan 2024 09:12:16 +0100 Subject: [PATCH] [llvm-objcopy] Don't remove .gnu_debuglink section when using --strip-all (#78919) This fixes the issue mentioned here: https://github.com/llvm/llvm-project/issues/57407 It prevents `llvm-objcopy` from removing the `.gnu _debuglink` section when used with the `--strip-all` flag. Since `--strip-all` is the default of `llvm-strip` the patch also prevents `llvm-strip` from removing the `.gnu_debuglink` section. --- llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 2 ++ llvm/test/tools/llvm-objcopy/ELF/strip-all.test | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp index dfe843e1d4b7..3c25d2f26ead 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -434,6 +434,8 @@ static Error replaceAndRemoveSections(const CommonConfig &Config, return false; if (StringRef(Sec.Name).startswith(".gnu.warning")) return false; + if (StringRef(Sec.Name).startswith(".gnu_debuglink")) + return false; // We keep the .ARM.attribute section to maintain compatibility // with Debian derived distributions. This is a bug in their // patchset as documented here: diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-all.test b/llvm/test/tools/llvm-objcopy/ELF/strip-all.test index 20f3c9addf55..ba27a3509c6a 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/strip-all.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-all.test @@ -68,16 +68,19 @@ Sections: Flags: [ ] - Name: .gnu.warning.foo Type: SHT_PROGBITS + - Name: .gnu_debuglink + Type: SHT_PROGBITS ProgramHeaders: # Use an arbitrary segment type to show that the segment type is unimportant. - Type: 0x61234567 FirstSec: non_alloc_in_segment LastSec: non_alloc_in_segment -# CHECK: SectionHeaderCount: 6 +# CHECK: SectionHeaderCount: 7 # CHECK: Name: non_alloc_in_segment # CHECK: Name: .bss # CHECK: Name: .text # CHECK: Name: .gnu.warning.foo +# CHECK: Name: .gnu_debuglink # CHECK: Name: .shstrtab -- Gitee