From 56c940ba496967e14a5ca87e67fac3128b2376d7 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 13 Jun 2017 00:31:16 +0000 Subject: [PATCH] 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 --- contrib/llvm/tools/lld/ELF/ICF.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/llvm/tools/lld/ELF/ICF.cpp b/contrib/llvm/tools/lld/ELF/ICF.cpp index 32cd0f8a185c..838b3d8b4930 100644 --- a/contrib/llvm/tools/lld/ELF/ICF.cpp +++ b/contrib/llvm/tools/lld/ELF/ICF.cpp @@ -245,7 +245,6 @@ bool ICF::variableEq(const InputSection *A, ArrayRef RelsA, if (&SA == &SB) return true; - // Or, the two sections must be in the same equivalence class. auto *DA = dyn_cast>(&SA); auto *DB = dyn_cast>(&SB); if (!DA || !DB) @@ -253,6 +252,11 @@ bool ICF::variableEq(const InputSection *A, ArrayRef 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>(DA->Section); auto *Y = dyn_cast>(DB->Section); if (!X || !Y)