mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 13:26:08 +00:00
[ELF][llvm-objcopy] Reject duplicate SHT_SYMTAB sections
The gABI prohibits multiple SH_SYMTAB sections. As a result, llvm-objcopy was crashing in SymbolTableSection::removeSymbols(). This patch fixes the issue by emitting an error if multiple SH_SYMTAB sections are encountered when building an ELF object. Fixes: https://github.com/llvm/llvm-project/issues/60448 Differential Revision: https://reviews.llvm.org/D143508
This commit is contained in:
parent
998ad085e8
commit
bc6e10c9ef
@ -1704,6 +1704,10 @@ Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
|
||||
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;
|
||||
|
20
llvm/test/tools/llvm-objcopy/ELF/multiple-symtab.test
Normal file
20
llvm/test/tools/llvm-objcopy/ELF/multiple-symtab.test
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user