Skip to content

Commit

Permalink
[MC][TargetMachine] Delete MCTargetOptions::MCPIECopyRelocations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay committed Jan 1, 2020
1 parent 47e3d3e commit d2bb8c1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 166 deletions.
1 change: 0 additions & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/MC/MCTargetOptions.h
Expand Up @@ -46,7 +46,6 @@ class MCTargetOptions {
bool MCSaveTempLabels : 1;
bool MCUseDwarfDirectory : 1;
bool MCIncrementalLinkerCompatible : 1;
bool MCPIECopyRelocations : 1;
bool ShowMCEncoding : 1;
bool ShowMCInst : 1;
bool AsmVerbose : 1;
Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/MC/MCTargetOptionsCommandFlags.inc
Expand Up @@ -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));

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/MC/MCTargetOptions.cpp
Expand Up @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/Target/TargetMachine.cpp
Expand Up @@ -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;
}

Expand Down
151 changes: 0 additions & 151 deletions llvm/test/CodeGen/X86/global-access-pie-copyrelocs.ll

This file was deleted.

0 comments on commit d2bb8c1

Please sign in to comment.