Author: kamil Date: Thu Feb 15 06:12:21 2018 New Revision: 325238 URL: http://llvm.org/viewvc/llvm-project?rev=325238&view=rev Log: Add Xray instrumentation compile-time/link-time support to FreeBSD
Summary: Similarly to the GNU driver version, adding proper compile and linker flags. Patch by: David CARLIER Reviewers: vitalybuka, krytarowski, dberris Reviewed By: krytarowski, dberris Subscribers: emaste, dberris, cfe-commits Differential Revision: https://reviews.llvm.org/D43279 Modified: cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp Modified: cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp?rev=325238&r1=325237&r2=325238&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp Thu Feb 15 06:12:21 2018 @@ -117,6 +117,30 @@ void freebsd::Assembler::ConstructJob(Co C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); } +static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args, + ArgStringList &CmdArgs) { + if (Args.hasArg(options::OPT_shared)) + return false; + + if (Args.hasFlag(options::OPT_fxray_instrument, + options::OPT_fnoxray_instrument, false)) { + CmdArgs.push_back("-whole-archive"); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, "xray", false)); + CmdArgs.push_back("-no-whole-archive"); + return true; + } + + return false; +} + +static void linkXRayRuntimeDeps(const ToolChain &TC, const ArgList &Args, + ArgStringList &CmdArgs) { + CmdArgs.push_back("--no-as-needed"); + CmdArgs.push_back("-pthread"); + CmdArgs.push_back("-lrt"); + CmdArgs.push_back("-lm"); +} + void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, @@ -235,6 +259,7 @@ void freebsd::Linker::ConstructJob(Compi AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D); bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); + bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { @@ -249,6 +274,8 @@ void freebsd::Linker::ConstructJob(Compi } if (NeedsSanitizerDeps) linkSanitizerRuntimeDeps(ToolChain, CmdArgs); + if (NeedsXRayDeps) + linkXRayRuntimeDeps(ToolChain, Args, CmdArgs); // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding // the default system libraries. Just mimic this for now. if (Args.hasArg(options::OPT_pg)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits