From: Alex Lorenz Date: Fri, 26 Jun 2020 22:33:56 +0000 (-0700) Subject: [darwin][driver] NFC, split addStartObjectFileArgs into multiple functions X-Git-Tag: llvmorg-12-init~1726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b00cacb2835d11cab6f71466604b7b1bdd46a8d;p=platform%2Fupstream%2Fllvm.git [darwin][driver] NFC, split addStartObjectFileArgs into multiple functions --- diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 3655948..47bf036 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -2574,98 +2574,102 @@ void Darwin::addPlatformVersionArgs(const llvm::opt::ArgList &Args, } } -void Darwin::addStartObjectFileArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { - // Derived from startfile spec. - if (Args.hasArg(options::OPT_dynamiclib)) { - // Derived from darwin_dylib1 spec. - if (isTargetWatchOSBased()) { - ; // watchOS does not need dylib1.o. - } else if (isTargetIOSSimulator()) { - ; // iOS simulator does not need dylib1.o. - } else if (isTargetIPhoneOS()) { - if (isIPhoneOSVersionLT(3, 1)) - CmdArgs.push_back("-ldylib1.o"); +// Add additional link args for the -dynamiclib option. +static void addDynamicLibLinkArgs(const Darwin &D, const ArgList &Args, + ArgStringList &CmdArgs) { + // Derived from darwin_dylib1 spec. + if (D.isTargetIPhoneOS()) { + if (D.isIPhoneOSVersionLT(3, 1)) + CmdArgs.push_back("-ldylib1.o"); + return; + } + + if (!D.isTargetMacOS()) + return; + if (D.isMacosxVersionLT(10, 5)) + CmdArgs.push_back("-ldylib1.o"); + else if (D.isMacosxVersionLT(10, 6)) + CmdArgs.push_back("-ldylib1.10.5.o"); +} + +// Add additional link args for the -bundle option. +static void addBundleLinkArgs(const Darwin &D, const ArgList &Args, + ArgStringList &CmdArgs) { + if (Args.hasArg(options::OPT_static)) + return; + // Derived from darwin_bundle1 spec. + if ((D.isTargetIPhoneOS() && D.isIPhoneOSVersionLT(3, 1)) || + (D.isTargetMacOS() && D.isMacosxVersionLT(10, 6))) + CmdArgs.push_back("-lbundle1.o"); +} + +// Add additional link args for the -pg option. +static void addPgProfilingLinkArgs(const Darwin &D, const ArgList &Args, + ArgStringList &CmdArgs) { + if (D.isTargetMacOS() && D.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 { - if (isMacosxVersionLT(10, 5)) - CmdArgs.push_back("-ldylib1.o"); - else if (isMacosxVersionLT(10, 6)) - CmdArgs.push_back("-ldylib1.10.5.o"); + CmdArgs.push_back("-lgcrt1.o"); + + // 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 (!D.isMacosxVersionLT(10, 8)) + CmdArgs.push_back("-no_new_main"); } else { - if (Args.hasArg(options::OPT_bundle)) { - if (!Args.hasArg(options::OPT_static)) { - // Derived from darwin_bundle1 spec. - if (isTargetWatchOSBased()) { - ; // watchOS does not need bundle1.o. - } else if (isTargetIOSSimulator()) { - ; // iOS simulator does not need bundle1.o. - } else if (isTargetIPhoneOS()) { - if (isIPhoneOSVersionLT(3, 1)) - CmdArgs.push_back("-lbundle1.o"); - } else { - if (isMacosxVersionLT(10, 6)) - CmdArgs.push_back("-lbundle1.o"); - } - } - } else { - if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { - 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. - } - // 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(); - } - } else { - if (Args.hasArg(options::OPT_static) || - Args.hasArg(options::OPT_object) || - Args.hasArg(options::OPT_preload)) { - CmdArgs.push_back("-lcrt0.o"); - } else { - // Derived from darwin_crt1 spec. - if (isTargetWatchOSBased()) { - ; // watchOS does not need crt1.o. - } else if (isTargetIOSSimulator()) { - ; // iOS simulator does not need crt1.o. - } else if (isTargetIPhoneOS()) { - if (getArch() == llvm::Triple::aarch64) - ; // iOS does not need any crt1 files for arm64 - else if (isIPhoneOSVersionLT(3, 1)) - CmdArgs.push_back("-lcrt1.o"); - else if (isIPhoneOSVersionLT(6, 0)) - CmdArgs.push_back("-lcrt1.3.1.o"); - } else { - if (isMacosxVersionLT(10, 5)) - CmdArgs.push_back("-lcrt1.o"); - else if (isMacosxVersionLT(10, 6)) - CmdArgs.push_back("-lcrt1.10.5.o"); - else if (isMacosxVersionLT(10, 8)) - CmdArgs.push_back("-lcrt1.10.6.o"); - - // darwin_crt2 spec is empty. - } - } - } - } + D.getDriver().Diag(diag::err_drv_clang_unsupported_opt_pg_darwin) + << D.isTargetMacOS(); + } +} + +static void addDefaultCRTLinkArgs(const Darwin &D, const ArgList &Args, + ArgStringList &CmdArgs) { + // Derived from darwin_crt1 spec. + if (D.isTargetIPhoneOS()) { + if (D.getArch() == llvm::Triple::aarch64) + ; // iOS does not need any crt1 files for arm64 + else if (D.isIPhoneOSVersionLT(3, 1)) + CmdArgs.push_back("-lcrt1.o"); + else if (D.isIPhoneOSVersionLT(6, 0)) + CmdArgs.push_back("-lcrt1.3.1.o"); + return; } - if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && - !isTargetWatchOS() && isMacosxVersionLT(10, 5)) { + if (!D.isTargetMacOS()) + return; + if (D.isMacosxVersionLT(10, 5)) + CmdArgs.push_back("-lcrt1.o"); + else if (D.isMacosxVersionLT(10, 6)) + CmdArgs.push_back("-lcrt1.10.5.o"); + else if (D.isMacosxVersionLT(10, 8)) + CmdArgs.push_back("-lcrt1.10.6.o"); + // darwin_crt2 spec is empty. +} + +void Darwin::addStartObjectFileArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + // Derived from startfile spec. + if (Args.hasArg(options::OPT_dynamiclib)) + addDynamicLibLinkArgs(*this, Args, CmdArgs); + else if (Args.hasArg(options::OPT_bundle)) + addBundleLinkArgs(*this, Args, CmdArgs); + else if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) + addPgProfilingLinkArgs(*this, Args, CmdArgs); + else if (Args.hasArg(options::OPT_static) || + Args.hasArg(options::OPT_object) || + Args.hasArg(options::OPT_preload)) + CmdArgs.push_back("-lcrt0.o"); + else + addDefaultCRTLinkArgs(*this, Args, CmdArgs); + + if (isTargetMacOS() && Args.hasArg(options::OPT_shared_libgcc) && + isMacosxVersionLT(10, 5)) { const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); CmdArgs.push_back(Str); } diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h index e6f2beb..4384559 100644 --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -357,6 +357,7 @@ protected: const_cast(this)->setTripleEnvironment(llvm::Triple::Simulator); } +public: bool isTargetIPhoneOS() const { assert(TargetInitialized && "Target not initialized!"); return (TargetPlatform == IPhoneOS || TargetPlatform == TvOS) && @@ -438,6 +439,7 @@ protected: return TargetVersion < VersionTuple(V0, V1, V2); } +protected: /// Return true if c++17 aligned allocation/deallocation functions are not /// implemented in the c++ standard library of the deployment target we are /// targeting.