Hi,

Here are two patches to slightly adjust the flags passed to the linker
in FreeBSD.

The first patch (freebsd-link-flags-1.diff) only enables the
--hash-style=both and --enable-new-dtags flags when we're not statically
linking, similar to what FreeBSD's gcc does.  Also, it only enables the
--hash-style=both flag for the architectures that actually support it.

The second patch silences warnings about unused -g, -emit-llvm or -w
flags when linking, similar to the fix that was done for Linux in PR
8611.  It also corrects a pasto in the comment in
linuxtools::Link::ConstructJob() about this.
Index: tools/clang/lib/Driver/Tools.cpp
===================================================================
--- tools/clang/lib/Driver/Tools.cpp	(revision 160886)
+++ tools/clang/lib/Driver/Tools.cpp	(working copy)
@@ -5003,8 +5003,6 @@ void freebsd::Link::ConstructJob(Compilation &C, c
                                  const char *LinkingOutput) const {
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
-  CmdArgs.push_back("--hash-style=both");
-  CmdArgs.push_back("--enable-new-dtags");
 
   if (!D.SysRoot.empty())
     CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
@@ -5021,6 +5019,11 @@ void freebsd::Link::ConstructJob(Compilation &C, c
       CmdArgs.push_back("-dynamic-linker");
       CmdArgs.push_back("/libexec/ld-elf.so.1");
     }
+    llvm::Triple::ArchType Arch = getToolChain().getArch();
+    if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc ||
+        Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
+      CmdArgs.push_back("--hash-style=both");
+    CmdArgs.push_back("--enable-new-dtags");
   }
 
   // When building 32-bit code on FreeBSD/amd64, we have to explicitly
Index: tools/clang/lib/Driver/Tools.cpp
===================================================================
--- tools/clang/lib/Driver/Tools.cpp	(revision 160886)
+++ tools/clang/lib/Driver/Tools.cpp	(working copy)
@@ -5004,6 +5004,14 @@ void freebsd::Link::ConstructJob(Compilation &C, c
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
+  // Silence warning for "clang -g foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_g_Group);
+  // and "clang -emit-llvm foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_emit_llvm);
+  // and for "clang -w foo.o -o foo". Other warning options are already
+  // handled somewhere else.
+  Args.ClaimAllArgs(options::OPT_w);
+
   if (!D.SysRoot.empty())
     CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
@@ -5435,7 +5443,7 @@ void linuxtools::Link::ConstructJob(Compilation &C,
   Args.ClaimAllArgs(options::OPT_g_Group);
   // and "clang -emit-llvm foo.o -o foo"
   Args.ClaimAllArgs(options::OPT_emit_llvm);
-  // and for "clang -g foo.o -o foo". Other warning options are already
+  // and for "clang -w foo.o -o foo". Other warning options are already
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to