On Fri, Mar 18, 2011 at 02:51:01AM +0100, Joerg Sonnenberger wrote:
> On Thu, Mar 17, 2011 at 11:11:01PM +0100, Joerg Sonnenberger wrote:
> > I would expect a sane cross-compiling setup for other platforms to be
> > quite similar. With some additional changes to make the look up for
> > crt0.o and libgcc honour --sysroot, all that is needed for
> > cross-compiliation is using "clang -ccc-host-triple i486--netbsdelf
> > --sysroot $DESTDIR" or adding a symlink and using "i486--netbsdelf-clang
> > --sysroot $DESTDIR".
> 
> Attached patch implements the missing parts of --sysroot. I'm not
> completely happy of moving it to driver, but I wouldn't find an easier
> way to get to the command line arguments early enough.
> 
> Again, other platforms likely want to have the same changes.

Better version. This makes -B =/foobar work as side effect.

Note the --sysroot invocation for linuxtools::Link::ConstructJob should
be checked. At least the version of ld I have doesn't allow
"--sysroot /foo", but requires "--sysroot=/foo" (without error).

Joerg
Index: include/clang/Driver/Driver.h
===================================================================
--- include/clang/Driver/Driver.h	(revision 127752)
+++ include/clang/Driver/Driver.h	(working copy)
@@ -77,6 +77,12 @@
   typedef llvm::SmallVector<std::string, 4> prefix_list;
   prefix_list PrefixDirs;
 
+  /// sysroot, if present
+  std::string SysRoot;
+
+  /// If the standard library is used
+  bool UseStdLib;
+
   /// Default host triple.
   std::string DefaultHostTriple;
 
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 127752)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -3417,6 +3428,10 @@
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
+  if (!D.SysRoot.empty()) {
+    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  }
+
   if (Args.hasArg(options::OPT_static)) {
     CmdArgs.push_back("-Bstatic");
   } else {
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp	(revision 127752)
+++ lib/Driver/ToolChains.cpp	(working copy)
@@ -1159,12 +1159,11 @@
         llvm::Triple::x86_64)
     Lib32 = true;
 
-  getProgramPaths().push_back(getDriver().Dir + "/../libexec");
-  getProgramPaths().push_back("/usr/libexec");
-  if (Lib32) {
-    getFilePaths().push_back("/usr/lib/i386");
-  } else {
-    getFilePaths().push_back("/usr/lib");
+  if (getDriver().UseStdLib) {
+    if (Lib32)
+      getFilePaths().push_back("=/usr/lib/i386");
+    else
+      getFilePaths().push_back("=/usr/lib");
   }
 }
 
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp	(revision 127769)
+++ lib/Driver/Driver.cpp	(working copy)
@@ -58,8 +58,8 @@
                bool IsProduction, bool CXXIsProduction,
                Diagnostic &_Diags)
   : Opts(createDriverOptTable()), Diags(_Diags),
-    ClangExecutable(_ClangExecutable), DefaultHostTriple(_DefaultHostTriple),
-    DefaultImageName(_DefaultImageName),
+    ClangExecutable(_ClangExecutable), UseStdLib(true),
+    DefaultHostTriple(_DefaultHostTriple), DefaultImageName(_DefaultImageName),
     DriverTitle("clang \"gcc-compatible\" driver"),
     Host(0),
     CCPrintOptionsFilename(0), CCPrintHeadersFilename(0), CCCIsCXX(false),
@@ -287,6 +287,10 @@
     A->claim();
     PrefixDirs.push_back(A->getValue(*Args, 0));
   }
+  if (const Arg *A = Args->getLastArg(options::OPT__sysroot_EQ))
+    SysRoot = A->getValue(*Args);
+  if (Args->hasArg(options::OPT_nostdlib))
+    UseStdLib = false;
 
   Host = GetHostInfo(DefaultHostTriple.c_str());
 
@@ -1258,7 +1262,12 @@
   // attempting to use this prefix when lokup up program paths.
   for (Driver::prefix_list::const_iterator it = PrefixDirs.begin(),
        ie = PrefixDirs.end(); it != ie; ++it) {
-    llvm::sys::Path P(*it);
+    std::string Dir(*it);
+    if (Dir.empty())
+      continue;
+    if (Dir[0] == '=')
+      Dir = SysRoot + Dir.substr(1);
+    llvm::sys::Path P(Dir);
     P.appendComponent(Name);
     bool Exists;
     if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
@@ -1268,7 +1277,12 @@
   const ToolChain::path_list &List = TC.getFilePaths();
   for (ToolChain::path_list::const_iterator
          it = List.begin(), ie = List.end(); it != ie; ++it) {
-    llvm::sys::Path P(*it);
+    std::string Dir(*it);
+    if (Dir.empty())
+      continue;
+    if (Dir[0] == '=')
+      Dir = SysRoot + Dir.substr(1);
+    llvm::sys::Path P(Dir);
     P.appendComponent(Name);
     bool Exists;
     if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to