Skip to content

Commit a331937

Browse files
committed
[MC] Move CompressDebugSections/RelaxELFRelocations from TargetOptions/MCAsmInfo to MCTargetOptions
The convention is for such MC-specific options to reside in MCTargetOptions. However, CompressDebugSections/RelaxELFRelocations do not follow the convention: `CompressDebugSections` is defined in both TargetOptions and MCAsmInfo and there is forwarding complexity. Move the option to MCTargetOptions and hereby simplify the code. Rename the misleading RelaxELFRelocations to X86RelaxRelocations. llvm-mc -relax-relocations and llc -x86-relax-relocations can now be unified.
1 parent 886ecb3 commit a331937

25 files changed

+61
-83
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
356356
llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion);
357357
Options.UseInitArray = CodeGenOpts.UseInitArray;
358358
Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
359-
Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections();
360-
Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
361359

362360
// Set EABI version.
363361
Options.EABIVersion = TargetOpts.EABIVersion;
@@ -460,6 +458,9 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
460458
Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
461459
Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64;
462460
Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
461+
Options.MCOptions.X86RelaxRelocations = CodeGenOpts.RelaxELFRelocations;
462+
Options.MCOptions.CompressDebugSections =
463+
CodeGenOpts.getCompressDebugSections();
463464
Options.MCOptions.ABIName = TargetOpts.ABI;
464465
for (const auto &Entry : HSOpts.UserEntries)
465466
if (!Entry.IsFramework &&

clang/tools/driver/cc1as_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
428428
MCTargetOptions MCOptions;
429429
MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;
430430
MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical;
431+
MCOptions.X86RelaxRelocations = Opts.RelaxELFRelocations;
432+
MCOptions.CompressDebugSections = Opts.CompressDebugSections;
431433
MCOptions.AsSecureLogFile = Opts.AsSecureLogFile;
432434

433435
std::unique_ptr<MCAsmInfo> MAI(
@@ -436,9 +438,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
436438

437439
// Ensure MCAsmInfo initialization occurs before any use, otherwise sections
438440
// may be created with a combination of default and explicit settings.
439-
MAI->setCompressDebugSections(Opts.CompressDebugSections);
440441

441-
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
442442

443443
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
444444
if (Opts.OutputPath.empty())

lld/test/ELF/weak-undef-got-pie.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/dummy-shared.s -o %t1.o
33
# RUN: ld.lld %t1.o -shared -o %t1.so
4-
# RUN: llvm-mc -filetype=obj -relax-relocations=false -triple=x86_64 %s -o %t.o
4+
# RUN: llvm-mc -filetype=obj -x86-relax-relocations=false -triple=x86_64 %s -o %t.o
55

66
# RUN: ld.lld -pie %t.o %t1.so -o %t
77
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s

llvm/include/llvm/CodeGen/CommandFlags.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ bool getUseCtors();
9898

9999
bool getDisableIntegratedAS();
100100

101-
bool getRelaxELFRelocations();
102-
103101
bool getDataSections();
104102
std::optional<bool> getExplicitDataSections();
105103

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,10 @@ class MCAsmInfo {
524524
/// Preserve Comments in assembly
525525
bool PreserveAsmComments;
526526

527-
/// Compress DWARF debug sections. Defaults to no compression.
528-
DebugCompressionType CompressDebugSections = DebugCompressionType::None;
529-
530527
/// True if the integrated assembler should interpret 'a >> b' constant
531528
/// expressions as logical rather than arithmetic.
532529
bool UseLogicalShr = true;
533530

534-
// If true, emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL, on
535-
// X86_64 ELF.
536-
bool RelaxELFRelocations = true;
537-
538531
// If true, then the lexer and expression parser will support %neg(),
539532
// %hi(), and similar unary operators.
540533
bool HasMipsExpressions = false;
@@ -875,18 +868,9 @@ class MCAsmInfo {
875868
PreserveAsmComments = Value;
876869
}
877870

878-
DebugCompressionType compressDebugSections() const {
879-
return CompressDebugSections;
880-
}
881-
882-
void setCompressDebugSections(DebugCompressionType CompressDebugSections) {
883-
this->CompressDebugSections = CompressDebugSections;
884-
}
885871

886872
bool shouldUseLogicalShr() const { return UseLogicalShr; }
887873

888-
bool canRelaxRelocations() const { return RelaxELFRelocations; }
889-
void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; }
890874
bool hasMipsExpressions() const { return HasMipsExpressions; }
891875
bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
892876
bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }

llvm/include/llvm/MC/MCContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ class MCContext {
451451

452452
const MCSubtargetInfo *getSubtargetInfo() const { return MSTI; }
453453

454+
const MCTargetOptions *getTargetOptions() const { return TargetOptions; }
455+
454456
CodeViewContext &getCVContext();
455457

456458
void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }

llvm/include/llvm/MC/MCTargetOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class MCTargetOptions {
6161

6262
bool Dwarf64 : 1;
6363

64+
// If true, prefer R_X86_64_[REX_]GOTPCRELX to R_X86_64_GOTPCREL on x86-64
65+
// ELF.
66+
bool X86RelaxRelocations = true;
67+
6468
EmitDwarfUnwindType EmitDwarfUnwind;
6569

6670
int DwarfVersion = 0;
@@ -76,6 +80,9 @@ class MCTargetOptions {
7680
};
7781
DwarfDirectory MCUseDwarfDirectory;
7882

83+
// Whether to compress DWARF debug sections.
84+
DebugCompressionType CompressDebugSections = DebugCompressionType::None;
85+
7986
std::string ABIName;
8087
std::string AssemblyLanguage;
8188
std::string SplitDwarfFile;

llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ bool getNoDeprecatedWarn();
4949

5050
bool getNoTypeCheck();
5151

52+
bool getX86RelaxRelocations();
53+
5254
std::string getABIName();
5355

5456
std::string getAsSecureLogFile();

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,18 @@ namespace llvm {
141141
HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
142142
GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
143143
EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
144-
DisableIntegratedAS(false), RelaxELFRelocations(true),
145-
FunctionSections(false), DataSections(false),
146-
IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true),
147-
UniqueSectionNames(true), UniqueBasicBlockSectionNames(false),
148-
TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
149-
EmulatedTLS(false), EnableTLSDESC(false), EnableIPRA(false),
150-
EmitStackSizeSection(false), EnableMachineOutliner(false),
151-
EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
152-
EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
153-
SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
154-
ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
155-
XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
144+
DisableIntegratedAS(false), FunctionSections(false),
145+
DataSections(false), IgnoreXCOFFVisibility(false),
146+
XCOFFTracebackTable(true), UniqueSectionNames(true),
147+
UniqueBasicBlockSectionNames(false), TrapUnreachable(false),
148+
NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false),
149+
EnableTLSDESC(false), EnableIPRA(false), EmitStackSizeSection(false),
150+
EnableMachineOutliner(false), EnableMachineFunctionSplitter(false),
151+
SupportsDefaultOutlining(false), EmitAddrsig(false), BBAddrMap(false),
152+
EmitCallSiteInfo(false), SupportsDebugEntryValues(false),
153+
EnableDebugEntryValues(false), ValueTrackingVariableLocations(false),
154+
ForceDwarfFrameSection(false), XRayFunctionIndex(true),
155+
DebugStrictDwarf(false), Hotpatch(false),
156156
PPCGenScalarMASSEntries(false), JMCInstrument(false),
157157
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
158158
FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
@@ -260,11 +260,6 @@ namespace llvm {
260260
/// Disable the integrated assembler.
261261
unsigned DisableIntegratedAS : 1;
262262

263-
/// Compress DWARF debug sections.
264-
DebugCompressionType CompressDebugSections = DebugCompressionType::None;
265-
266-
unsigned RelaxELFRelocations : 1;
267-
268263
/// Emit functions into separate sections.
269264
unsigned FunctionSections : 1;
270265

llvm/lib/CodeGen/CommandFlags.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ CGOPT(bool, StackRealign)
8585
CGOPT(std::string, TrapFuncName)
8686
CGOPT(bool, UseCtors)
8787
CGOPT(bool, DisableIntegratedAS)
88-
CGOPT(bool, RelaxELFRelocations)
8988
CGOPT_EXP(bool, DataSections)
9089
CGOPT_EXP(bool, FunctionSections)
9190
CGOPT(bool, IgnoreXCOFFVisibility)
@@ -362,13 +361,6 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
362361
cl::init(false));
363362
CGBINDOPT(UseCtors);
364363

365-
static cl::opt<bool> RelaxELFRelocations(
366-
"x86-relax-relocations",
367-
cl::desc(
368-
"Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
369-
cl::init(true));
370-
CGBINDOPT(RelaxELFRelocations);
371-
372364
static cl::opt<bool> DataSections(
373365
"data-sections", cl::desc("Emit data into separate sections"),
374366
cl::init(false));
@@ -568,7 +560,6 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
568560
Options.StackSymbolOrdering = getStackSymbolOrdering();
569561
Options.UseInitArray = !getUseCtors();
570562
Options.DisableIntegratedAS = getDisableIntegratedAS();
571-
Options.RelaxELFRelocations = getRelaxELFRelocations();
572563
Options.DataSections =
573564
getExplicitDataSections().value_or(TheTriple.hasDefaultDataSections());
574565
Options.FunctionSections = getFunctionSections();

0 commit comments

Comments
 (0)