Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -803,12 +803,12 @@ # (this is a variable that CrossCompile sets on recursive invocations) endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") +if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly|MidnightBSD)") # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM # with libxml2, iconv.h, etc., we must add /usr/local paths. include_directories(SYSTEM "/usr/local/include") link_directories("/usr/local/lib") -endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") +endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly|MidnightBSD)") if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) # special hack for Solaris to handle crazy system sys/regset.h Index: cmake/config.guess =================================================================== --- cmake/config.guess +++ cmake/config.guess @@ -1326,6 +1326,15 @@ i*86:AROS:*:*) echo ${UNAME_MACHINE}-pc-aros exit ;; + *:MidnightBSD:*:*) + UNAME_PROCESSOR=`/usr/bin/uname -p` + case ${UNAME_PROCESSOR} in + amd64) + echo x86_64-unknown-mdinightbsd${UNAME_RELEASE};; + *) + echo ${UNAME_PROCESSOR}-unknown-midnightbsd${UNAME_RELEASE};; + esac + exit ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 Index: cmake/modules/AddLLVM.cmake =================================================================== --- cmake/modules/AddLLVM.cmake +++ cmake/modules/AddLLVM.cmake @@ -1644,7 +1644,7 @@ set(_install_rpath "@loader_path/../lib" ${extra_libdir}) elseif(UNIX) set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly|MidnightBSD)") set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-z,origin ") endif() Index: cmake/modules/HandleLLVMOptions.cmake =================================================================== --- cmake/modules/HandleLLVMOptions.cmake +++ cmake/modules/HandleLLVMOptions.cmake @@ -138,6 +138,7 @@ # build might work on ELF but fail on MachO/COFF. if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR + ${CMAKE_SYSTEM_NAME} MATCHES "MidnightBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND NOT LLVM_USE_SANITIZER) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") Index: include/llvm/ADT/Triple.h =================================================================== --- include/llvm/ADT/Triple.h +++ include/llvm/ADT/Triple.h @@ -183,7 +183,8 @@ Contiki, AMDPAL, // AMD PAL Runtime HermitCore, // HermitCore Unikernel/Multikernel - LastOSType = HermitCore + MidnightBSD, + LastOSType = MidnightBSD }; enum EnvironmentType { UnknownEnvironment, @@ -579,6 +580,10 @@ return getOS() == Triple::KFreeBSD; } + bool isOSMidnightBSD() const { + return getOS() == Triple::MidnightBSD; + } + /// Tests whether the OS uses glibc. bool isOSGlibc() const { return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD) && Index: include/llvm/MC/MCELFObjectWriter.h =================================================================== --- include/llvm/MC/MCELFObjectWriter.h +++ include/llvm/MC/MCELFObjectWriter.h @@ -76,6 +76,7 @@ case Triple::HermitCore: return ELF::ELFOSABI_STANDALONE; case Triple::PS4: + case Triple::MidnightBSD: case Triple::FreeBSD: return ELF::ELFOSABI_FREEBSD; default: Index: lib/Analysis/TargetLibraryInfo.cpp =================================================================== --- lib/Analysis/TargetLibraryInfo.cpp +++ lib/Analysis/TargetLibraryInfo.cpp @@ -382,6 +382,7 @@ case Triple::WatchOS: case Triple::FreeBSD: case Triple::Linux: + case Triple::MidnightBSD: break; default: TLI.setUnavailable(LibFunc_ffsl); @@ -398,6 +399,7 @@ case Triple::WatchOS: case Triple::FreeBSD: case Triple::Linux: + case Triple::MidnightBSD: break; default: TLI.setUnavailable(LibFunc_ffsll); @@ -407,7 +409,7 @@ // http://svn.freebsd.org/base/head/lib/libc/string/fls.c // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c - if (!T.isOSFreeBSD()) { + if (!T.isOSFreeBSD() && !T.isOSMidnightBSD()) { TLI.setUnavailable(LibFunc_fls); TLI.setUnavailable(LibFunc_flsl); TLI.setUnavailable(LibFunc_flsll); Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -193,7 +193,7 @@ // FreeBSD must be explicit about the data size and using pcrel since it's // assembler/linker won't do the automatic conversion that the Linux tools // do. - if (TgtM.getTargetTriple().isOSFreeBSD()) { + if (TgtM.getTargetTriple().isOSFreeBSD() || TgtM.getTargetTriple().isOSMidnightBSD()) { PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; } Index: lib/Support/Triple.cpp =================================================================== --- lib/Support/Triple.cpp +++ lib/Support/Triple.cpp @@ -210,6 +210,7 @@ case Contiki: return "contiki"; case AMDPAL: return "amdpal"; case HermitCore: return "hermit"; + case MidnightBSD: return "midnightbsd"; } llvm_unreachable("Invalid OSType"); @@ -504,6 +505,7 @@ .StartsWith("contiki", Triple::Contiki) .StartsWith("amdpal", Triple::AMDPAL) .StartsWith("hermit", Triple::HermitCore) + .StartsWith("midnightbsd", Triple::MidnightBSD) .Default(Triple::UnknownOS); } @@ -1562,6 +1564,7 @@ // Some defaults are forced. switch (getOS()) { case llvm::Triple::FreeBSD: + case llvm::Triple::MidnightBSD: case llvm::Triple::NetBSD: if (!MArch.empty() && MArch == "v6") return "arm1176jzf-s"; Index: lib/Support/Unix/Memory.inc =================================================================== --- lib/Support/Unix/Memory.inc +++ lib/Support/Unix/Memory.inc @@ -32,7 +32,7 @@ #if defined(__mips__) # if defined(__OpenBSD__) # include -# elif !defined(__FreeBSD__) +# elif !defined(__FreeBSD__) && !defined(__MidnightBSD__) # include # endif #endif @@ -59,7 +59,7 @@ llvm::sys::Memory::MF_EXEC: return PROT_READ | PROT_WRITE | PROT_EXEC; case llvm::sys::Memory::MF_EXEC: -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__MidnightBSD__) // On PowerPC, having an executable page that has no read permission // can have unintended consequences. The function InvalidateInstruction- // Cache uses instructions dcbf and icbi, both of which are treated by Index: lib/Support/Unix/Path.inc =================================================================== --- lib/Support/Unix/Path.inc +++ lib/Support/Unix/Path.inc @@ -53,13 +53,13 @@ #include #if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && \ - !defined(__linux__) + !defined(__linux__) && !defined(__MidnightBSD__) #include #define STATVFS statvfs #define FSTATVFS fstatvfs #define STATVFS_F_FRSIZE(vfs) vfs.f_frsize #else -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__MidnightBSD__) #include #include #elif defined(__linux__) @@ -98,7 +98,8 @@ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \ - defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) + defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || \ + defined(__MidnightBSD__) static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { @@ -169,7 +170,8 @@ } #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__minix) || defined(__DragonFly__) || \ - defined(__FreeBSD_kernel__) || defined(_AIX) + defined(__FreeBSD_kernel__) || defined(_AIX) || \ + defined(__MidnightBSD__) char exe_path[PATH_MAX]; if (getprogpath(exe_path, argv0) != NULL) Index: lib/Support/Unix/Signals.inc =================================================================== --- lib/Support/Unix/Signals.inc +++ lib/Support/Unix/Signals.inc @@ -388,7 +388,8 @@ #if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && HAVE_LINK_H && \ (defined(__linux__) || defined(__FreeBSD__) || \ - defined(__FreeBSD_kernel__) || defined(__NetBSD__)) + defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \ + defined(__MidnightBSD__)) struct DlIteratePhdrData { void **StackTrace; int depth; Index: lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp +++ lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp @@ -65,6 +65,7 @@ // Enable IAS by default for FreeBSD / OpenBSD mips64/mips64el. if (TheTriple.isOSFreeBSD() || - TheTriple.isOSOpenBSD()) + TheTriple.isOSOpenBSD() || + TheTriple.isOSMidnightBSD()) UseIntegratedAssembler = true; } Index: lib/Target/X86/X86FrameLowering.cpp =================================================================== --- lib/Target/X86/X86FrameLowering.cpp +++ lib/Target/X86/X86FrameLowering.cpp @@ -2252,7 +2252,7 @@ report_fatal_error("Segmented stacks do not support vararg functions."); if (!STI.isTargetLinux() && !STI.isTargetDarwin() && !STI.isTargetWin32() && !STI.isTargetWin64() && !STI.isTargetFreeBSD() && - !STI.isTargetDragonFly()) + !STI.isTargetDragonFly() && !STI.isTargetMidnightBSD()) report_fatal_error("Segmented stacks not supported on this platform."); // Eventually StackSize will be calculated by a link-time pass; which will @@ -2304,7 +2304,7 @@ } else if (STI.isTargetWin64()) { TlsReg = X86::GS; TlsOffset = 0x28; // pvArbitrary, reserved for application use - } else if (STI.isTargetFreeBSD()) { + } else if (STI.isTargetFreeBSD() || STI.isTargetMidnightBSD()) { TlsReg = X86::FS; TlsOffset = 0x18; } else if (STI.isTargetDragonFly()) { @@ -2337,6 +2337,8 @@ TlsOffset = 0x10; // use tls_tcb.tcb_segstack } else if (STI.isTargetFreeBSD()) { report_fatal_error("Segmented stacks not supported on FreeBSD i386."); + } else if (STI.isTargetMidnightBSD()) { + report_fatal_error("Segmented stacks not supported on MidnightBSD i386."); } else { report_fatal_error("Segmented stacks not supported on this platform."); } Index: lib/Target/X86/X86TargetMachine.cpp =================================================================== --- lib/Target/X86/X86TargetMachine.cpp +++ lib/Target/X86/X86TargetMachine.cpp @@ -101,7 +101,7 @@ return llvm::make_unique(); } - if (TT.isOSFreeBSD()) + if (TT.isOSFreeBSD() || TT.isOSMidnightBSD()) return llvm::make_unique(); if (TT.isOSLinux() || TT.isOSNaCl() || TT.isOSIAMCU()) return llvm::make_unique(); Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -500,6 +500,7 @@ bool IsWindows = TargetTriple.isOSWindows(); bool IsFuchsia = TargetTriple.isOSFuchsia(); bool IsMyriad = TargetTriple.getVendor() == llvm::Triple::Myriad; + bool IsMidnightBSD = TargetTriple.isOSMidnightBSD(); ShadowMapping Mapping; @@ -513,7 +514,7 @@ Mapping.Offset = kDynamicShadowSentinel; else if (IsMIPS32) Mapping.Offset = kMIPS32_ShadowOffset32; - else if (IsFreeBSD) + else if (IsFreeBSD || isMidnightBSD) Mapping.Offset = kFreeBSD_ShadowOffset32; else if (IsNetBSD) Mapping.Offset = kNetBSD_ShadowOffset32; Index: lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/InstrProfiling.cpp +++ lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -702,7 +702,8 @@ if (Triple(M.getTargetTriple()).isOSLinux() || Triple(M.getTargetTriple()).isOSFreeBSD() || Triple(M.getTargetTriple()).isOSFuchsia() || - Triple(M.getTargetTriple()).isPS4CPU()) + Triple(M.getTargetTriple()).isPS4CPU() || + Triple(M.getTargetTriple()).isOSMidnightBSD()) return false; return true; Index: tools/llvm-shlib/CMakeLists.txt =================================================================== --- tools/llvm-shlib/CMakeLists.txt +++ tools/llvm-shlib/CMakeLists.txt @@ -47,6 +47,7 @@ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly") + OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "MidnightBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")) # FIXME: It should be "GNU ld for elf" configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in