--- tools/clang/include/clang/Analysis/Analyses/FormatString.h.orig 2016-12-15 18:54:00 UTC +++ tools/clang/include/clang/Analysis/Analyses/FormatString.h @@ -177,6 +177,12 @@ public: FreeBSDrArg, FreeBSDyArg, + // BSDSUniX kernel specific specifiers. + BSDSUniXbArg, + BSDSUniXDArg, + BSDSUniXrArg, + BSDSUniXyArg, + // GlibC specific specifiers. PrintErrno, // 'm' @@ -226,7 +232,7 @@ public: void setEndScanList(const char *pos) { EndScanList = pos; } bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) || - kind == FreeBSDrArg || kind == FreeBSDyArg; } + kind == FreeBSDrArg || kind == FreeBSDyArg || kind == BSDSUniXrArg || kind == BSDSUniXyArg; } bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; } bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; } bool isDoubleArg() const { @@ -682,7 +688,7 @@ public: bool ParsePrintfString(FormatStringHandler &H, const char *beg, const char *end, const LangOptions &LO, - const TargetInfo &Target, bool isFreeBSDKPrintf); + const TargetInfo &Target, bool isBSDKPrintf); bool ParseFormatStringHasSArg(const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target); --- tools/clang/include/clang/Sema/Sema.h.orig 2017-02-01 17:13:26 UTC +++ tools/clang/include/clang/Sema/Sema.h @@ -9969,6 +9969,7 @@ public: FST_Strfmon, FST_Kprintf, FST_FreeBSDKPrintf, + FST_BSDSUniXKPrintf, FST_OSTrace, FST_OSLog, FST_Unknown --- tools/clang/lib/Analysis/FormatString.cpp.orig 2016-10-24 20:39:34 UTC +++ tools/clang/lib/Analysis/FormatString.cpp @@ -611,6 +611,12 @@ const char *ConversionSpecifier::toStrin case FreeBSDrArg: return "r"; case FreeBSDyArg: return "y"; + // BSDSUniX kernel specific specifiers. + case BSDSUniXbArg: return "b"; + case BSDSUniXDArg: return "D"; + case BSDSUniXrArg: return "r"; + case BSDSUniXyArg: return "y"; + // GlibC specific specifiers. case PrintErrno: return "m"; @@ -708,7 +714,11 @@ bool FormatSpecifier::hasValidLengthModi return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: + return Target.getTriple().isOSFreeBSD() || + Target.getTriple().isOSBSDSUniX() || + Target.getTriple().isPS4(); default: return false; } @@ -741,7 +751,11 @@ bool FormatSpecifier::hasValidLengthModi return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: + return Target.getTriple().isOSFreeBSD() || + Target.getTriple().isOSBSDSUniX() || + Target.getTriple().isPS4(); default: return false; } @@ -878,6 +892,10 @@ bool FormatSpecifier::hasStandardConvers case ConversionSpecifier::FreeBSDDArg: case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: + case ConversionSpecifier::BSDSUniXbArg: + case ConversionSpecifier::BSDSUniXDArg: + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: case ConversionSpecifier::PrintErrno: case ConversionSpecifier::DArg: case ConversionSpecifier::OArg: --- tools/clang/lib/Analysis/PrintfFormatString.cpp.orig 2016-10-24 20:39:34 UTC +++ tools/clang/lib/Analysis/PrintfFormatString.cpp @@ -74,7 +74,7 @@ static PrintfSpecifierResult ParsePrintf const LangOptions &LO, const TargetInfo &Target, bool Warn, - bool isFreeBSDKPrintf) { + bool isBSDKPrintf) { using namespace clang::analyze_format_string; using namespace clang::analyze_printf; @@ -294,23 +294,43 @@ static PrintfSpecifierResult ParsePrintf case '@': k = ConversionSpecifier::ObjCObjArg; break; // Glibc specific. case 'm': k = ConversionSpecifier::PrintErrno; break; - // FreeBSD kernel specific. + // FreeBSD/BSDSUniX kernel specific. case 'b': - if (isFreeBSDKPrintf) - k = ConversionSpecifier::FreeBSDbArg; // int followed by char * + if (isBSDKPrintf) + { + if (Target.getTriple().isOSFreeBSD()) + k = ConversionSpecifier::FreeBSDbArg; // int followed by char * + else + k = ConversionSpecifier::BSDSUniXbArg; // int followed by char * + } break; case 'r': - if (isFreeBSDKPrintf) - k = ConversionSpecifier::FreeBSDrArg; // int + if (isBSDKPrintf) + { + if (Target.getTriple().isOSFreeBSD()) + k = ConversionSpecifier::FreeBSDrArg; // int + else + k = ConversionSpecifier::BSDSUniXrArg; // int + } break; case 'y': - if (isFreeBSDKPrintf) - k = ConversionSpecifier::FreeBSDyArg; // int + if (isBSDKPrintf) + { + if (Target.getTriple().isOSFreeBSD()) + k = ConversionSpecifier::FreeBSDyArg; // int + else + k = ConversionSpecifier::BSDSUniXyArg; // int + } break; // Apple-specific. case 'D': - if (isFreeBSDKPrintf) - k = ConversionSpecifier::FreeBSDDArg; // void * followed by char * + if (isBSDKPrintf) + { + if (Target.getTriple().isOSFreeBSD()) + k = ConversionSpecifier::FreeBSDDArg; // void * followed by char * + else + k = ConversionSpecifier::BSDSUniXDArg; // void * followed by char * + } else if (Target.getTriple().isOSDarwin()) k = ConversionSpecifier::DArg; break; @@ -343,9 +363,11 @@ static PrintfSpecifierResult ParsePrintf FS.setConversionSpecifier(CS); if (CS.consumesDataArgument() && !FS.usesPositionalArg()) FS.setArgIndex(argIndex++); - // FreeBSD kernel specific. - if (k == ConversionSpecifier::FreeBSDbArg || - k == ConversionSpecifier::FreeBSDDArg) + // FreeBSD/BSDSUniX kernel specific. + if (k == ConversionSpecifier::FreeBSDbArg || + k == ConversionSpecifier::FreeBSDDArg || + k == ConversionSpecifier::BSDSUniXbArg || + k == ConversionSpecifier::BSDSUniXDArg) argIndex++; if (k == ConversionSpecifier::InvalidSpecifier) { @@ -365,7 +387,7 @@ bool clang::analyze_format_string::Parse const char *E, const LangOptions &LO, const TargetInfo &Target, - bool isFreeBSDKPrintf) { + bool isBSDKPrintf) { unsigned argIndex = 0; @@ -373,7 +395,7 @@ bool clang::analyze_format_string::Parse while (I != E) { const PrintfSpecifierResult &FSR = ParsePrintfSpecifier(H, I, E, argIndex, LO, Target, true, - isFreeBSDKPrintf); + isBSDKPrintf); // Did a fail-stop error of any kind occur when parsing the specifier? // If so, don't do any more processing. if (FSR.shouldStop()) @@ -808,6 +830,8 @@ bool PrintfSpecifier::hasValidPlusPrefix case ConversionSpecifier::AArg: case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: return true; default: @@ -835,6 +859,8 @@ bool PrintfSpecifier::hasValidAlternativ case ConversionSpecifier::GArg: case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: return true; default: @@ -867,6 +893,8 @@ bool PrintfSpecifier::hasValidLeadingZer case ConversionSpecifier::GArg: case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: return true; default: @@ -893,6 +921,8 @@ bool PrintfSpecifier::hasValidSpacePrefi case ConversionSpecifier::AArg: case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: return true; default: @@ -960,6 +990,8 @@ bool PrintfSpecifier::hasValidPrecision( case ConversionSpecifier::sArg: case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: + case ConversionSpecifier::BSDSUniXrArg: + case ConversionSpecifier::BSDSUniXyArg: case ConversionSpecifier::PArg: return true; --- tools/clang/lib/Basic/Targets.cpp.orig 2017-04-28 00:36:13 UTC +++ tools/clang/lib/Basic/Targets.cpp @@ -321,6 +321,65 @@ public: } }; +#ifndef BSDSUNIX_CC_VERSION +#define BSDSUNIX_CC_VERSION 0U +#endif + +// BSDSUniX Target +template +class BSDSUniXTargetInfo : public OSTargetInfo { +protected: + void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, + MacroBuilder &Builder) const override { + // BSDSUniX defines; list based off of gcc output + + unsigned Release = Triple.getOSMajorVersion(); + if (Release == 0U) + Release = 8U; + unsigned CCVersion = BSDSUNIX_CC_VERSION; + if (CCVersion == 0U) + CCVersion = Release * 100000U + 1U; + + Builder.defineMacro("__BSDSUniX__", Twine(Release)); + Builder.defineMacro("__BSDSUniX_cc_version", Twine(CCVersion)); + Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); + DefineStd(Builder, "unix", Opts); + Builder.defineMacro("__ELF__"); + + // On BSDSUniX, wchar_t contains the number of the code point as + // used by the character set of the locale. These character sets are + // not necessarily a superset of ASCII. + // + // FIXME: This is wrong; the macro refers to the numerical values + // of wchar_t *literals*, which are not locale-dependent. However, + // BSDSUniX systems apparently depend on us getting this wrong, and + // setting this to 1 is conforming even if all the basic source + // character literals have the same encoding as char and wchar_t. + Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1"); + } +public: + BSDSUniXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) + : OSTargetInfo(Triple, Opts) { + switch (Triple.getArch()) { + default: + case llvm::Triple::x86: + case llvm::Triple::x86_64: + this->MCountName = ".mcount"; + break; + case llvm::Triple::mips: + case llvm::Triple::mipsel: + case llvm::Triple::ppc: + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: + this->MCountName = "_mcount"; + break; + case llvm::Triple::arm: + this->MCountName = "__mcount"; + break; + } + } +}; + #ifndef FREEBSD_CC_VERSION #define FREEBSD_CC_VERSION 0U #endif @@ -1640,6 +1699,7 @@ public: switch (getTriple().getOS()) { case llvm::Triple::Linux: + case llvm::Triple::BSDSUniX: case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: SizeType = UnsignedInt; @@ -1650,7 +1710,8 @@ public: break; } - if (getTriple().getOS() == llvm::Triple::FreeBSD) { + if (getTriple().getOS() == llvm::Triple::FreeBSD || + getTriple().getOS() == llvm::Triple::BSDSUniX) { LongDoubleWidth = LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEdouble(); } @@ -1684,6 +1745,7 @@ public: } switch (getTriple().getOS()) { + case llvm::Triple::BSDSUniX: case llvm::Triple::FreeBSD: LongDoubleWidth = LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEdouble(); @@ -4948,8 +5010,8 @@ class ARMTargetInfo : public TargetInfo else DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32; - // size_t is unsigned int on FreeBSD. - if (T.getOS() == llvm::Triple::FreeBSD) + // size_t is unsigned int on FreeBSD and BSDSUniX. + if (T.getOS() == llvm::Triple::FreeBSD || T.getOS() == llvm::Triple::BSDSUniX) SizeType = UnsignedInt; else SizeType = UnsignedLong; @@ -7530,7 +7592,8 @@ public: void setN32N64ABITypes() { LongDoubleWidth = LongDoubleAlign = 128; LongDoubleFormat = &llvm::APFloat::IEEEquad(); - if (getTriple().getOS() == llvm::Triple::FreeBSD) { + if (getTriple().getOS() == llvm::Triple::FreeBSD || + getTriple().getOS() == llvm::Triple::BSDSUniX) { LongDoubleWidth = LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEdouble(); } @@ -8575,6 +8638,8 @@ static TargetInfo *AllocateTarget(const switch (os) { case llvm::Triple::CloudABI: return new CloudABITargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::Fuchsia: @@ -8591,6 +8656,8 @@ static TargetInfo *AllocateTarget(const case llvm::Triple::aarch64_be: switch (os) { + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::Fuchsia: @@ -8613,6 +8680,8 @@ static TargetInfo *AllocateTarget(const return new CloudABITargetInfo(Triple, Opts); case llvm::Triple::Linux: return new LinuxTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::Fuchsia: @@ -8651,6 +8720,8 @@ static TargetInfo *AllocateTarget(const switch (os) { case llvm::Triple::Linux: return new LinuxTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::Fuchsia: @@ -8684,6 +8755,8 @@ static TargetInfo *AllocateTarget(const return new LinuxTargetInfo(Triple, Opts); case llvm::Triple::RTEMS: return new RTEMSTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::NetBSD: @@ -8698,6 +8771,8 @@ static TargetInfo *AllocateTarget(const return new LinuxTargetInfo(Triple, Opts); case llvm::Triple::RTEMS: return new RTEMSTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::NetBSD: @@ -8714,6 +8789,8 @@ static TargetInfo *AllocateTarget(const return new LinuxTargetInfo(Triple, Opts); case llvm::Triple::RTEMS: return new RTEMSTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::NetBSD: @@ -8730,6 +8807,8 @@ static TargetInfo *AllocateTarget(const return new LinuxTargetInfo(Triple, Opts); case llvm::Triple::RTEMS: return new RTEMSTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::NetBSD: @@ -8757,6 +8836,8 @@ static TargetInfo *AllocateTarget(const switch (os) { case llvm::Triple::Linux: return new LinuxTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::NetBSD: @@ -8777,6 +8858,8 @@ static TargetInfo *AllocateTarget(const return new LinuxTargetInfo(Triple, Opts); case llvm::Triple::Lv2: return new PS3PPUTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::NetBSD: @@ -8845,6 +8928,8 @@ static TargetInfo *AllocateTarget(const return new NetBSDTargetInfo(Triple, Opts); case llvm::Triple::OpenBSD: return new OpenBSDTargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); default: @@ -8888,6 +8973,8 @@ static TargetInfo *AllocateTarget(const return new OpenBSDI386TargetInfo(Triple, Opts); case llvm::Triple::Bitrig: return new BitrigI386TargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::Fuchsia: @@ -8945,6 +9032,8 @@ static TargetInfo *AllocateTarget(const return new OpenBSDX86_64TargetInfo(Triple, Opts); case llvm::Triple::Bitrig: return new BitrigX86_64TargetInfo(Triple, Opts); + case llvm::Triple::BSDSUniX: + return new BSDSUniXTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: return new FreeBSDTargetInfo(Triple, Opts); case llvm::Triple::Fuchsia: --- tools/clang/lib/CodeGen/TargetInfo.cpp.orig 2017-01-05 00:20:51 UTC +++ tools/clang/lib/CodeGen/TargetInfo.cpp @@ -370,8 +370,8 @@ TargetCodeGenInfo::~TargetCodeGenInfo() // It's probably just doomed to be platform-dependent, though. unsigned TargetCodeGenInfo::getSizeOfUnwindException() const { // Verified for: - // x86-64 FreeBSD, Linux, Darwin - // x86-32 FreeBSD, Linux, Darwin + // x86-64 FreeBSD, Linux, Darwin, BSDSUniX + // x86-32 FreeBSD, Linux, Darwin, BSDSUniX // PowerPC Linux, Darwin // ARM Darwin (*not* EABI) // AArch64 Linux @@ -1864,6 +1864,7 @@ bool X86_32TargetCodeGenInfo::isStructRe switch (Triple.getOS()) { case llvm::Triple::DragonFly: + case llvm::Triple::BSDSUniX: case llvm::Triple::FreeBSD: case llvm::Triple::OpenBSD: case llvm::Triple::Bitrig: --- tools/clang/lib/Driver/Driver.cpp.orig 2017-01-05 05:20:27 UTC +++ tools/clang/lib/Driver/Driver.cpp @@ -3685,6 +3685,9 @@ const ToolChain &Driver::getToolChain(co case llvm::Triple::NetBSD: TC = new toolchains::NetBSD(*this, Target, Args); break; + case llvm::Triple::BSDSUniX: + TC = new toolchains::BSDSUniX(*this, Target, Args); + break; case llvm::Triple::FreeBSD: TC = new toolchains::FreeBSD(*this, Target, Args); break; --- tools/clang/lib/Driver/ToolChain.cpp.orig 2016-12-14 16:46:50 UTC +++ tools/clang/lib/Driver/ToolChain.cpp @@ -307,7 +307,7 @@ std::string ToolChain::getCompilerRT(con : (IsITANMSVCWindows ? ".lib" : ".a"); SmallString<128> Path(getDriver().ResourceDir); - StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS(); + StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : Triple.isOSBSDSUniX() ? "bsdsunix" : getOS(); llvm::sys::path::append(Path, "lib", OSLibName); llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" + Arch + Env + Suffix); --- tools/clang/lib/Driver/ToolChains.cpp.orig 2017-01-10 21:13:08 UTC +++ tools/clang/lib/Driver/ToolChains.cpp @@ -3660,6 +3660,93 @@ void Bitrig::AddCXXStdlibLibArgs(const A } } +/// BSDSUniX - BSDSUniX tool chain which can call as(1) and ld(1) directly. + +BSDSUniX::BSDSUniX(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) + : Generic_ELF(D, Triple, Args) { + + // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall + // back to '/usr/lib' if it doesn't exist. + if ((Triple.getArch() == llvm::Triple::x86 || + Triple.getArch() == llvm::Triple::ppc) && + D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) + getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); + else + getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); +} + +ToolChain::CXXStdlibType BSDSUniX::GetDefaultCXXStdlibType() const { + if (getTriple().getOSMajorVersion() >= 10) + return ToolChain::CST_Libcxx; + return ToolChain::CST_Libstdcxx; +} + +void BSDSUniX::addLibStdCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/c++/4.2", "", "", + "", "", DriverArgs, CC1Args); +} + +void BSDSUniX::AddCXXStdlibLibArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + CXXStdlibType Type = GetCXXStdlibType(Args); + bool Profiling = Args.hasArg(options::OPT_pg); + + switch (Type) { + case ToolChain::CST_Libcxx: + CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); + break; + + case ToolChain::CST_Libstdcxx: + CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); + break; + } +} + +Tool *BSDSUniX::buildAssembler() const { + return new tools::freebsd::Assembler(*this); +} + +Tool *BSDSUniX::buildLinker() const { return new tools::freebsd::Linker(*this); } + +bool BSDSUniX::UseSjLjExceptions(const ArgList &Args) const { + // BSDSUniX uses SjLj exceptions on ARM oabi. + switch (getTriple().getEnvironment()) { + case llvm::Triple::GNUEABIHF: + case llvm::Triple::GNUEABI: + case llvm::Triple::EABI: + return false; + + default: + return (getTriple().getArch() == llvm::Triple::arm || + getTriple().getArch() == llvm::Triple::thumb); + } +} + +bool BSDSUniX::HasNativeLLVMSupport() const { return true; } + +bool BSDSUniX::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } + +SanitizerMask BSDSUniX::getSupportedSanitizers() const { + const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; + const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; + const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || + getTriple().getArch() == llvm::Triple::mips64el; + SanitizerMask Res = ToolChain::getSupportedSanitizers(); + Res |= SanitizerKind::Address; + Res |= SanitizerKind::Vptr; + if (IsX86_64 || IsMIPS64) { + Res |= SanitizerKind::Leak; + Res |= SanitizerKind::Thread; + } + if (IsX86 || IsX86_64) { + Res |= SanitizerKind::SafeStack; + } + return Res; +} + /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, --- tools/clang/lib/Driver/ToolChains.h.orig 2017-01-05 16:52:29 UTC +++ tools/clang/lib/Driver/ToolChains.h @@ -788,6 +788,35 @@ protected: Tool *buildLinker() const override; }; +class LLVM_LIBRARY_VISIBILITY BSDSUniX : public Generic_ELF { +public: + BSDSUniX(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args); + bool HasNativeLLVMSupport() const override; + + bool IsMathErrnoDefault() const override { return false; } + bool IsObjCNonFragileABIDefault() const override { return true; } + + CXXStdlibType GetDefaultCXXStdlibType() const override; + void addLibStdCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; + + bool UseSjLjExceptions(const llvm::opt::ArgList &Args) const override; + bool isPIEDefault() const override; + SanitizerMask getSupportedSanitizers() const override; + unsigned GetDefaultDwarfVersion() const override { return 2; } + // Until dtrace (via CTF) and LLDB can deal with distributed debug info, + // BSDSUniX defaults to standalone/full debug info. + bool GetDefaultStandaloneDebug() const override { return true; } + +protected: + Tool *buildAssembler() const override; + Tool *buildLinker() const override; +}; + class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF { public: FreeBSD(const Driver &D, const llvm::Triple &Triple, --- tools/clang/lib/Driver/Tools.h.orig 2017-01-05 05:20:27 UTC +++ tools/clang/lib/Driver/Tools.h @@ -510,6 +510,35 @@ public: }; } // end namespace bitrig +/// bsdsunix -- Directly call GNU Binutils assembler and linker +namespace bsdsunix { +class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { +public: + Assembler(const ToolChain &TC) + : GnuTool("bsdsunix::Assembler", "assembler", TC) {} + + bool hasIntegratedCPP() const override { return false; } + + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; +}; + +class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { +public: + Linker(const ToolChain &TC) : GnuTool("bsdsunix::Linker", "linker", TC) {} + + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return true; } + + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; +}; +} // end namespace bsdsunix + /// freebsd -- Directly call GNU Binutils assembler and linker namespace freebsd { class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool { --- tools/clang/lib/Frontend/InitHeaderSearch.cpp.orig 2016-12-02 09:51:51 UTC +++ tools/clang/lib/Frontend/InitHeaderSearch.cpp @@ -210,6 +210,7 @@ void InitHeaderSearch::AddDefaultCInclud if (HSOpts.UseStandardSystemIncludes) { switch (os) { case llvm::Triple::CloudABI: + case llvm::Triple::BSDSUniX: case llvm::Triple::FreeBSD: case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: --- tools/clang/lib/Sema/SemaChecking.cpp.orig 2017-02-01 17:13:26 UTC +++ tools/clang/lib/Sema/SemaChecking.cpp @@ -4719,6 +4719,7 @@ Sema::FormatStringType Sema::GetFormatSt .Case("strftime", FST_Strftime) .Case("strfmon", FST_Strfmon) .Cases("kprintf", "cmn_err", "vcmn_err", "zcmn_err", FST_Kprintf) + .Case("bsdsunix_kprintf", FST_BSDSUniXKPrintf) .Case("freebsd_kprintf", FST_FreeBSDKPrintf) .Case("os_trace", FST_OSLog) .Case("os_log", FST_OSLog) @@ -4809,6 +4810,7 @@ bool Sema::CheckFormatArguments(ArrayRef default: break; case FST_Kprintf: + case FST_BSDSUniXKPrintf: case FST_FreeBSDKPrintf: case FST_Printf: Diag(FormatLoc, diag::note_format_security_fixit) @@ -5657,6 +5659,44 @@ CheckPrintfHandler::HandlePrintfSpecifie return true; } + + // BSDSUniX kernel extensions. + if (CS.getKind() == ConversionSpecifier::BSDSUniXbArg || + CS.getKind() == ConversionSpecifier::BSDSUniXDArg) { + // We need at least two arguments. + if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex + 1)) + return false; + + // Claim the second argument. + CoveredArgs.set(argIndex + 1); + + // Type check the first argument (int for %b, pointer for %D) + const Expr *Ex = getDataArg(argIndex); + const analyze_printf::ArgType &AT = + (CS.getKind() == ConversionSpecifier::BSDSUniXbArg) ? + ArgType(S.Context.IntTy) : ArgType::CPointerTy; + if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) + EmitFormatDiagnostic( + S.PDiag(diag::warn_format_conversion_argument_type_mismatch) + << AT.getRepresentativeTypeName(S.Context) << Ex->getType() + << false << Ex->getSourceRange(), + Ex->getLocStart(), /*IsStringLocation*/false, + getSpecifierRange(startSpecifier, specifierLen)); + + // Type check the second argument (char * for both %b and %D) + Ex = getDataArg(argIndex + 1); + const analyze_printf::ArgType &AT2 = ArgType::CStrTy; + if (AT2.isValid() && !AT2.matchesType(S.Context, Ex->getType())) + EmitFormatDiagnostic( + S.PDiag(diag::warn_format_conversion_argument_type_mismatch) + << AT2.getRepresentativeTypeName(S.Context) << Ex->getType() + << false << Ex->getSourceRange(), + Ex->getLocStart(), /*IsStringLocation*/false, + getSpecifierRange(startSpecifier, specifierLen)); + + return true; + } + // Check for using an Objective-C specific conversion specifier // in a non-ObjC literal. if (!allowsObjCArg() && CS.isObjCArg()) { @@ -6352,7 +6392,7 @@ static void CheckFormatString(Sema &S, c if (Type == Sema::FST_Printf || Type == Sema::FST_NSString || Type == Sema::FST_FreeBSDKPrintf || Type == Sema::FST_OSLog || - Type == Sema::FST_OSTrace) { + Type == Sema::FST_BSDSUniXKPrintf || Type == Sema::FST_OSTrace) { CheckPrintfHandler H( S, FExpr, OrigFormatExpr, Type, firstDataArg, numDataArgs, (Type == Sema::FST_NSString || Type == Sema::FST_OSTrace), Str, @@ -6362,6 +6402,11 @@ static void CheckFormatString(Sema &S, c if (!analyze_format_string::ParsePrintfString(H, Str, Str + StrLen, S.getLangOpts(), S.Context.getTargetInfo(), + Type == Sema::FST_BSDSUniXKPrintf)) + H.DoneProcessing(); + if (!analyze_format_string::ParsePrintfString(H, Str, Str + StrLen, + S.getLangOpts(), + S.Context.getTargetInfo(), Type == Sema::FST_FreeBSDKPrintf)) H.DoneProcessing(); } else if (Type == Sema::FST_Scanf) { --- tools/clang/lib/Sema/SemaDeclAttr.cpp.orig 2017-01-09 04:12:14 UTC +++ tools/clang/lib/Sema/SemaDeclAttr.cpp @@ -2982,6 +2982,7 @@ static FormatAttrKind getFormatAttrKind( .Cases("scanf", "printf", "printf0", "strfmon", SupportedFormat) .Cases("cmn_err", "vcmn_err", "zcmn_err", SupportedFormat) .Case("kprintf", SupportedFormat) // OpenBSD. + .Case("bsdsunix_kprintf", SupportedFormat) // BSDSUniX. .Case("freebsd_kprintf", SupportedFormat) // FreeBSD. .Case("os_trace", SupportedFormat) .Case("os_log", SupportedFormat) --- tools/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp.orig 2015-11-26 22:08:58 UTC +++ tools/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp @@ -29,6 +29,7 @@ static bool isArc4RandomAvailable(const const llvm::Triple &T = Ctx.getTargetInfo().getTriple(); return T.getVendor() == llvm::Triple::Apple || T.getOS() == llvm::Triple::CloudABI || + T.getOS() == llvm::Triple::BSDSUniX || T.getOS() == llvm::Triple::FreeBSD || T.getOS() == llvm::Triple::NetBSD || T.getOS() == llvm::Triple::OpenBSD || --- tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp.orig 2017-01-05 17:26:53 UTC +++ tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -691,7 +691,7 @@ llvm::Optional MallocCh llvm::Triple::OSType OS = Ctx.getTargetInfo().getTriple().getOS(); if (!KernelZeroFlagVal.hasValue()) { - if (OS == llvm::Triple::FreeBSD) + if (OS == llvm::Triple::FreeBSD || OS == llvm::Triple::BSDSUniX) KernelZeroFlagVal = 0x0100; else if (OS == llvm::Triple::NetBSD) KernelZeroFlagVal = 0x0002; --- tools/clang/tools/scan-build/libexec/ccc-analyzer.orig 2016-02-18 11:08:46 UTC +++ tools/clang/tools/scan-build/libexec/ccc-analyzer @@ -81,6 +81,12 @@ if (`uname -a` =~ m/Darwin/) { if (-x "/usr/bin/xcrun") { $UseXCRUN = 1; } +} elsif (`uname -s` eq "FreeBSD\n") { + $DefaultCCompiler = 'cc'; + $DefaultCXXCompiler = 'c++'; +} elsif (`uname -s` eq "BSDSUniX\n") { + $DefaultCCompiler = 'cc'; + $DefaultCXXCompiler = 'c++'; } else { $DefaultCCompiler = 'gcc'; $DefaultCXXCompiler = 'g++'; --- lib/sanitizer_common/sanitizer_procmaps_bsdsunix.cc.orig 2020-05-22 13:13:50.612930000 +1000 +++ lib/sanitizer_common/sanitizer_procmaps_bsdsunix.cc 2020-05-22 13:20:03.264512000 +1000 @@ -0,0 +1,83 @@ +//===-- sanitizer_procmaps_bsdsunix.cc -------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Information about the process mappings (BSDSUniX-specific parts). +//===----------------------------------------------------------------------===// + +#include "sanitizer_platform.h" +#if SANITIZER_BSDSUNIX +#include "sanitizer_common.h" +#include "sanitizer_bsdsunix.h" +#include "sanitizer_procmaps.h" + +#include +#include +#include + + +namespace __sanitizer { + +void ReadProcMaps(ProcSelfMapsBuff *proc_maps) { + const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid() }; + size_t Size = 0; + int Err = sysctl(Mib, 4, NULL, &Size, NULL, 0); + CHECK_EQ(Err, 0); + CHECK_GT(Size, 0); + + size_t MmapedSize = Size * 4 / 3; + void *VmMap = MmapOrDie(MmapedSize, "ReadProcMaps()"); + Size = MmapedSize; + Err = sysctl(Mib, 4, VmMap, &Size, NULL, 0); + CHECK_EQ(Err, 0); + + proc_maps->data = (char*)VmMap; + proc_maps->mmaped_size = MmapedSize; + proc_maps->len = Size; +} + +bool MemoryMappingLayout::Next(uptr *start, uptr *end, uptr *offset, + char filename[], uptr filename_size, + uptr *protection, ModuleArch *arch, u8 *uuid) { + CHECK(!arch && "not implemented"); + CHECK(!uuid && "not implemented"); + char *last = proc_self_maps_.data + proc_self_maps_.len; + if (current_ >= last) return false; + uptr dummy; + if (!start) start = &dummy; + if (!end) end = &dummy; + if (!offset) offset = &dummy; + if (!protection) protection = &dummy; + struct kinfo_vmentry *VmEntry = (struct kinfo_vmentry*)current_; + + *start = (uptr)VmEntry->kve_start; + *end = (uptr)VmEntry->kve_end; + *offset = (uptr)VmEntry->kve_offset; + + *protection = 0; + if ((VmEntry->kve_protection & KVME_PROT_READ) != 0) + *protection |= kProtectionRead; + if ((VmEntry->kve_protection & KVME_PROT_WRITE) != 0) + *protection |= kProtectionWrite; + if ((VmEntry->kve_protection & KVME_PROT_EXEC) != 0) + *protection |= kProtectionExecute; + + if (filename != NULL && filename_size > 0) { + internal_snprintf(filename, + Min(filename_size, (uptr)PATH_MAX), + "%s", VmEntry->kve_path); + } + + current_ += VmEntry->kve_structsize; + + return true; +} + +} // namespace __sanitizer + +#endif // SANITIZER_BSDSUNIX