Skip to content

Commit 683a35d

Browse files
author
George Rimar
committedAug 12, 2016
[ELF] - Fix for: error "invalid section index: xxx" when linking FreeBSD kernel.
We found that GNU assembler 2.17.50 [FreeBSD] 2007-07-03 could generate broken objects. STT_SECTION symbols can be associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections. This is PR28868, patch fixes handling of such files. Differential revision: https://reviews.llvm.org/D23201 llvm-svn: 278550
1 parent 4c09318 commit 683a35d

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
 

‎lld/ELF/InputFiles.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,15 @@ elf::ObjectFile<ELFT>::getSection(const Elf_Sym &Sym) const {
343343
uint32_t Index = this->getSectionIndex(Sym);
344344
if (Index == 0)
345345
return nullptr;
346-
if (Index >= Sections.size() || !Sections[Index])
346+
if (Index >= Sections.size())
347347
fatal(getFilename(this) + ": invalid section index: " + Twine(Index));
348348
InputSectionBase<ELFT> *S = Sections[Index];
349-
if (S == &InputSectionBase<ELFT>::Discarded)
349+
// We found that GNU assembler 2.17.50 [FreeBSD] 2007-07-03
350+
// could generate broken objects. STT_SECTION symbols can be
351+
// associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections.
352+
// In this case it is fine for section to be null here as we
353+
// do not allocate sections of these types.
354+
if (!S || S == &InputSectionBase<ELFT>::Discarded)
350355
return S;
351356
return S->Repl;
352357
}

‎lld/test/ELF/section-symbols.test

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: ld.lld -shared %t -o %tout
3+
4+
# Verify that lld can handle STT_SECTION symbols associated
5+
# with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections.
6+
7+
!ELF
8+
FileHeader:
9+
Class: ELFCLASS64
10+
Data: ELFDATA2LSB
11+
OSABI: ELFOSABI_FREEBSD
12+
Type: ET_REL
13+
Machine: EM_X86_64
14+
Sections:
15+
- Name: .text
16+
Type: SHT_PROGBITS
17+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
18+
AddressAlign: 0x0000000000000010
19+
Content: "00000000"
20+
- Name: .rela.text
21+
Type: SHT_RELA
22+
Link: .symtab
23+
AddressAlign: 0x0000000000000008
24+
Info: .text
25+
Relocations:
26+
Symbols:
27+
Local:
28+
- Type: STT_SECTION
29+
Section: .rela.text
30+
- Type: STT_SECTION
31+
Section: .shstrtab
32+
- Type: STT_SECTION
33+
Section: .symtab
34+
- Type: STT_SECTION
35+
Section: .strtab

0 commit comments

Comments
 (0)
Please sign in to comment.