From 554f273b9d629fccfeada1442cd2274d88181df1 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 2 Feb 2016 07:07:34 +0000 Subject: [PATCH] ELF: Move PLT relocation handler to one place. NFC. llvm-svn: 259470 --- lld/ELF/Writer.cpp | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index a09a570384f1..1371a96236d7 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -324,25 +324,36 @@ void Writer::scanRelocs( continue; } + // If a relocation needs PLT, we create a PLT and a GOT slot + // for the symbol. + if (Body && Target->needsPlt(Type, *Body)) { + if (Body->isInPlt()) + continue; + Out::Plt->addEntry(Body); + + if (Target->UseLazyBinding) { + Out::GotPlt->addEntry(Body); + Out::RelaPlt->addReloc({&C, &RI}); + } else { + if (Body->isInGot()) + continue; + Out::Got->addEntry(Body); + Out::RelaDyn->addReloc({&C, &RI}); + } + + if (canBePreempted(Body, /*NeedsGot=*/true)) + Body->setUsedInDynamicReloc(); + continue; + } + bool NeedsGot = false; - bool NeedsPlt = false; if (Body) { - NeedsPlt = Target->needsPlt(Type, *Body); - if (NeedsPlt) { - if (Body->isInPlt()) - continue; - Out::Plt->addEntry(Body); - } NeedsGot = Target->needsGot(Type, *Body); if (NeedsGot) { - if (NeedsPlt && Target->UseLazyBinding) { - Out::GotPlt->addEntry(Body); - } else { - if (Body->isInGot()) - continue; - Out::Got->addEntry(Body); - } + if (Body->isInGot()) + continue; + Out::Got->addEntry(Body); } } @@ -383,10 +394,7 @@ void Writer::scanRelocs( if (CBP) Body->setUsedInDynamicReloc(); - if (NeedsPlt && Target->UseLazyBinding) - Out::RelaPlt->addReloc({&C, &RI}); - else - Out::RelaDyn->addReloc({&C, &RI}); + Out::RelaDyn->addReloc({&C, &RI}); } }