diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -725,13 +725,16 @@ CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-function-sections=0")); + bool DataSectionsTurnedOff = false; if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections, - UseSeparateSections)) + UseSeparateSections)) { CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=1")); - else if (Args.hasArg(options::OPT_fno_data_sections)) + } else if (Args.hasArg(options::OPT_fno_data_sections)) { + DataSectionsTurnedOff = true; CmdArgs.push_back( Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=0")); + } if (Args.hasArg(options::OPT_mxcoff_roptr) || Args.hasArg(options::OPT_mno_xcoff_roptr)) { @@ -744,8 +747,10 @@ << OptStr << ToolChain.getTriple().str(); if (HasRoptr) { - if (!Args.hasFlag(options::OPT_fdata_sections, - options::OPT_fno_data_sections, UseSeparateSections)) + // The data sections option is on by default on AIX. We only need to error + // out when -fno-data-sections is specified explicitly to turn off data + // sections. + if (DataSectionsTurnedOff) D.Diag(diag::err_roptr_requires_data_sections); CmdArgs.push_back( diff --git a/clang/test/Driver/ppc-roptr.c b/clang/test/Driver/ppc-roptr.c --- a/clang/test/Driver/ppc-roptr.c +++ b/clang/test/Driver/ppc-roptr.c @@ -12,7 +12,7 @@ // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=NO_ROPTR // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \ -// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR +// RUN: FileCheck %s --check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR // RUN: touch %t.o // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \ // RUN: FileCheck %s --check-prefix=LINK @@ -33,14 +33,14 @@ // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \ // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR -// ROPTR: "-mxcoff-roptr" -// LINK: "-bforceimprw" -// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr" -// NO_ROPTR-NOT: "-mxcoff-roptr" -// NO_ROPTR-NOT: "-bforceimprw" - // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu' // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu' // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared + +// ROPTR: "-mxcoff-roptr" +// LINK: "-bforceimprw" +// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr" +// NO_ROPTR-NOT: "-mxcoff-roptr" +// NO_ROPTR-NOT: "-bforceimprw"