r288397 - [clang] Implement support for -defsym assembler option
Mandeep Singh Grang via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 1 10:42:16 PST 2016
Author: mgrang
Date: Thu Dec 1 12:42:16 2016
New Revision: 288397
URL: http://llvm.org/viewvc/llvm-project?rev=288397&view=rev
Log:
[clang] Implement support for -defsym assembler option
Summary:
Adds support for -Wa,-defsym,abc=1 option.
Related llvm patch: https://reviews.llvm.org/D26214
Reviewers: rafael, t.p.northover, colinl, echristo, compnerd, rengolin
Subscribers: mehdi_amini
Tags: #clang-c
Differential Revision: https://reviews.llvm.org/D26213
Added:
cfe/trunk/test/Driver/defsym.s
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/tools/driver/cc1as_main.cpp
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=288397&r1=288396&r2=288397&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Dec 1 12:42:16 2016
@@ -743,4 +743,6 @@ def show_inst : Flag<["-"], "show-inst">
def dwarf_debug_producer : Separate<["-"], "dwarf-debug-producer">,
HelpText<"The string to embed in the Dwarf debug AT_producer record.">;
+def defsym : Separate<["-"], "defsym">,
+ HelpText<"Define a value for a symbol">;
} // let Flags = [CC1AsOption]
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=288397&r1=288396&r2=288397&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Dec 1 12:42:16 2016
@@ -3115,6 +3115,9 @@ static void CollectArgsForIntegratedAsse
} else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
Value.startswith("-mhwdiv") || Value.startswith("-march")) {
// Do nothing, we'll validate it later.
+ } else if (Value == "-defsym") {
+ CmdArgs.push_back(Value.data());
+ TakeNextArg = true;
} else {
D.Diag(diag::err_drv_unsupported_option_argument)
<< A->getOption().getName() << Value;
Added: cfe/trunk/test/Driver/defsym.s
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/defsym.s?rev=288397&view=auto
==============================================================================
--- cfe/trunk/test/Driver/defsym.s (added)
+++ cfe/trunk/test/Driver/defsym.s Thu Dec 1 12:42:16 2016
@@ -0,0 +1,22 @@
+// RUN: %clang -### -c -integrated-as %s \
+// RUN: -Wa,-defsym,abc=5 -Wa,-defsym,xyz=0xa \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM1
+
+// RUN: %clang -### -c -no-integrated-as %s \
+// RUN: -Wa,-defsym,abc=5 -Wa,-defsym,xyz=0xa \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM1
+
+// CHECK-DEFSYM1: "-defsym"
+// CHECK-DEFSYM1: "abc=5"
+// CHECK-DEFSYM1: "-defsym"
+// CHECK-DEFSYM1: "xyz=0xa"
+
+// RUN: not %clang -c -integrated-as %s \
+// RUN: -Wa,-defsym,abc= \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM-ERR1
+// CHECK-DEFSYM-ERR1: error: defsym must be of the form: sym=value: abc=
+
+// RUN: not %clang -c -integrated-as %s \
+// RUN: -Wa,-defsym,abc=1a2b3c \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM-ERR2
+// CHECK-DEFSYM-ERR2: error: Value is not an integer: 1a2b3c
Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=288397&r1=288396&r2=288397&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Thu Dec 1 12:42:16 2016
@@ -77,6 +77,9 @@ struct AssemblerInvocation {
/// be a list of strings starting with '+' or '-'.
std::vector<std::string> Features;
+ /// The list of symbol definitions.
+ std::vector<std::string> SymbolDefs;
+
/// @}
/// @name Language Options
/// @{
@@ -252,6 +255,7 @@ bool AssemblerInvocation::CreateFromArgs
Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
Opts.IncrementalLinkerCompatible =
Args.hasArg(OPT_mincremental_linker_compatible);
+ Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
return Success;
}
@@ -420,6 +424,14 @@ static bool ExecuteAssembler(AssemblerIn
if (!TAP)
Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
+ // Set values for symbols, if any.
+ for (auto &S : Opts.SymbolDefs) {
+ if (Ctx.setSymbolValue(Parser->getStreamer(), S)) {
+ Failed = true;
+ break;
+ }
+ }
+
if (!Failed) {
Parser->setTargetParser(*TAP.get());
Failed = Parser->Run(Opts.NoInitialTextSection);
More information about the cfe-commits
mailing list