[PATCH] D51743: [ELF] Check if LinkSec is nullptr when initializing SHF_LINK_ORDER sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 6 16:18:13 PDT 2018


MaskRay updated this revision to Diff 164315.
MaskRay marked an inline comment as done.
MaskRay added a comment.

Beautify


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D51743

Files:
  ELF/InputFiles.cpp
  test/ELF/invalid/linkorder-invalid-sec2.test


Index: test/ELF/invalid/linkorder-invalid-sec2.test
===================================================================
--- /dev/null
+++ test/ELF/invalid/linkorder-invalid-sec2.test
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+# CHECK: invalid sh_link index: 0
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:          .linkorder
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR, SHF_LINK_ORDER ]
+    Link:          0
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -478,11 +478,13 @@
     // .ARM.exidx sections have a reverse dependency on the InputSection they
     // have a SHF_LINK_ORDER dependency, this is identified by the sh_link.
     if (Sec.sh_flags & SHF_LINK_ORDER) {
-      if (Sec.sh_link >= this->Sections.size())
+      InputSectionBase *LinkSec = nullptr;
+      if (Sec.sh_link < this->Sections.size())
+        LinkSec = this->Sections[Sec.sh_link];
+      if (!LinkSec)
         fatal(toString(this) +
               ": invalid sh_link index: " + Twine(Sec.sh_link));
 
-      InputSectionBase *LinkSec = this->Sections[Sec.sh_link];
       InputSection *IS = cast<InputSection>(this->Sections[I]);
       LinkSec->DependentSections.push_back(IS);
       if (!isa<InputSection>(LinkSec))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51743.164315.patch
Type: text/x-patch
Size: 1532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180906/2e0b13ef/attachment.bin>


More information about the llvm-commits mailing list