From 89414b384a0004c698244cc675f49d0669bb3463 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 12 Nov 2010 03:00:39 +0000 Subject: [PATCH] Add support for -nostdlib in the linux toolchain. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118878 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 104 ++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1addf4703b..954ec8d723 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3255,20 +3255,21 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); - if (!Args.hasArg(options::OPT_shared)) - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o"))); - - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); + if (!Args.hasArg(options::OPT_nostdlib)) { + if (!Args.hasArg(options::OPT_shared)) + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o"))); - const char *crtbegin; - if (Args.hasArg(options::OPT_static)) - crtbegin = "crtbeginT.o"; - else if (Args.hasArg(options::OPT_shared)) - crtbegin = "crtbeginS.o"; - else - crtbegin = "crtbegin.o"; + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); + const char *crtbegin; + if (Args.hasArg(options::OPT_static)) + crtbegin = "crtbeginT.o"; + else if (Args.hasArg(options::OPT_shared)) + crtbegin = "crtbeginS.o"; + else + crtbegin = "crtbegin.o"; + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); + } Args.AddAllArgs(CmdArgs, options::OPT_L); @@ -3283,7 +3284,7 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); - if (D.CCCIsCXX) { + if (D.CCCIsCXX && !Args.hasArg(options::OPT_nostdlib)) { ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } @@ -3291,52 +3292,55 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--start-group"); - if (!D.CCCIsCXX) - CmdArgs.push_back("-lgcc"); - - if (Args.hasArg(options::OPT_static)) { - if (D.CCCIsCXX) - CmdArgs.push_back("-lgcc"); - } else { + if (!Args.hasArg(options::OPT_nostdlib)) { if (!D.CCCIsCXX) - CmdArgs.push_back("--as-needed"); - CmdArgs.push_back("-lgcc_s"); - if (!D.CCCIsCXX) - CmdArgs.push_back("--no-as-needed"); - } + CmdArgs.push_back("-lgcc"); - if (Args.hasArg(options::OPT_static)) - CmdArgs.push_back("-lgcc_eh"); - else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) - CmdArgs.push_back("-lgcc"); + if (Args.hasArg(options::OPT_static)) { + if (D.CCCIsCXX) + CmdArgs.push_back("-lgcc"); + } else { + if (!D.CCCIsCXX) + CmdArgs.push_back("--as-needed"); + CmdArgs.push_back("-lgcc_s"); + if (!D.CCCIsCXX) + CmdArgs.push_back("--no-as-needed"); + } - if (Args.hasArg(options::OPT_pthread) || Args.hasArg(options::OPT_pthreads)) - CmdArgs.push_back("-lpthread"); + if (Args.hasArg(options::OPT_static)) + CmdArgs.push_back("-lgcc_eh"); + else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) + CmdArgs.push_back("-lgcc"); - CmdArgs.push_back("-lc"); + if (Args.hasArg(options::OPT_pthread) || + Args.hasArg(options::OPT_pthreads)) + CmdArgs.push_back("-lpthread"); - if (Args.hasArg(options::OPT_static)) - CmdArgs.push_back("--end-group"); - else { - if (!D.CCCIsCXX) - CmdArgs.push_back("-lgcc"); + CmdArgs.push_back("-lc"); - if (!D.CCCIsCXX) - CmdArgs.push_back("--as-needed"); - CmdArgs.push_back("-lgcc_s"); - if (!D.CCCIsCXX) - CmdArgs.push_back("--no-as-needed"); + if (Args.hasArg(options::OPT_static)) + CmdArgs.push_back("--end-group"); + else { + if (!D.CCCIsCXX) + CmdArgs.push_back("-lgcc"); - if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) - CmdArgs.push_back("-lgcc"); - } + if (!D.CCCIsCXX) + CmdArgs.push_back("--as-needed"); + CmdArgs.push_back("-lgcc_s"); + if (!D.CCCIsCXX) + CmdArgs.push_back("--no-as-needed"); - if (Args.hasArg(options::OPT_shared)) - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); - else - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); + if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) + CmdArgs.push_back("-lgcc"); + } - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); + if (Args.hasArg(options::OPT_shared)) + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); + else + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); + + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); + } if (Args.hasArg(options::OPT_use_gold_plugin)) { CmdArgs.push_back("-plugin"); -- 2.40.0