diff options
-rw-r--r-- | clang/include/clang/Basic/CodeGenOptions.def | 1 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 | ||||
-rw-r--r-- | clang/include/clang/Driver/Options.td | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 18 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/CommonArgs.cpp | 21 | ||||
-rw-r--r-- | clang/test/Driver/crel.c | 31 | ||||
-rw-r--r-- | clang/test/Misc/cc1as-crel.s | 6 | ||||
-rw-r--r-- | clang/tools/driver/cc1as_main.cpp | 6 |
9 files changed, 91 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index e3f6da4..25de220 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -36,6 +36,7 @@ VALUE_CODEGENOPT(Name, Bits, Default) #endif CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as +CODEGENOPT(Crel, 1, 0) ///< -Wa,--crel CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no} CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm. CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments. diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 1ca2cb8..a62bdc2 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -801,6 +801,10 @@ def warn_drv_missing_multilib : Warning< def note_drv_available_multilibs : Note< "available multilibs are:%0">; +def err_drv_experimental_crel : Error< + "-Wa,--allow-experimental-crel must be specified to use -Wa,--crel. " + "CREL is experimental and uses a non-standard section type code">; + def warn_android_unversioned_fallback : Warning< "using unversioned Android target directory %0 for target %1; unversioned " "directories will not be used in Clang 19 -- provide a versioned directory " diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index af5ed95..58ca6f2 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -7027,6 +7027,9 @@ def massembler_no_warn : Flag<["-"], "massembler-no-warn">, def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">, HelpText<"Make assembler warnings fatal">, MarshallingInfoFlag<CodeGenOpts<"FatalWarnings">>; +def crel : Flag<["--"], "crel">, + HelpText<"Enable CREL relocation format (ELF only)">, + MarshallingInfoFlag<CodeGenOpts<"Crel">>; def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">, HelpText<"Disable x86 relax relocations">, MarshallingInfoNegativeFlag<CodeGenOpts<"RelaxELFRelocations">>; diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 4195bb8..e765bbf 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -470,6 +470,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose; Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64; Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments; + Options.MCOptions.Crel = CodeGenOpts.Crel; Options.MCOptions.X86RelaxRelocations = CodeGenOpts.RelaxELFRelocations; Options.MCOptions.CompressDebugSections = CodeGenOpts.getCompressDebugSections(); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index cf1767a..aa285c3 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2500,6 +2500,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, // arg after parsing the '-I' arg. bool TakeNextArg = false; + const llvm::Triple &Triple = C.getDefaultToolChain().getTriple(); + bool Crel = false, ExperimentalCrel = false; bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations(); bool UseNoExecStack = false; const char *MipsTargetFeature = nullptr; @@ -2623,6 +2625,12 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, Value == "-nocompress-debug-sections" || Value == "--nocompress-debug-sections") { CmdArgs.push_back(Value.data()); + } else if (Value == "--crel") { + Crel = true; + } else if (Value == "--no-crel") { + Crel = false; + } else if (Value == "--allow-experimental-crel") { + ExperimentalCrel = true; } else if (Value == "-mrelax-relocations=yes" || Value == "--mrelax-relocations=yes") { UseRelaxRelocations = true; @@ -2688,6 +2696,16 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, } if (ImplicitIt.size()) AddARMImplicitITArgs(Args, CmdArgs, ImplicitIt); + if (Crel) { + if (!ExperimentalCrel) + D.Diag(diag::err_drv_experimental_crel); + if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) { + CmdArgs.push_back("--crel"); + } else { + D.Diag(diag::err_drv_unsupported_opt_for_target) + << "-Wa,--crel" << D.getTargetTriple(); + } + } if (!UseRelaxRelocations) CmdArgs.push_back("-mrelax-relocations=no"); if (UseNoExecStack) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 2cb152f..c56a0c2 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1133,6 +1133,27 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, addMachineOutlinerArgs(D, Args, CmdArgs, ToolChain.getEffectiveTriple(), /*IsLTO=*/true, PluginOptPrefix); + + for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) { + bool Crel = false; + for (StringRef V : A->getValues()) { + if (V == "--crel") + Crel = true; + else if (V == "--no-crel") + Crel = false; + else + continue; + A->claim(); + } + if (Crel) { + if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) { + CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "-crel")); + } else { + D.Diag(diag::err_drv_unsupported_opt_for_target) + << "-Wa,--crel" << D.getTargetTriple(); + } + } + } } /// Adds the '-lcgpu' and '-lmgpu' libraries to the compilation to include the diff --git a/clang/test/Driver/crel.c b/clang/test/Driver/crel.c new file mode 100644 index 0000000..a47e7eb --- /dev/null +++ b/clang/test/Driver/crel.c @@ -0,0 +1,31 @@ +// RUN: not %clang -### -c --target=x86_64 -Wa,--crel %s 2>&1 | FileCheck %s --check-prefix=NOEXP + +// NOEXP: error: -Wa,--allow-experimental-crel must be specified to use -Wa,--crel. CREL is experimental and uses a non-standard section type code + +// RUN: %clang -### -c --target=x86_64 -Wa,--crel,--allow-experimental-crel %s -Werror 2>&1 | FileCheck %s +// RUN: %clang -### -c --target=x86_64 -Wa,--crel,--no-crel,--allow-experimental-crel %s -Werror 2>&1 | FileCheck %s --check-prefix=NO +// RUN: %clang -### -c --target=x86_64 -Wa,--allow-experimental-crel %s -Werror 2>&1 | FileCheck %s --check-prefix=NO +// RUN: not %clang -### -c --target=arm64-apple-darwin -Wa,--crel,--allow-experimental-crel %s 2>&1 | FileCheck %s --check-prefix=ERR +// RUN: not %clang -### -c --target=mips64 -Wa,--crel,--allow-experimental-crel %s 2>&1 | FileCheck %s --check-prefix=ERR + +// RUN: %clang -### -c --target=aarch64 -Werror -Wa,--crel,--allow-experimental-crel -x assembler %s -Werror 2>&1 | FileCheck %s --check-prefix=ASM +// RUN: not %clang -### -c --target=mips64 -Wa,--crel,--allow-experimental-crel -x assembler %s 2>&1 | FileCheck %s --check-prefix=ERR + +// CHECK: "-cc1" {{.*}}"--crel" +// NO: "-cc1" +// NO-NOT: "--crel" +// ASM: "-cc1as" {{.*}}"--crel" +// ERR: error: unsupported option '-Wa,--crel' for target '{{.*}}' + +/// The --allow-experimental-crel error check is exempted for -fno-integrated-as. +// RUN: %clang -### -c --target=aarch64 -fno-integrated-as -Wa,--crel %s -Werror 2>&1 | FileCheck %s --check-prefix=GAS + +// GAS: "--crel" + +/// The --allow-experimental-crel error check doesn't apply to LTO. +// RUN: %clang -### --target=x86_64-linux -Werror -flto -Wa,--crel %s 2>&1 | FileCheck %s --check-prefix=LTO + +// LTO: "-plugin-opt=-crel" + +// RUN: touch %t.o +// RUN: not %clang -### --target=mips64-linux-gnu -flto -Wa,--crel %t.o 2>&1 | FileCheck %s --check-prefix=ERR diff --git a/clang/test/Misc/cc1as-crel.s b/clang/test/Misc/cc1as-crel.s new file mode 100644 index 0000000..78e78b0 --- /dev/null +++ b/clang/test/Misc/cc1as-crel.s @@ -0,0 +1,6 @@ +// REQUIRES: x86-registered-target +// RUN: %clang -cc1as -triple x86_64 %s -filetype obj --crel -o %t.o +// RUN: llvm-readelf -S %t.o | FileCheck %s + +// CHECK: .crel.text CREL +call foo diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index ce1e181..4e0aa14 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -164,6 +164,9 @@ struct AssemblerInvocation { LLVM_PREFERRED_TYPE(bool) unsigned EmitCompactUnwindNonCanonical : 1; + LLVM_PREFERRED_TYPE(bool) + unsigned Crel : 1; + /// The name of the relocation model to use. std::string RelocationModel; @@ -204,6 +207,7 @@ public: EmbedBitcode = 0; EmitDwarfUnwind = EmitDwarfUnwindType::Default; EmitCompactUnwindNonCanonical = false; + Crel = false; } static bool CreateFromArgs(AssemblerInvocation &Res, @@ -373,6 +377,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, Opts.EmitCompactUnwindNonCanonical = Args.hasArg(OPT_femit_compact_unwind_non_canonical); + Opts.Crel = Args.hasArg(OPT_crel); Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file); @@ -430,6 +435,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels; + MCOptions.Crel = Opts.Crel; MCOptions.X86RelaxRelocations = Opts.RelaxELFRelocations; MCOptions.CompressDebugSections = Opts.CompressDebugSections; MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; |