r322064 - ananas: Add shared library support

Ed Schouten via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 01:18:14 PST 2018


Author: ed
Date: Tue Jan  9 01:18:14 2018
New Revision: 322064

URL: http://llvm.org/viewvc/llvm-project?rev=322064&view=rev
Log:
ananas: Add shared library support

The Ananas Operating System (https://github.com/zhmu/ananas) has shared
library support as of commit 57739c0b6ece56dd4872aedf30264ed4b9412c77.

This change adds the necessary settings to clang so that shared
executables and libraries can be build correctly.

Submitted by:	Rink Springer
Differential Revision:	https://reviews.llvm.org/D41500

Modified:
    cfe/trunk/lib/Driver/ToolChains/Ananas.cpp
    cfe/trunk/test/Driver/ananas.c

Modified: cfe/trunk/lib/Driver/ToolChains/Ananas.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Ananas.cpp?rev=322064&r1=322063&r2=322064&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Ananas.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Ananas.cpp Tue Jan  9 01:18:14 2018
@@ -64,8 +64,19 @@ void ananas::Linker::ConstructJob(Compil
   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 @@ void ananas::Linker::ConstructJob(Compil
   }
 
   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 @@ void ananas::Linker::ConstructJob(Compil
     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")));
   }
 

Modified: cfe/trunk/test/Driver/ananas.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ananas.c?rev=322064&r1=322063&r2=322064&view=diff
==============================================================================
--- cfe/trunk/test/Driver/ananas.c (original)
+++ cfe/trunk/test/Driver/ananas.c Tue Jan  9 01:18:14 2018
@@ -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




More information about the cfe-commits mailing list