diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -150,7 +150,8 @@ ///< generates a 'patchable-function' attribute. CODEGENOPT(JMCInstrument, 1, 0) ///< Set when -fjmc is enabled. -CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled. +CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -p is enabled. +CODEGENOPT(InstrumentForProfilingGraph , 1, 0) ///< Set when -pg is enabled. CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled. CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled. CODEGENOPT(RecordMCount , 1, 0) ///< Set when -mrecord-mcount is enabled. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4094,8 +4094,10 @@ MarshallingInfoFlag>; def pedantic : Flag<["-", "--"], "pedantic">, Group, Flags<[CC1Option,FlangOption,FC1Option]>, HelpText<"Warn on language extensions">, MarshallingInfoFlag>; -def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>, +def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>, MarshallingInfoFlag>; +def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>, + MarshallingInfoFlag>; def pipe : Flag<["-", "--"], "pipe">, HelpText<"Use pipes between commands, when possible">; def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">; @@ -4140,7 +4142,6 @@ 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/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -923,7 +923,8 @@ if (CodeGenOpts.InstrumentFunctions || CodeGenOpts.InstrumentFunctionEntryBare || CodeGenOpts.InstrumentFunctionsAfterInlining || - CodeGenOpts.InstrumentForProfiling) { + CodeGenOpts.InstrumentForProfiling || + CodeGenOpts.InstrumentForProfilingGraph) { PB.registerPipelineStartEPCallback( [](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(createModuleToFunctionPassAdaptor( diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1043,7 +1043,8 @@ // inlining, we just add an attribute to insert a mcount call in backend. // The attribute "counting-function" is set to mcount function name which is // architecture dependent. - if (CGM.getCodeGenOpts().InstrumentForProfiling) { + if (CGM.getCodeGenOpts().InstrumentForProfiling || + CGM.getCodeGenOpts().InstrumentForProfilingGraph) { // Calls to fentry/mcount should not be generated if function has // the no_instrument_function attribute. if (!CurFuncDecl || !CurFuncDecl->hasAttr()) { diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -250,6 +250,13 @@ CmdArgs.push_back("-lm"); CmdArgs.push_back("-lc"); + + 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) + + "/usr/lib/profiled")); + } } const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -521,7 +521,8 @@ static bool useFramePointerForTargetByDefault(const ArgList &Args, const llvm::Triple &Triple) { - if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry)) + if (Args.hasArg(options::OPT_p, options::OPT_pg) && + !Args.hasArg(options::OPT_mfentry)) return true; switch (Triple.getArch()) { @@ -6268,6 +6269,7 @@ Args.AddLastArg(CmdArgs, options::OPT_fms_hotpatch); if (TC.SupportsProfiling()) { + Args.AddLastArg(CmdArgs, options::OPT_p); Args.AddLastArg(CmdArgs, options::OPT_pg); llvm::Triple::ArchType Arch = TC.getArch(); @@ -7388,7 +7390,7 @@ C.getJobs().getJobs().back()->PrintInputFilenames = true; } - if (Arg *A = Args.getLastArg(options::OPT_pg)) + if (Arg *A = Args.getLastArg(options::OPT_p, options::OPT_pg)) if (FPKeepKind == CodeGenOptions::FramePointerKind::None && !Args.hasArg(options::OPT_mfentry)) D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -498,7 +498,7 @@ if (!isAndroid && !IsIAMCU) { const char *crt1 = nullptr; if (!Args.hasArg(options::OPT_shared)) { - if (Args.hasArg(options::OPT_pg)) + if (Args.hasArg(options::OPT_p, options::OPT_pg)) crt1 = "gcrt1.o"; else if (IsPIE) crt1 = "Scrt1.o"; diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c --- 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 \ diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1572,6 +1572,13 @@ // CHECK-CRTFASTMATH: usr/lib/gcc/x86_64-unknown-linux/10.2.0{{/|\\\\}}crtfastmath.o // CHECK-NOCRTFASTMATH-NOT: crtfastmath.o +// Check that we link in gcrt1.o when compiling with -p +// RUN: %clang -p --target=x86_64-unknown-linux -no-pie -### %s \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>& 1 \ +// RUN: | FileCheck --check-prefix=CHECK-P %s +// CHECK-P: gcrt1.o + // Check that we link in gcrt1.o when compiling with -pg // RUN: %clang -pg --target=x86_64-unknown-linux -no-pie -### %s \ // RUN: --gcc-toolchain="" \