[lld] r295031 - Do not store a computable attributes to Config.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 21:45:47 PST 2017


Author: ruiu
Date: Mon Feb 13 23:45:47 2017
New Revision: 295031

URL: http://llvm.org/viewvc/llvm-project?rev=295031&view=rev
Log:
Do not store a computable attributes to Config.

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/LTO.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Thunks.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Mon Feb 13 23:45:47 2017
@@ -119,7 +119,6 @@ struct Configuration {
   bool OFormatBinary;
   bool OMagic;
   bool OptRemarksWithHotness;
-  bool Pic;
   bool Pie;
   bool PrintGcSections;
   bool Rela;
@@ -160,7 +159,14 @@ struct Configuration {
   unsigned LTOO;
   unsigned Optimize;
   unsigned ThinLTOJobs;
-  bool copyRelocs() { return Relocatable || EmitRelocs; };
+
+  // Returns true if we need to pass through relocations in input
+  // files to the output file. Usually false because we consume
+  // relocations.
+  bool copyRelocs() const { return Relocatable || EmitRelocs; };
+
+  // Returns true if we are creating position-independent code.
+  bool pic() const { return Pie || Shared; }
 };
 
 // The only instance of Configuration struct.

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Feb 13 23:45:47 2017
@@ -600,9 +600,6 @@ void LinkerDriver::readConfigs(opt::Inpu
   if (!Config->Relocatable)
     Config->Strip = getStripOption(Args);
 
-  // Config->Pic is true if we are generating position-independent code.
-  Config->Pic = Config->Pie || Config->Shared;
-
   if (auto *Arg = Args.getLastArg(OPT_hash_style)) {
     StringRef S = Arg->getValue();
     if (S == "gnu") {
@@ -772,7 +769,7 @@ static uint64_t getImageBase(opt::InputA
   // has to be called after the variable is initialized.
   auto *Arg = Args.getLastArg(OPT_image_base);
   if (!Arg)
-    return Config->Pic ? 0 : Target->DefaultImageBase;
+    return Config->pic() ? 0 : Target->DefaultImageBase;
 
   StringRef S = Arg->getValue();
   uint64_t V;

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Mon Feb 13 23:45:47 2017
@@ -72,7 +72,7 @@ static std::unique_ptr<lto::LTO> createL
   Conf.Options = InitTargetOptionsFromCodeGenFlags();
   Conf.Options.RelaxELFRelocations = true;
 
-  Conf.RelocModel = Config->Pic ? Reloc::PIC_ : Reloc::Static;
+  Conf.RelocModel = Config->pic() ? Reloc::PIC_ : Reloc::Static;
   Conf.DisableVerify = Config->DisableVerify;
   Conf.DiagHandler = diagnosticHandler;
   Conf.OptLevel = Config->LTOO;

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Mon Feb 13 23:45:47 2017
@@ -100,7 +100,7 @@ static unsigned handleNoRelaxTlsRelocati
     // if we know that we are linking an executable. For ARM we resolve the
     // relocation when writing the Got. MIPS has a custom Got implementation
     // that writes the Module index in directly.
-    if (!Body.isPreemptible() && !Config->Pic && Config->EMachine == EM_ARM)
+    if (!Body.isPreemptible() && !Config->pic() && Config->EMachine == EM_ARM)
       Got->Relocations.push_back(
           {R_ABS, Target->TlsModuleIndexRel, Off, 0, &Body});
     else {
@@ -110,7 +110,7 @@ static unsigned handleNoRelaxTlsRelocati
     }
   };
   if (Expr == R_MIPS_TLSLD || Expr == R_TLSLD_PC) {
-    if (Got->addTlsIndex() && (Config->Pic || Config->EMachine == EM_ARM))
+    if (Got->addTlsIndex() && (Config->pic() || Config->EMachine == EM_ARM))
       addModuleReloc(Body, Got, Got->getTlsIndexOff(), true);
     C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
     return 1;
@@ -327,12 +327,12 @@ static bool isStaticLinkTimeConstant(Rel
   // These never do, except if the entire file is position dependent or if
   // only the low bits are used.
   if (E == R_GOT || E == R_PLT || E == R_TLSDESC)
-    return Target->usesOnlyLowPageBits(Type) || !Config->Pic;
+    return Target->usesOnlyLowPageBits(Type) || !Config->pic();
 
   if (isPreemptible(Body, Type))
     return false;
 
-  if (!Config->Pic)
+  if (!Config->pic())
     return true;
 
   bool AbsVal = isAbsoluteValue<ELFT>(Body);
@@ -479,7 +479,7 @@ static RelExpr adjustExpr(const elf::Obj
   // This relocation would require the dynamic linker to write a value to read
   // only memory. We can hack around it if we are producing an executable and
   // the refered symbol can be preemepted to refer to the executable.
-  if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) {
+  if (Config->Shared || (Config->pic() && !isRelExpr(Expr))) {
     error(S.getLocation(RelOff) + ": can't create dynamic relocation " +
           toString(Type) + " against " +
           (Body.getName().empty() ? "local symbol in readonly segment"
@@ -553,7 +553,7 @@ static typename ELFT::uint computeAddend
     if (Expr == R_MIPS_GOTREL && Body.isLocal())
       Addend += File.MipsGp0;
   }
-  if (Config->Pic && Config->EMachine == EM_PPC64 && Type == R_PPC64_TOC)
+  if (Config->pic() && Config->EMachine == EM_PPC64 && Type == R_PPC64_TOC)
     Addend += getPPC64TocBase();
   return Addend;
 }
@@ -785,13 +785,14 @@ static void scanRelocs(InputSectionBase<
       if (Body.isTls()) {
         DynType = Target->TlsGotRel;
         GotRE = R_TLS;
-      } else if (!Preemptible && Config->Pic && !isAbsolute<ELFT>(Body))
+      } else if (!Preemptible && Config->pic() && !isAbsolute<ELFT>(Body))
         DynType = Target->RelativeRel;
       else
         DynType = Target->GotRel;
 
       // FIXME: this logic is almost duplicated above.
-      bool Constant = !Preemptible && !(Config->Pic && !isAbsolute<ELFT>(Body));
+      bool Constant =
+          !Preemptible && !(Config->pic() && !isAbsolute<ELFT>(Body));
       if (!Constant)
         AddDyn({DynType, In<ELFT>::Got, Off, !Preemptible, &Body, 0});
       if (Constant || (!RelTy::IsRela && !Preemptible))

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Feb 13 23:45:47 2017
@@ -694,7 +694,7 @@ template <class ELFT> void MipsGotSectio
   // TLS symbol's values otherwise. To calculate the adjustments use offsets
   // for thread-local storage.
   // https://www.linux-mips.org/wiki/NPTL
-  if (TlsIndexOff != -1U && !Config->Pic)
+  if (TlsIndexOff != -1U && !Config->pic())
     writeUint<ELFT>(Buf + TlsIndexOff, 1);
   for (const SymbolBody *B : TlsEntries) {
     if (!B || B->isPreemptible())

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Mon Feb 13 23:45:47 2017
@@ -446,7 +446,7 @@ bool X86TargetInfo::isTlsInitialExecRel(
 void X86TargetInfo::writePltHeader(uint8_t *Buf) const {
   // Executable files and shared object files have
   // separate procedure linkage tables.
-  if (Config->Pic) {
+  if (Config->pic()) {
     const uint8_t V[] = {
         0xff, 0xb3, 0x04, 0x00, 0x00, 0x00, // pushl 4(%ebx)
         0xff, 0xa3, 0x08, 0x00, 0x00, 0x00, // jmp   *8(%ebx)
@@ -478,7 +478,7 @@ void X86TargetInfo::writePlt(uint8_t *Bu
   memcpy(Buf, Inst, sizeof(Inst));
 
   // jmp *foo at GOT(%ebx) or jmp *foo_in_GOT
-  Buf[1] = Config->Pic ? 0xa3 : 0x25;
+  Buf[1] = Config->pic() ? 0xa3 : 0x25;
   uint32_t Got = In<ELF32LE>::GotPlt->getVA();
   write32le(Buf + 2, Config->Shared ? GotEntryAddr - Got : GotEntryAddr);
   write32le(Buf + 7, RelOff);
@@ -946,7 +946,7 @@ RelExpr X86_64TargetInfo<ELFT>::adjustRe
   // We also don't relax test/binop instructions without REX byte,
   // they are 32bit operations and not common to have.
   assert(Type == R_X86_64_REX_GOTPCRELX);
-  return Config->Pic ? RelExpr : R_RELAX_GOT_PC_NOPIC;
+  return Config->pic() ? RelExpr : R_RELAX_GOT_PC_NOPIC;
 }
 
 // A subset of relaxations can only be applied for no-PIC. This method
@@ -1033,7 +1033,7 @@ void X86_64TargetInfo<ELFT>::relaxGot(ui
   if (Op != 0xff) {
     // We are relaxing a rip relative to an absolute, so compensate
     // for the old -4 addend.
-    assert(!Config->Pic);
+    assert(!Config->pic());
     relaxGotNoPic(Loc, Val + 4, Op, ModRm);
     return;
   }

Modified: lld/trunk/ELF/Thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.cpp (original)
+++ lld/trunk/ELF/Thunks.cpp Mon Feb 13 23:45:47 2017
@@ -244,12 +244,12 @@ static Thunk<ELFT> *addThunkArm(uint32_t
   case R_ARM_PC24:
   case R_ARM_PLT32:
   case R_ARM_JUMP24:
-    if (Config->Pic)
+    if (Config->pic())
       return make<ARMToThumbV7PILongThunk<ELFT>>(S);
     return make<ARMToThumbV7ABSLongThunk<ELFT>>(S);
   case R_ARM_THM_JUMP19:
   case R_ARM_THM_JUMP24:
-    if (Config->Pic)
+    if (Config->pic())
       return make<ThumbToARMV7PILongThunk<ELFT>>(S);
     return make<ThumbToARMV7ABSLongThunk<ELFT>>(S);
   }

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=295031&r1=295030&r2=295031&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Feb 13 23:45:47 2017
@@ -353,7 +353,8 @@ template <class ELFT> void Writer<ELFT>:
   }
 
   // Add MIPS-specific sections.
-  bool HasDynSymTab = !Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic;
+  bool HasDynSymTab =
+      !Symtab<ELFT>::X->getSharedFiles().empty() || Config->pic();
   if (Config->EMachine == EM_MIPS) {
     if (!Config->Shared && HasDynSymTab) {
       In<ELFT>::MipsRldMap = make<MipsRldMapSection<ELFT>>();
@@ -1613,7 +1614,7 @@ template <class ELFT> static uint8_t get
 }
 
 static uint16_t getELFType() {
-  if (Config->Pic)
+  if (Config->pic())
     return ET_DYN;
   if (Config->Relocatable)
     return ET_REL;




More information about the llvm-commits mailing list