Fixed llvm-objcopy to add correct symbol table for ELF with program headers.

This fixes the following bugs:
https://bugs.llvm.org/show_bug.cgi?id=43935

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D102258
This commit is contained in:
Alex Orlov 2021-05-12 12:39:30 +04:00
parent 44642505ce
commit d8e65585f7
2 changed files with 27 additions and 0 deletions

View File

@ -105,3 +105,26 @@ DynamicSymbols:
Binding: STB_GLOBAL
Symbols: []
...
## Check the created .symtab is correct when there are program headers.
# RUN: yaml2obj --docnum=4 %s -o %t4
# RUN: llvm-objcopy %t4 %t4.add --add-symbol foo=1234
# RUN: llvm-readelf -s %t4.add | FileCheck --check-prefix=SEC4 %s
# SEC4: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
# SEC4-NEXT: 1: 00000000000004d2 0 NOTYPE GLOBAL DEFAULT ABS foo
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
ProgramHeaders:
- Type: PT_LOAD
FirstSec: .foo
LastSec: .foo
...

View File

@ -1205,6 +1205,10 @@ static bool sectionWithinSegment(const SectionBase &Sec, const Segment &Seg) {
// not the first.
uint64_t SecSize = Sec.Size ? Sec.Size : 1;
// Ignore just added sections.
if (Sec.OriginalOffset == std::numeric_limits<uint64_t>::max())
return false;
if (Sec.Type == SHT_NOBITS) {
if (!(Sec.Flags & SHF_ALLOC))
return false;