On FreeBSD, the arch in the arch-vendor-os triple is usually 'amd64'
instead of 'x86_64', e.g. amd64-unknown-freebsd9.0.

If somebody uses such a triple, the code in Clang::AddX86TargetArgs()
does not recognize the arch, so the default CPU name is not set to
x86-64, and interesting things can then happen.

In my case, clang assumed an incorrect 16-byte alignment for some global
structs, and started accessing them with SSE movaps instructions,
leading to bus errors at runtime, because the structs were really 8-byte
aligned.

I would like to propose the attached patch, which makes clang recognize
both 'amd64' and 'x86_64', at least for FreeBSD.  Maybe this can also be
used for other operating systems, if that is desirable.
Index: tools/clang/lib/Driver/Tools.cpp
===================================================================
--- tools/clang/lib/Driver/Tools.cpp    (revision 131958)
+++ tools/clang/lib/Driver/Tools.cpp    (working copy)
@@ -777,7 +777,8 @@ void Clang::AddX86TargetArgs(const ArgList &Args,
       else if (getToolChain().getArchName() == "i386")
         CPUName = "i486";
     } else if (getToolChain().getOS().startswith("freebsd"))  {
-      if (getToolChain().getArchName() == "x86_64")
+      if (getToolChain().getArchName() == "amd64" ||
+          getToolChain().getArchName() == "x86_64")
         CPUName = "x86-64";
       else if (getToolChain().getArchName() == "i386")
         CPUName = "i486";
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to