[PATCH] D143508: [ELF][llvm-objcopy] Reject duplicate SHT_SYMTAB sections.

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 09:59:51 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc6e10c9efca: [ELF][llvm-objcopy] Reject duplicate SHT_SYMTAB sections (authored by Moshe Berman <mosheberman at users.noreply.github.com>, committed by jhenderson).

Changed prior to commit:
  https://reviews.llvm.org/D143508?vs=498374&id=498427#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143508/new/

https://reviews.llvm.org/D143508

Files:
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/test/tools/llvm-objcopy/ELF/multiple-symtab.test


Index: llvm/test/tools/llvm-objcopy/ELF/multiple-symtab.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/multiple-symtab.test
@@ -0,0 +1,20 @@
+## According to the ELF gABI, "Currently, an object file may have only one
+## section of each type [SHT_SYMTAB and SHT_DYNSYM], but this restriction may be
+## relaxed in the future."
+## This test shows that we emit an error if we encounter multiple SHT_SYMTAB
+## sections.
+# RUN: yaml2obj %s -o %t
+# RUN: not llvm-objcopy %t /dev/null 2>&1 | FileCheck %s
+
+# CHECK: error: found multiple SHT_SYMTAB sections
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+Sections:
+  - Name: .symtab
+    Type: SHT_SYMTAB
+  - Name: .symtab2
+    Type: SHT_SYMTAB
Index: llvm/lib/ObjCopy/ELF/ELFObject.cpp
===================================================================
--- llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -1704,6 +1704,10 @@
     else
       return Data.takeError();
   case SHT_SYMTAB: {
+    // Multiple SHT_SYMTAB sections are forbidden by the ELF gABI.
+    if (Obj.SymbolTable != nullptr)
+      return createStringError(llvm::errc::invalid_argument,
+                               "found multiple SHT_SYMTAB sections");
     auto &SymTab = Obj.addSection<SymbolTableSection>();
     Obj.SymbolTable = &SymTab;
     return SymTab;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143508.498427.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230217/62325105/attachment.bin>


More information about the llvm-commits mailing list