From 30951480156613eacfac4f426941f647aaa75d97 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 25 Feb 2016 19:34:37 +0000 Subject: [PATCH] ELF: Split Writer::addPredefiendSections. NFC. llvm-svn: 261924 --- lld/ELF/Writer.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 620be30..6072c60 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -60,6 +60,7 @@ private: void addReservedSymbols(); bool createSections(); void addPredefinedSections(); + bool needsGot(); template void scanRelocs(InputSectionBase &C, @@ -1073,6 +1074,20 @@ template bool Writer::createSections() { return true; } +template bool Writer::needsGot() { + if (!Out::Got->empty()) + return true; + + // We add the .got section to the result for dynamic MIPS target because + // its address and properties are mentioned in the .dynamic section. + if (Config->EMachine == EM_MIPS && isOutputDynamic()) + return true; + + // If we have a relocation that is relative to GOT (such as GOTOFFREL), + // we need to emit a GOT even if it's empty. + return HasGotOffRel; +} + // This function add Out::* sections to OutputSections. template void Writer::addPredefinedSections() { auto Add = [&](OutputSectionBase *C) { @@ -1115,17 +1130,7 @@ template void Writer::addPredefinedSections() { Out::RelaPlt->Static = !isOutputDynamic(); } - bool needsGot = !Out::Got->empty(); - // We add the .got section to the result for dynamic MIPS target because - // its address and properties are mentioned in the .dynamic section. - if (Config->EMachine == EM_MIPS) - needsGot |= isOutputDynamic(); - // If we have a relocation that is relative to GOT (such as GOTOFFREL), - // we need to emit a GOT even if it's empty. - if (HasGotOffRel) - needsGot = true; - - if (needsGot) + if (needsGot()) Add(Out::Got); if (Out::GotPlt && !Out::GotPlt->empty()) Add(Out::GotPlt); -- 2.7.4