From 31d2ada6d544160655292715cb7614230eccc8e5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 1 Apr 2016 14:14:48 +0000 Subject: [PATCH] Refactor duplicated code. We had almost identical code to handle creating a plt entry in two places. llvm-svn: 265142 --- lld/ELF/Writer.cpp | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index d2b6335fe61f..da5c3f8b359d 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -384,27 +384,6 @@ void Writer::scanRelocs(InputSectionBase &C, } } - // An STT_GNU_IFUNC symbol always uses a PLT entry, and all references - // to the symbol go through the PLT. This is true even for a local - // symbol, although local symbols normally do not require PLT entries. - if (Body.IsGnuIFunc) { - if (Body.isInPlt()) - continue; - Out::Plt->addEntry(Body); - if (Target->UseLazyBinding) { - Out::GotPlt->addEntry(Body); - Out::RelaPlt->addReloc( - {Preemptible ? Target->PltRel : Target->IRelativeRel, - DynamicReloc::Off_GotPlt, !Preemptible, &Body}); - } else { - Out::Got->addEntry(Body); - Out::RelaDyn->addReloc( - {Preemptible ? Target->PltRel : Target->IRelativeRel, - DynamicReloc::Off_Got, !Preemptible, &Body}); - } - continue; - } - // If a relocation needs PLT, we create a PLT and a GOT slot // for the symbol. TargetInfo::PltNeed NeedPlt = Target->needsPlt(Type, Body); @@ -415,16 +394,22 @@ void Writer::scanRelocs(InputSectionBase &C, continue; Out::Plt->addEntry(Body); + uint32_t Rel; + if (Body.IsGnuIFunc) + Rel = Preemptible ? Target->PltRel : Target->IRelativeRel; + else + Rel = Target->UseLazyBinding ? Target->PltRel : Target->GotRel; + if (Target->UseLazyBinding) { Out::GotPlt->addEntry(Body); Out::RelaPlt->addReloc( - {Target->PltRel, DynamicReloc::Off_GotPlt, &Body}); + {Rel, DynamicReloc::Off_GotPlt, !Preemptible, &Body}); } else { if (Body.isInGot()) continue; Out::Got->addEntry(Body); Out::RelaDyn->addReloc( - {Target->GotRel, DynamicReloc::Off_Got, &Body}); + {Rel, DynamicReloc::Off_Got, !Preemptible, &Body}); } continue; }