This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Check if LinkSec is nullptr when initializing SHF_LINK_ORDER sections
ClosedPublic

Authored by MaskRay on Sep 6 2018, 11:19 AM.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

MaskRay created this revision.Sep 6 2018, 11:19 AM
MaskRay edited the summary of this revision. (Show Details)Sep 6 2018, 11:21 AM
ruiu added inline comments.Sep 6 2018, 3:57 PM
ELF/InputFiles.cpp
481–484

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];

MaskRay updated this revision to Diff 164315.Sep 6 2018, 4:18 PM
MaskRay marked an inline comment as done.

Beautify

MaskRay added inline comments.Sep 6 2018, 4:18 PM
ELF/InputFiles.cpp
481–484

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?

ruiu accepted this revision.Sep 6 2018, 5:03 PM

LGTM

Looks better!

This revision is now accepted and ready to land.Sep 6 2018, 5:03 PM
This revision was automatically updated to reflect the committed changes.