From cf4c953d2c070d1c505f512a0d395a60b95c3728 Mon Sep 17 00:00:00 2001 From: Simon Dardis Date: Thu, 3 Aug 2017 13:04:29 +0000 Subject: [PATCH] [mips] Add support -m(no-)embedded-data option Add support for the -membedded-data option which places constant data in the .rodata section, rather than the .sdata section. Reviewers: atanasyan, nitesh.jain Differential Revision: https://reviews.llvm.org/D35914 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309935 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 6 ++++++ lib/Driver/ToolChains/Clang.cpp | 15 ++++++++++++++- test/Driver/mips-features.c | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index ccf6dd63e5..571d52fc0a 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -2051,6 +2051,12 @@ def mextern_sdata : Flag<["-"], "mextern-sdata">, Group, def mno_extern_sdata : Flag<["-"], "mno-extern-sdata">, Group, HelpText<"Do not assume that externally defined data is in the small data if" " it meets the -G threshold (MIPS)">; +def membedded_data : Flag<["-"], "membedded-data">, Group, + HelpText<"Place constants in the .rodata section instead of the .sdata " + "section even if they meet the -G threshold (MIPS)">; +def mno_embedded_data : Flag<["-"], "mno-embedded-data">, Group, + HelpText<"Do not place constants in the .rodata section instead of the " + ".sdata if they meet the -G threshold (MIPS)">; def mnan_EQ : Joined<["-"], "mnan=">, Group; def mabicalls : Flag<["-"], "mabicalls">, Group, HelpText<"Enable SVR4-style position-independent code (Mips only)">; diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 16c700106e..80fc9923d3 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -1484,7 +1484,9 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args, Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata, options::OPT_mno_local_sdata); Arg *ExternSData = Args.getLastArg(options::OPT_mextern_sdata, - options::OPT_mno_extern_sdata); + options::OPT_mno_extern_sdata); + Arg *EmbeddedData = Args.getLastArg(options::OPT_membedded_data, + options::OPT_mno_embedded_data); if (LocalSData) { CmdArgs.push_back("-mllvm"); if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) { @@ -1504,6 +1506,17 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args, } ExternSData->claim(); } + + if (EmbeddedData) { + CmdArgs.push_back("-mllvm"); + if (EmbeddedData->getOption().matches(options::OPT_membedded_data)) { + CmdArgs.push_back("-membedded-data=1"); + } else { + CmdArgs.push_back("-membedded-data=0"); + } + EmbeddedData->claim(); + } + } else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt) D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1); diff --git a/test/Driver/mips-features.c b/test/Driver/mips-features.c index 6e8f6170c9..80143c25ee 100644 --- a/test/Driver/mips-features.c +++ b/test/Driver/mips-features.c @@ -65,6 +65,21 @@ // RUN: | FileCheck --check-prefix=CHECK-MEXTERNSDATADEF %s // CHECK-MEXTERNSDATADEF-NOT: "-mllvm" "-mextern-sdata" // +// -mno-abicalls -mgpopt -membedded-data +// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt -mno-embedded-data -membedded-data 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MEMBEDDEDDATA %s +// CHECK-MEMBEDDEDDATA: "-mllvm" "-membedded-data=1" +// +// -mno-abicalls -mgpopt -mno-embedded-data +// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt -membedded-data -mno-embedded-data 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MNOEMBEDDEDDATA %s +// CHECK-MNOEMBEDDEDDATA: "-mllvm" "-membedded-data=0" +// +// -mno-abicalls -mgpopt +// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MEMBEDDEDDATADEF %s +// CHECK-MEMBEDDEDDATADEF-NOT: "-mllvm" "-membedded-data" +// // -mips16 // RUN: %clang -target mips-linux-gnu -### -c %s \ // RUN: -mno-mips16 -mips16 2>&1 \ -- 2.40.0