[cfe-dev] [PATCH]: add support for FreeBSD
Roman Divacky
rdivacky at freebsd.org
Tue Oct 14 00:20:41 PDT 2008
> >+ Define(Defs, "__FreeBSD_cc_version", "800001");
> >
> >right?
> >
> >the problem is that the second number is defined only in an internal
> >freebsd
> >header file or can be obtained via "gcc -E -dM dummy_file.c", the
> >__FreeBSD_cc_version
> >does not correspond to anything in uname.
>
> Ok, but what *is* that number and how does it get used? For example,
> we always currently hardcode these values:
>
> DefineBuiltinMacro(Buf, "__GNUC_MINOR__=2");
> DefineBuiltinMacro(Buf, "__GNUC_PATCHLEVEL__=1");
> DefineBuiltinMacro(Buf, "__GNUC__=4");
>
> this is us claiming to be 4.2.1. In my mind, this is ok because code
> checking these is really almost always doing a feature check on some
> thing that 4.2.1 supports, and we plan to eventually support most of
> these.
>
> Is __FreeBSD_cc_version like this? When does it change? What other
> values has it been over time? Is it always just '__FreeBSD__ +
> "00001"'?
I think you are right.... the __FreeBSD_cc_version is used to denote
what gcc is used on a given FreeBSD. I believe we can easily pretend
it's always X00001 where X is the FreeBSD major number. do you like this
patch? I could not test it but it should be ok...
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp (revision 57424)
+++ lib/Basic/Targets.cpp (working copy)
@@ -17,6 +17,9 @@
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/APFloat.h"
+#ifdef __FreeBSD__
+#include <sys/utsname.h>
+#endif
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -42,6 +45,26 @@
Define(Defs, "__SOLARIS__");
}
+static void getFreeBSDDefines(std::vector<char> &Defs, bool is64Bit) {
+ // FreeBSD defines; list based off of gcc output
+ struct utsname name;
+
+ uname(&name);
+ char release[] = "X";
+ release[0] = name.release[0];
+ char version[] = "X00001";
+ version[0] = name.release[0];
+
+ Define(Defs, "__FreeBSD__", release);
+ Define(Defs, "__FreeBSD_cc_version", version);
+ Define(Defs, "__KPRINTF_ATTRIBUTE__");
+ Define(Defs, "unix");
+ Define(Defs, "bsd");
+ if (is64Bit) {
+ Define(Defs, "__LP64__");
+ }
+}
+
static void getDragonFlyDefines(std::vector<char> &Defs) {
// DragonFly defines; list based off of gcc output
Define(Defs, "__DragonFly__");
@@ -509,6 +532,19 @@
} // end anonymous namespace
namespace {
+// x86-32 FreeBSD target
+class FreeBSDX86_32TargetInfo : public X86_32TargetInfo {
+public:
+ FreeBSDX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) {
+ }
+ virtual void getTargetDefines(std::vector<char> &Defines) const {
+ X86_32TargetInfo::getTargetDefines(Defines);
+ getFreeBSDDefines(Defines, 0);
+ }
+};
+} // end anonymous namespace
+
+namespace {
// x86-32 DragonFly target
class DragonFlyX86_32TargetInfo : public X86_32TargetInfo {
public:
@@ -588,6 +624,19 @@
} // end anonymous namespace
namespace {
+// x86-64 FreeBSD target
+class FreeBSDX86_64TargetInfo : public X86_64TargetInfo {
+public:
+ FreeBSDX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) {
+ }
+ virtual void getTargetDefines(std::vector<char> &Defines) const {
+ X86_64TargetInfo::getTargetDefines(Defines);
+ getFreeBSDDefines(Defines, 1);
+ }
+};
+} // end anonymous namespace
+
+namespace {
// x86-64 Linux target
class LinuxX86_64TargetInfo : public X86_64TargetInfo {
public:
@@ -798,6 +847,7 @@
// Additions and corrections are welcome.
bool isDarwin = T.find("-darwin") != std::string::npos;
bool isDragonFly = T.find("-dragonfly") != std::string::npos;
+ bool isFreeBSD = T.find("-freebsd") != std::string::npos;
bool isSolaris = T.find("-solaris") != std::string::npos;
bool isLinux = T.find("-linux") != std::string::npos;
bool isWindows = T.find("-windows") != std::string::npos ||
@@ -833,6 +883,8 @@
return new DarwinX86_64TargetInfo(T);
if (isLinux)
return new LinuxX86_64TargetInfo(T);
+ if (isFreeBSD)
+ return new FreeBSDX86_64TargetInfo(T);
return new X86_64TargetInfo(T);
}
@@ -846,6 +898,8 @@
return new LinuxX86_32TargetInfo(T);
if (isDragonFly)
return new DragonFlyX86_32TargetInfo(T);
+ if (isFreeBSD)
+ return new FreeBSDX86_32TargetInfo(T);
if (isWindows)
return new WindowsX86_32TargetInfo(T);
return new X86_32TargetInfo(T);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081014/0c8396e0/attachment.sig>
More information about the cfe-dev
mailing list