Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2041,6 +2041,10 @@ def mno_gpopt : Flag<["-"], "mno-gpopt">, Group, HelpText<"Do not use GP relative accesses for symbols known to be in a small" " data section (MIPS)">; +def mlocal_sdata : Flag<["-"], "mlocal-sdata">, Group, + HelpText<"Extend the -G behaviour to object local data (MIPS)">; +def mno_local_sdata : Flag<["-"], "mno-local-sdata">, Group, + HelpText<"Do not extend the -G behaviour to object local data (MIPS)">; def mnan_EQ : Joined<["-"], "mnan=">, Group; def mabicalls : Flag<["-"], "mabicalls">, Group, HelpText<"Enable SVR4-style position-independent code (Mips only)">; Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -1464,7 +1464,8 @@ Arg *GPOpt = Args.getLastArg(options::OPT_mgpopt, options::OPT_mno_gpopt); Arg *ABICalls = Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls); - + Arg *LocalSData = + Args.getLastArg(options::OPT_mlocal_sdata, options::OPT_mno_local_sdata); // -mabicalls is the default for many MIPS environments, even with -fno-pic. // -mgpopt is the default for static, -fno-pic environments but these two // options conflict. We want to be certain that -mno-abicalls -mgpopt is @@ -1487,6 +1488,16 @@ if (GPOpt) GPOpt->claim(); + + if (LocalSData) { + CmdArgs.push_back("-mllvm"); + if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) { + CmdArgs.push_back("-mlocal-sdata=1"); + } else { + CmdArgs.push_back("-mlocal-sdata=0"); + } + LocalSData->claim(); + } } if (Arg *A = Args.getLastArg(options::OPT_mcompact_branches_EQ)) { Index: test/Driver/mips-features.c =================================================================== --- test/Driver/mips-features.c +++ test/Driver/mips-features.c @@ -35,6 +35,21 @@ // RUN: | FileCheck --check-prefix=CHECK-MGPOPTDEF %s // CHECK-MGPOPTDEF: "-mllvm" "-mgpopt=1" // +// -mgpopt -mno-abicalls -mlocal-sdata +// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt -mgpopt -mno-local-sdata -mlocal-sdata 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MLOCALSDATA %s +// CHECK-MLOCALSDATA: "-mllvm" "-mlocal-sdata=1" +// +// -mgpopt -mno-abicalls -mno-local-sdata +// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt -mgpopt -mlocal-sdata -mno-local-sdata 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MNOLOCALSDATA %s +// CHECK-MNOLOCALSDATA: "-mllvm" "-mlocal-sdata=0" +// +// -mgpopt -mno-abicalls +// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s +// CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata" +// // -mips16 // RUN: %clang -target mips-linux-gnu -### -c %s \ // RUN: -mno-mips16 -mips16 2>&1 \