[clang] ac1d143 - [Clang][AIX][p] Manually Claim -p in front end
Author: Michael Francis Date: 2023-03-15T23:26:48Z New Revision: ac1d143b0ef924cf2725bb36537f18ae2c7f9c4f URL: https://github.com/llvm/llvm-project/commit/ac1d143b0ef924cf2725bb36537f18ae2c7f9c4f DIFF: https://github.com/llvm/llvm-project/commit/ac1d143b0ef924cf2725bb36537f18ae2c7f9c4f.diff LOG: [Clang][AIX][p] Manually Claim -p in front end The current implementation of `-p` does not claim the argument once it is passed. Since it pushes `-pg` directly, it is only ever referred to again when linking. As a result, when compiling with `-S`, the compiler warns that `-p` goes unused even though that is not the case. With this patch, if both `-p` and `-pg` are passed, the argument that is passed second will take precedence. `-p` will still throw an error on unsupported platforms, regardless of precedence. This revision includes a test case, which has been placed in `clang/test/Driver/zos-profiling-error.c`. As a result, `zos-profiling-error.c` has been renamed to `ibm-profiling.c`. This revision also passes `clang/test/Driver/aix-ld.c`. Differential Revision: https://reviews.llvm.org/D145021 Added: clang/test/Driver/ibm-profiling.c Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/Clang.cpp Removed: clang/test/Driver/zos-profiling-error.c diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 15560e1c81bca..f41fb768fdc06 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -164,14 +164,14 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, } auto getCrt0Basename = [&Args, IsArch32Bit] { -// Enable gprofiling when "-pg" is specified. -if (Args.hasArg(options::OPT_pg)) - return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; -// Enable profiling when "-p" is specified. -else if (Args.hasArg(options::OPT_p)) +if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) { + // Enable gprofiling when "-pg" is specified. + if (A->getOption().matches(options::OPT_pg)) +return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; + // Enable profiling when "-p" is specified. return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o"; -else - return IsArch32Bit ? "crt0.o" : "crt0_64.o"; +} +return IsArch32Bit ? "crt0.o" : "crt0_64.o"; }; if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, @@ -271,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lc"); -if (Args.hasArg(options::OPT_p, options::OPT_pg)) { +if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) { CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + "/lib/profiled")); CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 79fcf4526df3e..87862e028636f 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6322,20 +6322,26 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, << A->getAsString(Args) << TripleStr; } } - if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { -if (TC.getTriple().isOSAIX()) { - CmdArgs.push_back("-pg"); -} else if (!TC.getTriple().isOSOpenBSD()) { + + if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { +if (TC.getTriple().isOSzOS()) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } } - if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { -if (TC.getTriple().isOSzOS()) { + if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { +if (!(TC.getTriple().isOSAIX() || TC.getTriple().isOSOpenBSD())) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } } + if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) { +if (A->getOption().matches(options::OPT_p)) { + A->claim(); + if (TC.getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg)) +CmdArgs.push_back("-pg"); +} + } if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) diff --git a/clang/test/Driver/ibm-profiling.c b/clang/test/Driver/ibm-profiling.c new file mode 100644 index 0..26bc0d7784373 --- /dev/null +++ b/clang/test/Driver/ibm-profiling.c @@ -0,0 +1,27 @@ +// Check that -pg throws an error on z/OS. +// RUN: %clang -### 2>&1 --target=s390x-none-zos -S -pg %s | FileCheck -check-prefix=FAIL-PG-NAME %s +// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos' + +// Check that -p is still used when not linking on AIX. +// R
[clang] 5259da7 - [AIX][Clang] Respect -r when invoking the linker
Author: Michael Francis Date: 2023-03-20T17:56:39Z New Revision: 5259da75b9352592cd12fc2c6b6b875567989867 URL: https://github.com/llvm/llvm-project/commit/5259da75b9352592cd12fc2c6b6b875567989867 DIFF: https://github.com/llvm/llvm-project/commit/5259da75b9352592cd12fc2c6b6b875567989867.diff LOG: [AIX][Clang] Respect -r when invoking the linker On AIX, libraries are still being linked when `-r` is passed to the driver. This patch corrects this error. Differential Revision: https://reviews.llvm.org/D145899 Added: Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/test/Driver/aix-ld.c Removed: diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index f41fb768fdc06..d4d13ce36e76f 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -175,7 +175,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, }; if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, - options::OPT_shared)) { + options::OPT_shared, options::OPT_r)) { CmdArgs.push_back( Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(; @@ -235,47 +235,49 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Add directory to library search path. Args.AddAllArgs(CmdArgs, options::OPT_L); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - ToolChain.addProfileRTLibs(Args, CmdArgs); - - if (getToolChain().ShouldLinkCXXStdlib(Args)) -getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); - - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { -AddRunTimeLibs(ToolChain, D, CmdArgs, Args); - -// Add OpenMP runtime if -fopenmp is specified. -if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, - options::OPT_fno_openmp, false)) { - switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { - case Driver::OMPRT_OMP: -CmdArgs.push_back("-lomp"); -break; - case Driver::OMPRT_IOMP5: -CmdArgs.push_back("-liomp5"); -break; - case Driver::OMPRT_GOMP: -CmdArgs.push_back("-lgomp"); -break; - case Driver::OMPRT_Unknown: -// Already diagnosed. -break; + if (!Args.hasArg(options::OPT_r)) { +ToolChain.addProfileRTLibs(Args, CmdArgs); + +if (getToolChain().ShouldLinkCXXStdlib(Args)) + getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); + +if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { + AddRunTimeLibs(ToolChain, D, CmdArgs, Args); + + // Add OpenMP runtime if -fopenmp is specified. + if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, + options::OPT_fno_openmp, false)) { +switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { +case Driver::OMPRT_OMP: + CmdArgs.push_back("-lomp"); + break; +case Driver::OMPRT_IOMP5: + CmdArgs.push_back("-liomp5"); + break; +case Driver::OMPRT_GOMP: + CmdArgs.push_back("-lgomp"); + break; +case Driver::OMPRT_Unknown: + // Already diagnosed. + break; +} } -} -// Support POSIX threads if "-pthreads" or "-pthread" is present. -if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread)) - CmdArgs.push_back("-lpthreads"); + // Support POSIX threads if "-pthreads" or "-pthread" is present. + if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread)) +CmdArgs.push_back("-lpthreads"); -if (D.CCCIsCXX()) - CmdArgs.push_back("-lm"); + if (D.CCCIsCXX()) +CmdArgs.push_back("-lm"); -CmdArgs.push_back("-lc"); + CmdArgs.push_back("-lc"); -if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) { - CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + - "/lib/profiled")); - CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + - "/usr/lib/profiled")); + if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) { +CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + + "/lib/profiled")); +CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + + "/usr/lib/profiled")); + } } } diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c index 38ac440aabdc6..eb2910db239ff 100644 --- a/clang/test/Driver/aix-ld.c +++ b/clang/test/Driver/aix-ld.c @@ -1077,3 +1077,22 @@ // RUN:-fopenmp=libfoo \ // RUN: | FileCheck --check-prefixes=CHECK-FOPENMP-FOO %s // CHECK-FOPENMP-FOO: error: unsupported argument 'libfoo'
[clang] 4c483a0 - [AIX] Consolidate Crt0Basename logic
Author: Michael Francis Date: 2023-03-21T00:47:05Z New Revision: 4c483a046d2ff29ec2fd5bad6305f97424a2b880 URL: https://github.com/llvm/llvm-project/commit/4c483a046d2ff29ec2fd5bad6305f97424a2b880 DIFF: https://github.com/llvm/llvm-project/commit/4c483a046d2ff29ec2fd5bad6305f97424a2b880.diff LOG: [AIX] Consolidate Crt0Basename logic when certain flags are specified, the Crt0 object files are not linked. However, the logic for determining which files will always run. This patch moves that logic so that the basename is only determined if it is needed. Differential Revision: https://reviews.llvm.org/D146443 Added: Modified: clang/lib/Driver/ToolChains/AIX.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index d4d13ce36e76f..5521a38d9bc0a 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -163,19 +163,19 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-bpD:0x11000"); } - auto getCrt0Basename = [&Args, IsArch32Bit] { -if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) { - // Enable gprofiling when "-pg" is specified. - if (A->getOption().matches(options::OPT_pg)) -return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; - // Enable profiling when "-p" is specified. - return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o"; -} -return IsArch32Bit ? "crt0.o" : "crt0_64.o"; - }; - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared, options::OPT_r)) { +auto getCrt0Basename = [&Args, IsArch32Bit] { + if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) { +// Enable gprofiling when "-pg" is specified. +if (A->getOption().matches(options::OPT_pg)) + return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; +// Enable profiling when "-p" is specified. +return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o"; + } + return IsArch32Bit ? "crt0.o" : "crt0_64.o"; +}; + CmdArgs.push_back( Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4dc0455 - [AIX][r] Do not call AddFilePathLibArgs with -r
Author: Michael Francis Date: 2023-03-22T02:25:46Z New Revision: 4dc04557d71c1752c53eb8025957df8f1bdbb1e1 URL: https://github.com/llvm/llvm-project/commit/4dc04557d71c1752c53eb8025957df8f1bdbb1e1 DIFF: https://github.com/llvm/llvm-project/commit/4dc04557d71c1752c53eb8025957df8f1bdbb1e1.diff LOG: [AIX][r] Do not call AddFilePathLibArgs with -r We do not want to add file path lib args when -r is specified. Differential Revision: https://reviews.llvm.org/D146578 Added: Modified: clang/lib/Driver/ToolChains/AIX.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 5521a38d9bc0a..711e8619d0a79 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -234,8 +234,8 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Add directory to library search path. Args.AddAllArgs(CmdArgs, options::OPT_L); - ToolChain.AddFilePathLibArgs(Args, CmdArgs); if (!Args.hasArg(options::OPT_r)) { +ToolChain.AddFilePathLibArgs(Args, CmdArgs); ToolChain.addProfileRTLibs(Args, CmdArgs); if (getToolChain().ShouldLinkCXXStdlib(Args)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 59848b9 - [Clang][AIX][p] Manually Claim -p in front end
Author: Michael Francis Date: 2023-03-12T07:33:21Z New Revision: 59848b9ebae6a92a4342b1e8aa32feaf5c9c4b51 URL: https://github.com/llvm/llvm-project/commit/59848b9ebae6a92a4342b1e8aa32feaf5c9c4b51 DIFF: https://github.com/llvm/llvm-project/commit/59848b9ebae6a92a4342b1e8aa32feaf5c9c4b51.diff LOG: [Clang][AIX][p] Manually Claim -p in front end The current implementation of `-p` does not claim the argument once it is passed. Since it pushes `-pg` directly, it is only ever referred to again when linking. As a result, when compiling with `-S`, the compiler warns that `-p` goes unused even though that is not the case. With this patch, if both `-p` and `-pg` are passed, the argument that is passed second will take precedence. `-p` will still throw an error on unsupported platforms, regardless of precedence. This revision includes a test case, which has been placed in `clang/test/Driver/zos-profiling-error.c`. As a result, `zos-profiling-error.c` has been renamed to `ibm-profiling.c`. This revision also passes `clang/test/Driver/aix-ld.c`. Differential Revision: https://reviews.llvm.org/D145021 Added: clang/test/Driver/ibm-profiling.c Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/Clang.cpp Removed: clang/test/Driver/zos-profiling-error.c diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 15560e1c81bca..57234f235156e 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -164,11 +164,12 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, } auto getCrt0Basename = [&Args, IsArch32Bit] { +Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg); // Enable gprofiling when "-pg" is specified. -if (Args.hasArg(options::OPT_pg)) +if (A->getOption().matches(options::OPT_pg)) return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; // Enable profiling when "-p" is specified. -else if (Args.hasArg(options::OPT_p)) +else if (A->getOption().matches(options::OPT_p)) return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o"; else return IsArch32Bit ? "crt0.o" : "crt0_64.o"; @@ -271,7 +272,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lc"); -if (Args.hasArg(options::OPT_p, options::OPT_pg)) { +if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) { CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + "/lib/profiled")); CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 79fcf4526df3e..87862e028636f 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6322,20 +6322,26 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, << A->getAsString(Args) << TripleStr; } } - if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { -if (TC.getTriple().isOSAIX()) { - CmdArgs.push_back("-pg"); -} else if (!TC.getTriple().isOSOpenBSD()) { + + if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { +if (TC.getTriple().isOSzOS()) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } } - if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { -if (TC.getTriple().isOSzOS()) { + if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { +if (!(TC.getTriple().isOSAIX() || TC.getTriple().isOSOpenBSD())) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } } + if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) { +if (A->getOption().matches(options::OPT_p)) { + A->claim(); + if (TC.getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg)) +CmdArgs.push_back("-pg"); +} + } if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) diff --git a/clang/test/Driver/ibm-profiling.c b/clang/test/Driver/ibm-profiling.c new file mode 100644 index 0..26bc0d7784373 --- /dev/null +++ b/clang/test/Driver/ibm-profiling.c @@ -0,0 +1,27 @@ +// Check that -pg throws an error on z/OS. +// RUN: %clang -### 2>&1 --target=s390x-none-zos -S -pg %s | FileCheck -check-prefix=FAIL-PG-NAME %s +// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos' + +// Check that -p is still used when not linking on AIX. +// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 -S -p -S %s \ +// RUN: | FileCheck --check-prefix=CHECK %s +// CHECK-NOT: warning: argument unused during compilation: '-p' + +// Check precedence: -pg is unused when passed first on AIX. +// RU
[clang] 7488dd2 - Revert "[Clang][AIX][p] Manually Claim -p in front end"
Author: Michael Francis Date: 2023-03-12T08:14:33Z New Revision: 7488dd25e1613894d79d69f153469545b9bf660a URL: https://github.com/llvm/llvm-project/commit/7488dd25e1613894d79d69f153469545b9bf660a DIFF: https://github.com/llvm/llvm-project/commit/7488dd25e1613894d79d69f153469545b9bf660a.diff LOG: Revert "[Clang][AIX][p] Manually Claim -p in front end" This reverts commit 59848b9ebae6a92a4342b1e8aa32feaf5c9c4b51, as it causes some failures in AIX-related Lit tests. Added: clang/test/Driver/zos-profiling-error.c Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/Clang.cpp Removed: clang/test/Driver/ibm-profiling.c diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 57234f235156e..15560e1c81bca 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -164,12 +164,11 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, } auto getCrt0Basename = [&Args, IsArch32Bit] { -Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg); // Enable gprofiling when "-pg" is specified. -if (A->getOption().matches(options::OPT_pg)) +if (Args.hasArg(options::OPT_pg)) return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; // Enable profiling when "-p" is specified. -else if (A->getOption().matches(options::OPT_p)) +else if (Args.hasArg(options::OPT_p)) return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o"; else return IsArch32Bit ? "crt0.o" : "crt0_64.o"; @@ -272,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lc"); -if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) { +if (Args.hasArg(options::OPT_p, options::OPT_pg)) { CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + "/lib/profiled")); CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 87862e028636f..79fcf4526df3e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6322,26 +6322,20 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, << A->getAsString(Args) << TripleStr; } } - - if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { -if (TC.getTriple().isOSzOS()) { + if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { +if (TC.getTriple().isOSAIX()) { + CmdArgs.push_back("-pg"); +} else if (!TC.getTriple().isOSOpenBSD()) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } } - if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { -if (!(TC.getTriple().isOSAIX() || TC.getTriple().isOSOpenBSD())) { + if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { +if (TC.getTriple().isOSzOS()) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } } - if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) { -if (A->getOption().matches(options::OPT_p)) { - A->claim(); - if (TC.getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg)) -CmdArgs.push_back("-pg"); -} - } if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) diff --git a/clang/test/Driver/ibm-profiling.c b/clang/test/Driver/ibm-profiling.c deleted file mode 100644 index 26bc0d7784373..0 --- a/clang/test/Driver/ibm-profiling.c +++ /dev/null @@ -1,27 +0,0 @@ -// Check that -pg throws an error on z/OS. -// RUN: %clang -### 2>&1 --target=s390x-none-zos -S -pg %s | FileCheck -check-prefix=FAIL-PG-NAME %s -// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos' - -// Check that -p is still used when not linking on AIX. -// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 -S -p -S %s \ -// RUN: | FileCheck --check-prefix=CHECK %s -// CHECK-NOT: warning: argument unused during compilation: '-p' - -// Check precedence: -pg is unused when passed first on AIX. -// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 --sysroot %S/Inputs/aix_ppc_tree -pg -p %s \ -// RUN:| FileCheck --check-prefix=CHECK2 %s -// CHECK2-NOT: warning: argument unused during compilation: '-p' [-Wunused-command-line-argument] -// CHECK2: "-isysroot" "[[SYSROOT:[^"]+]]" -// CHECK2: "[[SYSROOT]]/usr/lib{{/|}}mcrt0.o" -// CHECK2: "-L[[SYSROOT]]/lib/profiled" -// CHECK2: "-L[[SYSROOT]]/usr/lib/profiled" - -// Check precedence: -p is unused when passed first on AIX. -// RUN: %clang -### 2>&1 --target=powerpc-ibm-aix7.1.0.0 --sysroot %S/Inputs/aix_ppc_tree -p -pg %s \ -// RUN:| Fi
[clang] 7f85c56 - [Clang][AIX][p]Enable -p Functionality
Author: Michael Francis Date: 2023-02-09T16:13:51Z New Revision: 7f85c560b43bd1b2ebf77cc443281b474b5e19c6 URL: https://github.com/llvm/llvm-project/commit/7f85c560b43bd1b2ebf77cc443281b474b5e19c6 DIFF: https://github.com/llvm/llvm-project/commit/7f85c560b43bd1b2ebf77cc443281b474b5e19c6.diff LOG: [Clang][AIX][p]Enable -p Functionality This patch enables `-p` functionality into Clang on AIX and Linux To create parity with GCC. The purpose of the `-p` flag is similar to that of `-pg`, but the results are analyzed with the `prof` tool as opposed to the `gprof` tool. More details can be found in this RFC post: https://discourse.llvm.org/t/rfc-add-p-driver-support-to-clang/66013?u=francii On AIX, compiling with `-p` links against `mcrt0.o` and produces a mon.out file analyzed with the `prof` tool, while `-pg` links against `gcrt0.o` and produces a `gmon.out`file analyzed with the `gprof` tool. The differences are therefore only a concern when linking, so calling `-p` will push `-pg` to cc1. An AIX test for `-p` already exists, and I recently another test was added here: https://github.com/llvm/llvm-project/commit/dc9846ce988b9ddfcbc42cd462d5d94b634b3161 As such, there is no AIX test case attached to this patch. Reviewed By: daltenty Differential Revision: https://reviews.llvm.org/D137753 Added: Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/aix-ld.c Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6e7cdf131d937..9766a087eb6d9 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4179,6 +4179,7 @@ def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, Group>; def pedantic : Flag<["-", "--"], "pedantic">, Group, Flags<[CC1Option,FlangOption,FC1Option]>, HelpText<"Warn on language extensions">, MarshallingInfoFlag>; +def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">; def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>, MarshallingInfoFlag>; def pipe : Flag<["-", "--"], "pipe">, @@ -4225,7 +4226,6 @@ defm pthread : BoolOption<"", "pthread", LangOpts<"POSIXThreads">, DefaultFalse, PosFlag, NegFlag, BothFlags<[CC1Option]>>; -def p : Flag<["-"], "p">; def pie : Flag<["-"], "pie">, Group; def static_pie : Flag<["-"], "static-pie">, Group; def read__only__relocs : Separate<["-"], "read_only_relocs">; diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index f62b566c3946e..15560e1c81bca 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -271,7 +271,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lc"); -if (Args.hasArg(options::OPT_pg)) { +if (Args.hasArg(options::OPT_p, options::OPT_pg)) { CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + "/lib/profiled")); CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) + diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index e7ba912403d83..3aff071d75394 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6331,7 +6331,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } } if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) { -if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) { +if (TC.getTriple().isOSAIX()) { + CmdArgs.push_back("-pg"); +} else if (!TC.getTriple().isOSOpenBSD()) { D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args) << TripleStr; } diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c index 8f0125c272a69..38ac440aabdc6 100644 --- a/clang/test/Driver/aix-ld.c +++ b/clang/test/Driver/aix-ld.c @@ -135,6 +135,8 @@ // CHECK-LD32-PROF-NOT: "--no-as-needed" // CHECK-LD32-PROF-NOT: "-lm" // CHECK-LD32-PROF: "-lc" +// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled" +// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled" // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling. // RUN: %clang %s -### 2>&1 \ @@ -162,6 +164,8 @@ // CHECK-LD64-PROF-NOT: "--no-as-needed" // CHECK-LD64-PROF-NOT: "-lm" // CHECK-LD64-PROF: "-lc" +// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled" +// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling. // RUN: %clang %s -### 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ec094d2 - [z/OS][pg] Throw error when using -pg on z/OS
Author: Michael Francis Date: 2023-02-09T16:14:29Z New Revision: ec094d259ecfdd82b951f644bc9a28e487e53c60 URL: https://github.com/llvm/llvm-project/commit/ec094d259ecfdd82b951f644bc9a28e487e53c60 DIFF: https://github.com/llvm/llvm-project/commit/ec094d259ecfdd82b951f644bc9a28e487e53c60.diff LOG: [z/OS][pg] Throw error when using -pg on z/OS Throw an error when trying to compile with `-pg` on z/OS, as the platform does not support `gprof`. Reviewed By: cebowleratibm, MaskRay Differential Revision: https://reviews.llvm.org/D137756 Added: clang/test/Driver/zos-profiling-error.c Modified: clang/lib/Driver/ToolChains/Clang.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 3aff071d75394..58d6215670ad6 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6338,6 +6338,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, << A->getAsString(Args) << TripleStr; } } + if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) { +if (TC.getTriple().isOSzOS()) { + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getAsString(Args) << TripleStr; +} + } if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) diff --git a/clang/test/Driver/zos-profiling-error.c b/clang/test/Driver/zos-profiling-error.c new file mode 100644 index 0..e969dc31a245a --- /dev/null +++ b/clang/test/Driver/zos-profiling-error.c @@ -0,0 +1,2 @@ +// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s +// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5da7f30 - [AIX][Clang][K] Create `-K` Option for AIX.
Author: Michael Francis Date: 2023-05-08T22:53:44Z New Revision: 5da7f30f24c4620c4f4425206fbdd0921d333dc0 URL: https://github.com/llvm/llvm-project/commit/5da7f30f24c4620c4f4425206fbdd0921d333dc0 DIFF: https://github.com/llvm/llvm-project/commit/5da7f30f24c4620c4f4425206fbdd0921d333dc0.diff LOG: [AIX][Clang][K] Create `-K` Option for AIX. `-K` is a linker option on AIX, that is used to align the header, text, data, and loader sections of the output file so that each section begins on a page boundary. This patch creates the `-K` option in clang. On non-AIX targets, the "unsupported option" error is thrown. Differential Revision: https://reviews.llvm.org/D146399 Added: clang/test/Driver/unsupported-target-K.c Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/aix-ld.c Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 182f0290736d8..496264b74d460 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3421,6 +3421,7 @@ def vfsoverlay : JoinedOrSeparate<["-", "--"], "vfsoverlay">, Flags<[CC1Option, HelpText<"Overlay the virtual filesystem described by file over the real file system. " "Additionally, pass this overlay file to the linker if it supports it">; def imultilib : Separate<["-"], "imultilib">, Group; +def K : Flag<["-"], "K">, Flags<[LinkerInput]>; def keep__private__externs : Flag<["-"], "keep_private_externs">; def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>, Group; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 32ba56066af58..c12a6ab88097b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6326,6 +6326,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } } + if (Arg *A = Args.getLastArgNoClaim(options::OPT_K); + A && !TC.getTriple().isOSAIX()) +D.Diag(diag::err_drv_unsupported_opt_for_target) +<< A->getAsString(Args) << TripleStr; + if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) CmdArgs.push_back("-fapple-kext"); diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c index eb2910db239ff..d5c595495976a 100644 --- a/clang/test/Driver/aix-ld.c +++ b/clang/test/Driver/aix-ld.c @@ -1096,3 +1096,27 @@ // CHECK-RELOCATABLE-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o" // CHECK-RELOCATABLE-NOT: "-l{{.*}}" // CHECK-RELOCATABLE-NOT: "-L{{.*}}" + +// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option. +// RUN: %clang %s 2>&1 -### \ +// RUN:--target=powerpc-ibm-aix7.1.0.0 \ +// RUN:--sysroot %S/Inputs/aix_ppc_tree \ +// RUN:--unwindlib=libunwind \ +// RUN:-K \ +// RUN: | FileCheck --check-prefixes=CHECK-K %s +// CHECK-K: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0" +// CHECK-K: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-K: "{{.*}}ld{{(.exe)?}}" +// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crt0.o" +// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crti.o" +// CHECK-K: "-K" + +// Check powerpc-ibm-aix7.1.0.0. -K unused when not linking. +// RUN: %clang %s 2>&1 -### \ +// RUN:--target=powerpc-ibm-aix7.1.0.0 \ +// RUN:--sysroot %S/Inputs/aix_ppc_tree \ +// RUN:--unwindlib=libunwind \ +// RUN:-K \ +// RUN:-c \ +// RUN: | FileCheck --check-prefixes=CHECK-K-UNUSED %s +// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument] diff --git a/clang/test/Driver/unsupported-target-K.c b/clang/test/Driver/unsupported-target-K.c new file mode 100644 index 0..8b9a6f529c326 --- /dev/null +++ b/clang/test/Driver/unsupported-target-K.c @@ -0,0 +1,8 @@ +// Check powerpc64-unknown-linux-gnu. -K not supported. +// RUN: %clang %s 2>&1 -### \ +// RUN:--target=powerpc64-unknown-linux-gnu \ +// RUN:--sysroot %S/Inputs/aix_ppc_tree \ +// RUN:--unwindlib=libunwind \ +// RUN:-K \ +// RUN: | FileCheck --check-prefixes=CHECK-K-SUPPORT %s +// CHECK-K-SUPPORT: clang: error: unsupported option '-K' for target 'powerpc64-unknown-linux-gnu' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits