From 956749515496f0ec00b527414c7d4c5a8b25c3d1 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Fri, 18 Sep 2015 21:48:38 +0000 Subject: [PATCH] [elf2] Convert if/else cascade into a covered switch. NFC. llvm-svn: 248049 --- lld/ELF/Writer.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index b784ec6c3472..b2d761115ff1 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -730,18 +730,26 @@ void OutputSection::relocate( uint32_t Type = RI.getType(IsMips64EL); uintX_t SymVA; - if (auto *DR = dyn_cast>(Body)) { - SymVA = getSymVA(DR); - } else if (auto *DA = dyn_cast>(Body)) { - SymVA = DA->Sym.st_value; - } else if (auto *S = dyn_cast>(Body)) { + + switch (Body->kind()) { + case SymbolBody::DefinedRegularKind: + SymVA = getSymVA(cast>(Body)); + break; + case SymbolBody::DefinedAbsoluteKind: + SymVA = cast>(Body)->Sym.st_value; + break; + case SymbolBody::DefinedCommonKind: + continue; + case SymbolBody::SharedKind: if (!relocNeedsGOT(Type)) continue; - SymVA = GotSec.getEntryAddr(*S); + SymVA = GotSec.getEntryAddr(*Body); Type = R_X86_64_PC32; - } else { - // Skip unsupported for now. + break; + case SymbolBody::UndefinedKind: continue; + case SymbolBody::LazyKind: + llvm_unreachable("Lazy symbol reached writer"); } relocateOne(Buf, RI, Type, BaseAddr, SymVA);