Index: lib/Driver/ToolChains/Ananas.cpp =================================================================== --- lib/Driver/ToolChains/Ananas.cpp +++ lib/Driver/ToolChains/Ananas.cpp @@ -64,8 +64,19 @@ if (!D.SysRoot.empty()) CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); - // Ananas only supports static linkage for now. - CmdArgs.push_back("-Bstatic"); + if (Args.hasArg(options::OPT_static)) { + CmdArgs.push_back("-Bstatic"); + } else { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); + if (Args.hasArg(options::OPT_shared)) { + CmdArgs.push_back("-Bshareable"); + } else { + Args.AddAllArgs(CmdArgs, options::OPT_pie); + CmdArgs.push_back("-dynamic-linker"); + CmdArgs.push_back("/lib/ld-ananas.so"); + } + } if (Output.isFilename()) { CmdArgs.push_back("-o"); @@ -75,9 +86,15 @@ } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); + if (!Args.hasArg(options::OPT_shared)) { + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); + } CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o"))); + if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) { + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o"))); + } else { + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o"))); + } } Args.AddAllArgs(CmdArgs, options::OPT_L); @@ -97,7 +114,10 @@ CmdArgs.push_back("-lc"); if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); + if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) + 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"))); } Index: test/Driver/ananas.c =================================================================== --- test/Driver/ananas.c +++ test/Driver/ananas.c @@ -7,3 +7,11 @@ // CHECK-STATIC: crtbegin.o // CHECK-STATIC: crtend.o // CHECK-STATIC: crtn.o + +// RUN: %clang -no-canonical-prefixes -target x86_64-unknown-ananas -shared %s \ +// RUN: --sysroot=%S/Inputs/ananas-tree -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-SHARED %s +// CHECK-SHARED: crti.o +// CHECK-SHARED: crtbeginS.o +// CHECK-SHARED: crtendS.o +// CHECK-SHARED: crtn.o