[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:18 PDT 2018


MaskRay added inline comments.


================
Comment at: ELF/InputFiles.cpp:481
     if (Sec.sh_flags & SHF_LINK_ORDER) {
-      if (Sec.sh_link >= this->Sections.size())
+      InputSectionBase *LinkSec = Sec.sh_link < this->Sections.size()
+                                      ? this->Sections[Sec.sh_link]
----------------
ruiu wrote:
> It feels like setting to a nullptr is a little bit tricky. I'd probably keep the original code for this line, and add another null check after `InputSectionBase *LinkSec = this->Sections[Sec.sh_link];`
Duplicate `fatal` calls seem verbose

      if (Sec.sh_link >= this->Sections.size())
        fatal(toString(this) +
              ": invalid sh_link index: " + Twine(Sec.sh_link));
      InputSectionBase *LinkSec = this->Sections[Sec.sh_link];
      if (!LinkSec)
        fatal(toString(this) +
              ": invalid sh_link index: " + Twine(Sec.sh_link));

How about the current change?


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D51743





More information about the llvm-commits mailing list