[PATCH] D143508: [ELF][llvm-objcopy] Reject duplicate SHT_SYMTAB sections.
Moshe via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 7 08:51:15 PST 2023
MosheBerman created this revision.
MosheBerman added a reviewer: jhenderson.
Herald added subscribers: abrachet, hiraditya, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a project: All.
MosheBerman requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.
This commit addresses [issue #60448][1].
- Add a check for duplicate `SHT_SYMTAB` sections.
- Add a test that verifies that the error is logged as expected.
Code Style
----------
I looked at the relevant parts of the [LLVM Coding Standards][2] for guidance on formatting the logic checking, but didn't see anything explicit.
1. Error message
- I included the quote from the ELF gABI docs in the error message to make it more searchable online.
- If we can add a suggestion for how a user can proceed that would be great, imo.
[1]: https://github.com/llvm/llvm-project/issues/60448
[2]: https://llvm.org/docs/CodingStandards.html#assert-liberally
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143508
Files:
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/test/tools/llvm-objcopy/ELF/symtab-duplicate.test
Index: llvm/test/tools/llvm-objcopy/ELF/symtab-duplicate.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/symtab-duplicate.test
@@ -0,0 +1,18 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not llvm-objcopy -O binary %t - 2>&1 | FileCheck %s --check-prefix=SYMTAB
+# SYMTAB: found multiple SHT_SYMTAB sections; Currently, an object file may have only one
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Flags: [ SHF_ALLOC ]
+ - Name: .symtab2
+ Type: SHT_SYMTAB
+ Flags: [ SHF_ALLOC ]
+
\ No newline at end of file
Index: llvm/lib/ObjCopy/ELF/ELFObject.cpp
===================================================================
--- llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -1704,6 +1704,11 @@
else
return Data.takeError();
case SHT_SYMTAB: {
+ // Duplicate SHT_SYMTAB sections are forbidden by the ELF gABI.
+ if (Obj.SymbolTable != nullptr)
+ return createStringError(llvm::errc::invalid_argument,
+ "found multiple SHT_SYMTAB sections. "
+ "Currently, an object file may have only one");
auto &SymTab = Obj.addSection<SymbolTableSection>();
Obj.SymbolTable = &SymTab;
return SymTab;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143508.495565.patch
Type: text/x-patch
Size: 1416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230207/e094e575/attachment.bin>
More information about the llvm-commits
mailing list