[PATCH] D82274: [llvm-objcopy] Emit error if removing symbol table referenced by SHT_GROUP section
Georgy Komarov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 23 19:27:01 PDT 2020
jubnzv updated this revision to Diff 272889.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D82274/new/
https://reviews.llvm.org/D82274
Files:
llvm/test/tools/llvm-objcopy/ELF/group.test
llvm/tools/llvm-objcopy/ELF/Object.cpp
Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -972,6 +972,13 @@
Error GroupSection::removeSectionReferences(
bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) {
+ if (ToRemove(SymTab) && !AllowBrokenLinks) {
+ return createStringError(
+ llvm::errc::invalid_argument,
+ "section '.symtab' cannot be removed because it is "
+ "referenced by the group section '%s'",
+ this->Name.data());
+ }
llvm::erase_if(GroupMembers, ToRemove);
return Error::success();
}
Index: llvm/test/tools/llvm-objcopy/ELF/group.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/group.test
+++ llvm/test/tools/llvm-objcopy/ELF/group.test
@@ -1,6 +1,6 @@
# RUN: yaml2obj %s -o %t
-# RUN: llvm-objcopy --remove-section=.text.bar %t %t2
-# RUN: llvm-readobj --elf-section-groups %t2 | FileCheck %s
+# RUN: llvm-objcopy --remove-section=.text.bar %t %t1
+# RUN: llvm-readobj --elf-section-groups %t1 | FileCheck %s
# In this test the section .text.bar is getting removed, as a result,
# the indices of the sections which go after .text.bar will change,
@@ -54,3 +54,25 @@
Section: .text.foo
Size: 0x0000000000000000
Binding: STB_WEAK
+
+## This checks that tool will emit an error when trying to remove the symbol
+## table when we have the a group section linked with symtab.
+# RUN: not llvm-objcopy -R .symtab %t %t2 2>&1 | FileCheck %s --check-prefix=ERR -DINPUT=%t
+
+# ERR: error: '[[INPUT]]': section '.symtab' cannot be removed because it is referenced by the group section '.group'
+
+## The '.symtab' section could be removed using --allow-broken-links option.
+# RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t3
+# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=SECTIONS
+
+# SECTIONS: There are 6 section headers
+# SECTIONS: Name
+# SECTIONS-NEXT: NULL
+# SECTIONS-NEXT: .group
+# SECTIONS-NEXT: .text.bar
+# SECTIONS-NEXT: .text.foo
+# SECTIONS-NEXT: .strtab
+# SECTIONS-NEXT: .shstrtab
+
+## Nothing will change when removing symtab again; tool should exit with return code 0.
+# RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82274.272889.patch
Type: text/x-patch
Size: 2384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200624/e1ef9fb3/attachment.bin>
More information about the llvm-commits
mailing list