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:
parent
6149361b1e
commit
56c940ba49
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=319885
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user