lld: ELF: Fix ICF crash on absolute symbol relocations.

If two sections contained relocations to absolute symbols with the same
value we would crash when trying to access their sections. Add a check that
both symbols point to sections before accessing their sections, and treat
absolute symbols as equal if their values are equal.

Obtained from:	LLD commit r292578
MFC after:	3 days
This commit is contained in:
emaste 2017-06-13 00:31:16 +00:00
parent 36fc47a035
commit 3fdb20a9bf

View File

@ -245,7 +245,6 @@ bool ICF<ELFT>::variableEq(const InputSection<ELFT> *A, ArrayRef<RelTy> RelsA,
if (&SA == &SB)
return true;
// Or, the two sections must be in the same equivalence class.
auto *DA = dyn_cast<DefinedRegular<ELFT>>(&SA);
auto *DB = dyn_cast<DefinedRegular<ELFT>>(&SB);
if (!DA || !DB)
@ -253,6 +252,11 @@ bool ICF<ELFT>::variableEq(const InputSection<ELFT> *A, ArrayRef<RelTy> RelsA,
if (DA->Value != DB->Value)
return false;
// Either both symbols must be absolute...
if (!DA->Section || !DB->Section)
return !DA->Section && !DB->Section;
// Or the two sections must be in the same equivalence class.
auto *X = dyn_cast<InputSection<ELFT>>(DA->Section);
auto *Y = dyn_cast<InputSection<ELFT>>(DB->Section);
if (!X || !Y)