[PATCH] D23201: [ELF] - Fix for: error "invalid section index: xxx" when linking FreeBSD kernel.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 03:01:24 PDT 2016


grimar updated this revision to Diff 67308.
grimar added a comment.

- Created testcase.


https://reviews.llvm.org/D23201

Files:
  ELF/InputFiles.cpp
  test/ELF/section-symbols.test

Index: test/ELF/section-symbols.test
===================================================================
--- test/ELF/section-symbols.test
+++ test/ELF/section-symbols.test
@@ -0,0 +1,29 @@
+# RUN: yaml2obj %s -o %t
+# RUN: ld.lld -shared %t -o %tout
+
+# Verify that lld can handle STT_SECTION symbols associated
+# with SHT_RELA sections.
+
+!ELF
+FileHeader:      
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  OSABI:           ELFOSABI_FREEBSD
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000010
+    Content:         "00000000"
+  - Name:            .rela.text
+    Type:            SHT_RELA
+    Link:            .symtab
+    AddressAlign:    0x0000000000000008
+    Info:            .text
+    Relocations:
+Symbols:
+  Local:
+    - Type:            STT_SECTION
+      Section:         .rela.text
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -339,10 +339,10 @@
   uint32_t Index = this->getSectionIndex(Sym);
   if (Index == 0)
     return nullptr;
-  if (Index >= Sections.size() || !Sections[Index])
+  if (Index >= Sections.size())
     fatal(getFilename(this) + ": invalid section index: " + Twine(Index));
   InputSectionBase<ELFT> *S = Sections[Index];
-  if (S == &InputSectionBase<ELFT>::Discarded)
+  if (!S || S == &InputSectionBase<ELFT>::Discarded)
     return S;
   return S->Repl;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23201.67308.patch
Type: text/x-patch
Size: 1636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160809/1d1a22fe/attachment.bin>


More information about the llvm-commits mailing list