From: Volodymyr Sapsai Date: Thu, 14 Feb 2019 23:50:44 +0000 (+0000) Subject: [Driver][Darwin] Emit an error when using -pg on OS without support for it. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ec1b61e70ad4c91669694b4bf5ab297dfc063ce;p=clang [Driver][Darwin] Emit an error when using -pg on OS without support for it. Instead of letting a program fail at runtime, emit an error during compilation. rdar://problem/12206955 Reviewers: dexonsmith, bob.wilson, steven_wu Reviewed By: steven_wu Subscribers: jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D57991 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354084 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 189e0565a8..3ebd931f48 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -96,6 +96,8 @@ def err_drv_clang_unsupported : Error< "the clang compiler does not support '%0'">; def err_drv_clang_unsupported_opt_cxx_darwin_i386 : Error< "the clang compiler does not support '%0' for C++ on Darwin/i386">; +def err_drv_clang_unsupported_opt_pg_darwin: Error< + "the clang compiler does not support -pg option on %select{Darwin|versions of OS X 10.9 and later}0">; def err_drv_clang_unsupported_opt_faltivec : Error< "the clang compiler does not support '%0', %1">; def err_drv_command_failed : Error< diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 582f3f9c4a..9b3f3740fd 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -2289,22 +2289,27 @@ void Darwin::addStartObjectFileArgs(const ArgList &Args, } } else { if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { - if (Args.hasArg(options::OPT_static) || - Args.hasArg(options::OPT_object) || - Args.hasArg(options::OPT_preload)) { - CmdArgs.push_back("-lgcrt0.o"); - } else { - CmdArgs.push_back("-lgcrt1.o"); + if (isTargetMacOS() && isMacosxVersionLT(10, 9)) { + if (Args.hasArg(options::OPT_static) || + Args.hasArg(options::OPT_object) || + Args.hasArg(options::OPT_preload)) { + CmdArgs.push_back("-lgcrt0.o"); + } else { + CmdArgs.push_back("-lgcrt1.o"); - // darwin_crt2 spec is empty. + // darwin_crt2 spec is empty. + } + // By default on OS X 10.8 and later, we don't link with a crt1.o + // file and the linker knows to use _main as the entry point. But, + // when compiling with -pg, we need to link with the gcrt1.o file, + // so pass the -no_new_main option to tell the linker to use the + // "start" symbol as the entry point. + if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) + CmdArgs.push_back("-no_new_main"); + } else { + getDriver().Diag(diag::err_drv_clang_unsupported_opt_pg_darwin) + << isTargetMacOS(); } - // By default on OS X 10.8 and later, we don't link with a crt1.o - // file and the linker knows to use _main as the entry point. But, - // when compiling with -pg, we need to link with the gcrt1.o file, - // so pass the -no_new_main option to tell the linker to use the - // "start" symbol as the entry point. - if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) - CmdArgs.push_back("-no_new_main"); } else { if (Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_object) || diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index 5198ef057b..181d4e324c 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -203,6 +203,14 @@ // LINK_PG: -lgcrt1.o // LINK_PG: -no_new_main +// RUN: %clang -target i386-apple-darwin13 -pg -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK_PG_NO_SUPPORT_OSX %s < %t.log +// LINK_PG_NO_SUPPORT_OSX: error: the clang compiler does not support -pg option on versions of OS X + +// RUN: %clang -target x86_64-apple-ios5.0 -pg -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK_PG_NO_SUPPORT %s < %t.log +// LINK_PG_NO_SUPPORT: error: the clang compiler does not support -pg option on Darwin + // Check that clang links with libgcc_s.1 for iOS 4 and earlier, but not arm64. // RUN: %clang -target armv7-apple-ios4.0 -miphoneos-version-min=4.0 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_IOS_LIBGCC_S %s < %t.log