Commit d2bb8c16 authored by Fangrui Song's avatar Fangrui Song
Browse files

[MC][TargetMachine] Delete MCTargetOptions::MCPIECopyRelocations

clang/lib/CodeGen/CodeGenModule performs the -mpie-copy-relocations
check and sets dso_local on applicable global variables. We don't need
to duplicate the work in TargetMachine shouldAssumeDSOLocal.

Verified that -mpie-copy-relocations can still emit PC relative
relocations for external variable accesses.

clang -target x86_64 -fpie -mpie-copy-relocations -c => R_X86_64_PC32
clang -target aarch64 -fpie -mpie-copy-relocations -c => R_AARCH64_ADR_PREL_PG_HI21+R_AARCH64_LDST64_ABS_LO12_NC
parent 47e3d3ec
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -485,7 +485,6 @@ static void initTargetOptions(llvm::TargetOptions &Options,
  Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
  Options.MCOptions.MCIncrementalLinkerCompatible =
      CodeGenOpts.IncrementalLinkerCompatible;
  Options.MCOptions.MCPIECopyRelocations = CodeGenOpts.PIECopyRelocations;
  Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
  Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
  Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
+0 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ public:
  bool MCSaveTempLabels : 1;
  bool MCUseDwarfDirectory : 1;
  bool MCIncrementalLinkerCompatible : 1;
  bool MCPIECopyRelocations : 1;
  bool ShowMCEncoding : 1;
  bool ShowMCInst : 1;
  bool AsmVerbose : 1;
+0 −3
Original line number Diff line number Diff line
@@ -28,8 +28,6 @@ static cl::opt<bool> IncrementalLinkerCompatible(
        "When used with filetype=obj, "
        "emit an object file which can be used with an incremental linker"));

static cl::opt<bool> PIECopyRelocations("pie-copy-relocations", cl::desc("PIE Copy Relocations"));

static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
                          cl::init(0));

@@ -55,7 +53,6 @@ static MCTargetOptions InitMCTargetOptionsFromFlags() {
  MCTargetOptions Options;
  Options.MCRelaxAll = RelaxAll;
  Options.MCIncrementalLinkerCompatible = IncrementalLinkerCompatible;
  Options.MCPIECopyRelocations = PIECopyRelocations;
  Options.DwarfVersion = DwarfVersion;
  Options.ShowMCInst = ShowMCInst;
  Options.ABIName = ABIName;
+2 −2
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@ MCTargetOptions::MCTargetOptions()
    : MCRelaxAll(false), MCNoExecStack(false), MCFatalWarnings(false),
      MCNoWarn(false), MCNoDeprecatedWarn(false), MCSaveTempLabels(false),
      MCUseDwarfDirectory(false), MCIncrementalLinkerCompatible(false),
      MCPIECopyRelocations(false), ShowMCEncoding(false), ShowMCInst(false),
      AsmVerbose(false), PreserveAsmComments(true) {}
      ShowMCEncoding(false), ShowMCInst(false), AsmVerbose(false),
      PreserveAsmComments(true) {}

StringRef MCTargetOptions::getABIName() const {
  return ABIName;
+7 −8
Original line number Diff line number Diff line
@@ -184,15 +184,14 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
    const Function *F = dyn_cast_or_null<Function>(GV);
    if (F && F->hasFnAttribute(Attribute::NonLazyBind))
      return false;

    bool IsTLS = GV && GV->isThreadLocal();
    bool IsAccessViaCopyRelocs =
        GV && Options.MCOptions.MCPIECopyRelocations && isa<GlobalVariable>(GV);
    Triple::ArchType Arch = TT.getArch();
    bool IsPPC =
        Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le;
    // Check if we can use copy relocations. PowerPC has no copy relocations.
    if (!IsTLS && !IsPPC && (RM == Reloc::Static || IsAccessViaCopyRelocs))

    // PowerPC prefers avoiding copy relocations.
    if (Arch == Triple::ppc || TT.isPPC64())
      return false;

    // Check if we can use copy relocations.
    if (!(GV && GV->isThreadLocal()) && RM == Reloc::Static)
      return true;
  }

Loading