alnyan/yggdrasil: Yggdrasil host support

This commit is contained in:
Mark Poliakov 2024-12-16 15:39:04 +02:00
parent 0b21467e61
commit 05e94c6739
34 changed files with 101 additions and 43 deletions

View File

@ -441,6 +441,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::riscv64:
switch (os) {
case llvm::Triple::Yggdrasil:
return std::make_unique<YggdrasilTargetInfo<RISCV64TargetInfo>>(Triple,
Opts);
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<RISCV64TargetInfo>>(Triple,
Opts);

View File

@ -1966,10 +1966,17 @@ int Driver::ExecuteCompilation(
// llvm/lib/Support/*/Signals.inc will exit with a special return code
// for SIGPIPE. Do not print diagnostics for this case.
#if defined(__yggdrasil__)
if (CommandRes == -1) {
Res = CommandRes;
continue;
}
#else
if (CommandRes == EX_IOERR) {
Res = CommandRes;
continue;
}
#endif
// Print extra information about abnormal failures, if possible.
//

View File

@ -113,7 +113,7 @@ void yggdrasil::Linker::ConstructJob(
if (D.CCCIsCXX()) {
if (ToolChain.ShouldLinkCXXStdlib(Args)) {
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
// CmdArgs.push_back("-lm");
CmdArgs.push_back("-lm");
// CmdArgs.push_back("-lpthread");
}
}
@ -139,6 +139,9 @@ Yggdrasil::Yggdrasil(
llvm::sys::path::append(P, "lib");
getFilePaths().push_back(std::string(P));
}
getFilePaths().push_back(concat(getDriver().SysRoot, "/lib"));
getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
}
std::string Yggdrasil::ComputeEffectiveClangTriple(const ArgList &Args,
@ -178,7 +181,7 @@ ToolChain::UnwindTableLevel Yggdrasil::getDefaultUnwindTableLevel(const llvm::op
void Yggdrasil::addClangTargetOptions(const ArgList &DriverArgs,
ArgStringList &CC1Args,
Action::OffloadKind) const {
if (getArch() == llvm::Triple::x86) {
if (getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::riscv64) {
CC1Args.push_back("-mstack-alignment=16");
}
// if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
@ -214,6 +217,8 @@ void Yggdrasil::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
llvm::sys::path::append(P, "include");
addExternCSystemInclude(DriverArgs, CC1Args, P.str());
}
addSystemInclude(DriverArgs, CC1Args, concat(getDriver().SysRoot, "/usr/include"));
}
void Yggdrasil::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,

View File

@ -817,7 +817,8 @@ typedef __char32_t char32_t;
defined(__APPLE__) || \
defined(__MVS__) || \
defined(_AIX) || \
defined(__EMSCRIPTEN__)
defined(__EMSCRIPTEN__) || \
defined(__yggdrasil__)
// clang-format on
# define _LIBCPP_HAS_THREAD_API_PTHREAD
# elif defined(__Fuchsia__)

View File

@ -33,7 +33,7 @@
// OpenBSD does not have a fully conformant suite of POSIX timers, but
// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__yggdrasil__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
# define _LIBCPP_HAS_CLOCK_GETTIME
#endif

View File

@ -18,7 +18,7 @@
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TimeProfiler.h"
#if LLVM_ON_UNIX
#if LLVM_ON_UNIX || defined(__yggdrasil__)
#include <unistd.h>
#endif
#include <thread>

View File

@ -1238,7 +1238,7 @@ if( LLVM_INCLUDE_UTILS )
if( LLVM_INCLUDE_TESTS )
set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)
set(LLVM_SUBPROJECT_TITLE)
set(LLVM_SUBPROJECT_TITLE)
endif()
else()
if ( LLVM_INCLUDE_TESTS )

View File

@ -393,7 +393,9 @@ void GenericCycleInfo<ContextT>::compute(FunctionT &F) {
<< "\n");
Compute.run(&F.front());
#if !defined(NDEBUG)
assert(validateTree());
#endif
}
template <typename ContextT>
@ -406,7 +408,9 @@ void GenericCycleInfo<ContextT>::splitCriticalEdge(BlockT *Pred, BlockT *Succ,
return;
addBlockToCycle(NewBlock, Cycle);
#if !defined(NDEBUG)
assert(validateTree());
#endif
}
/// \brief Find the innermost cycle containing a given block.

View File

@ -135,7 +135,7 @@ inline perms operator~(perms x) {
/// represents the information provided by Windows FileFirstFile/FindNextFile.
class basic_file_status {
protected:
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
time_t fs_st_atime = 0;
time_t fs_st_mtime = 0;
uint32_t fs_st_atime_nsec = 0;
@ -159,7 +159,7 @@ public:
explicit basic_file_status(file_type Type) : Type(Type) {}
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
basic_file_status(file_type Type, perms Perms, time_t ATime,
uint32_t ATimeNSec, time_t MTime, uint32_t MTimeNSec,
uid_t UID, gid_t GID, off_t Size)
@ -198,7 +198,7 @@ public:
/// same machine.
TimePoint<> getLastModificationTime() const;
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
uint32_t getUser() const { return fs_st_uid; }
uint32_t getGroup() const { return fs_st_gid; }
uint64_t getSize() const { return fs_st_size; }
@ -225,7 +225,7 @@ public:
class file_status : public basic_file_status {
friend bool equivalent(file_status A, file_status B);
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
dev_t fs_st_dev = 0;
nlink_t fs_st_nlinks = 0;
ino_t fs_st_ino = 0;
@ -240,7 +240,7 @@ public:
explicit file_status(file_type Type) : basic_file_status(Type) {}
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
file_status(file_type Type, perms Perms, dev_t Dev, nlink_t Links, ino_t Ino,
time_t ATime, uint32_t ATimeNSec,
time_t MTime, uint32_t MTimeNSec,
@ -1209,7 +1209,7 @@ std::error_code unlockFile(int FD);
/// means that the filesystem may have failed to perform some buffered writes.
std::error_code closeFile(file_t &F);
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
/// @brief Change ownership of a file.
///
/// @param Owner The owner of the file to change to.

View File

@ -28,7 +28,7 @@ namespace sys {
/// This is the OS-specific separator for PATH like environment variables:
// a colon on Unix or a semicolon on Windows.
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
const char EnvPathSeparator = ':';
#elif defined (_WIN32)
const char EnvPathSeparator = ';';

View File

@ -31,7 +31,7 @@ typedef PVOID HANDLE;
namespace llvm {
#if LLVM_ON_UNIX || _WIN32
#if LLVM_ON_UNIX || defined(__yggdrasil__) || _WIN32
/// LLVM thread following std::thread interface with added constructor to
/// specify stack size.
@ -46,7 +46,7 @@ class thread {
}
public:
#if LLVM_ON_UNIX
#if LLVM_ON_UNIX || defined(__yggdrasil__)
using native_handle_type = pthread_t;
using id = pthread_t;
using start_routine_type = void *(*)(void *);

View File

@ -716,7 +716,7 @@ static bool constantIsDead(const Constant *C, bool RemoveDeadUsers) {
ReplaceableMetadataImpl::SalvageDebugInfo(*C);
const_cast<Constant *>(C)->destroyConstant();
}
return true;
}
@ -2239,10 +2239,10 @@ Constant *ConstantExpr::getPointerBitCastOrAddrSpaceCast(Constant *S,
}
Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
#ifndef NDEBUG
// #ifndef NDEBUG
bool fromVec = isa<VectorType>(C->getType());
bool toVec = isa<VectorType>(Ty);
#endif
// #endif
assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
assert(C->getType()->isIntOrIntVectorTy() && "Trunc operand must be integer");
assert(Ty->isIntOrIntVectorTy() && "Trunc produces only integral");

View File

@ -382,11 +382,11 @@ StringRef DIScope::getName() const {
return "";
}
#ifndef NDEBUG
// #ifndef NDEBUG
static bool isCanonical(const MDString *S) {
return !S || !S->getString().empty();
}
#endif
// #endif
dwarf::Tag GenericDINode::getTag() const { return (dwarf::Tag)SubclassData16; }
GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,

View File

@ -465,7 +465,7 @@ void Value::assertModuleIsMaterializedImpl() const {
#endif
}
#ifndef NDEBUG
// #ifndef NDEBUG
static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
Constant *C) {
if (!Cache.insert(Expr).second)
@ -498,7 +498,7 @@ static bool contains(Value *Expr, Value *V) {
SmallPtrSet<ConstantExpr *, 4> Cache;
return contains(Cache, CE, C);
}
#endif // NDEBUG
// #endif // NDEBUG
void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) {
assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
@ -827,7 +827,7 @@ bool Value::canBeFreed() const {
// which is why we need the explicit opt in on a per collector basis.
if (!F->hasGC())
return true;
const auto &GCName = F->getGC();
if (GCName == "statepoint-example") {
auto *PT = cast<PointerType>(this->getType());

View File

@ -37,6 +37,10 @@ if(LLVM_ENABLE_ZSTD)
list(APPEND imported_libs ${zstd_target})
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "yggdrasil")
set(system_libs ${system_libs} m)
endif()
if( WIN32 )
# libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
# advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.

View File

@ -15,7 +15,7 @@
#include "llvm/Config/llvm-config.h"
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/COM.inc"
#elif defined(_WIN32)
#include "Windows/COM.inc"

View File

@ -26,7 +26,7 @@ static inline struct tm getStructTM(TimePoint<> TP) {
struct tm Storage;
std::time_t OurTime = toTimeT(TP);
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
struct tm *LT = ::localtime_r(&OurTime, &Storage);
assert(LT);
(void)LT;
@ -44,7 +44,7 @@ static inline struct tm getStructTMUtc(UtcTime<> TP) {
struct tm Storage;
std::time_t OurTime = toTimeT(TP);
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
struct tm *LT = ::gmtime_r(&OurTime, &Storage);
assert(LT);
(void)LT;

View File

@ -344,8 +344,16 @@ static void uninstallExceptionOrSignalHandlers() {
#include <signal.h>
static const int Signals[] =
{ SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP };
static const int Signals[] = {
SIGABRT,
SIGBUS,
SIGFPE,
#if !defined(__yggdrasil__)
SIGILL,
#endif
SIGSEGV,
SIGTRAP
};
static const unsigned NumSignals = std::size(Signals);
static struct sigaction PrevActions[NumSignals];
@ -372,10 +380,12 @@ static void CrashRecoverySignalHandler(int Signal) {
}
// Unblock the signal we received.
#if !defined(__yggdrasil__)
sigset_t SigMask;
sigemptyset(&SigMask);
sigaddset(&SigMask, Signal);
sigprocmask(SIG_UNBLOCK, &SigMask, nullptr);
#endif
// Return the same error code as if the program crashed, as mentioned in the
// section "Exit Status for Commands":
@ -383,8 +393,10 @@ static void CrashRecoverySignalHandler(int Signal) {
int RetCode = 128 + Signal;
// Don't consider a broken pipe as a crash (see clang/lib/Driver/Driver.cpp)
#if !defined(__yggdrasil__)
if (Signal == SIGPIPE)
RetCode = EX_IOERR;
#endif
if (CRCI)
const_cast<CrashRecoveryContextImpl *>(CRCI)->HandleCrash(RetCode, Signal);

View File

@ -19,7 +19,7 @@
#endif // ifndef NDEBUG
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Memory.inc"
#endif
#ifdef _WIN32

View File

@ -1196,7 +1196,7 @@ Error readNativeFileToEOF(file_t FileHandle, SmallVectorImpl<char> &Buffer,
} // end namespace llvm
// Include the truly platform-specific parts.
#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Path.inc"
#endif
#if defined(_WIN32)

View File

@ -119,7 +119,7 @@ bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; }
}
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Process.inc"
#endif
#ifdef _WIN32

View File

@ -100,7 +100,7 @@ void sys::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
}
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Program.inc"
#endif
#ifdef _WIN32

View File

@ -273,7 +273,7 @@ static bool printMarkupStackTrace(StringRef Argv0, void **StackTrace, int Depth,
}
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Signals.inc"
#endif
#ifdef _WIN32

View File

@ -158,8 +158,10 @@ void StdThreadPool::wait(ThreadPoolTaskGroup &Group) {
return;
}
// Make sure to not deadlock waiting for oneself.
#ifndef NDEBUG
assert(CurrentThreadTaskGroups == nullptr ||
!llvm::is_contained(*CurrentThreadTaskGroups, &Group));
#endif
// Handle the case of recursive call from another task in a different group,
// in which case process tasks while waiting to keep the thread busy and avoid
// possible deadlock.

View File

@ -65,7 +65,7 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
}
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Threading.inc"
#endif
#ifdef _WIN32

View File

@ -112,7 +112,7 @@ typedef uint_t uint;
#endif
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
defined(__MVS__)
defined(__MVS__) || defined(__yggdrasil__)
#define STATVFS_F_FLAG(vfs) (vfs).f_flag
#else
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
@ -505,6 +505,9 @@ static bool is_local_impl(struct STATVFS &Vfs) {
#elif defined(__Fuchsia__)
// Fuchsia doesn't yet support remote filesystem mounts.
return true;
#elif defined(__yggdrasil__)
// Yggdrasil doesn't yet support remote filesystem mounts.
return true;
#elif defined(__EMSCRIPTEN__)
// Emscripten doesn't currently support remote filesystem mounts.
return true;

View File

@ -92,7 +92,9 @@ Expected<unsigned> Process::getPageSize() {
}
size_t Process::GetMallocUsage() {
#if defined(HAVE_MALLINFO2)
#if defined(__yggdrasil__)
return 1;
#elif defined(HAVE_MALLINFO2)
struct mallinfo2 mi;
mi = ::mallinfo2();
return mi.uordblks;

View File

@ -426,7 +426,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
// Parent process: Wait for the child process to terminate.
int status = 0;
ProcessInfo WaitResult;
#ifndef __Fuchsia__
#if !defined(__Fuchsia__)
rusage Info;
if (ProcStat)
ProcStat->reset();
@ -473,7 +473,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
sigaction(SIGALRM, &Old, nullptr);
}
#ifndef __Fuchsia__
#if !defined(__Fuchsia__) && !defined(__yggdrasil__)
if (ProcStat) {
std::chrono::microseconds UserT = toDuration(Info.ru_utime);
std::chrono::microseconds KernelT = toDuration(Info.ru_stime);

View File

@ -213,7 +213,10 @@ static const int IntSigs[] = {SIGHUP, SIGINT, SIGTERM, SIGUSR2};
/// Signals that represent that we have a bug, and our prompt termination has
/// been ordered.
static const int KillSigs[] = {SIGILL,
static const int KillSigs[] = {
#if !defined(__yggdrasil__)
SIGILL,
#endif
SIGTRAP,
SIGABRT,
SIGFPE,
@ -437,7 +440,11 @@ void llvm::sys::SetOneShotPipeSignalFunction(void (*Handler)()) {
void llvm::sys::DefaultOneShotPipeSignalHandler() {
// Send a special return code that drivers can check for, from sysexits.h.
#if defined(__yggdrasil__)
exit(-1);
#else
exit(EX_IOERR);
#endif
}
// The public API

View File

@ -2323,9 +2323,11 @@ RedirectingFileSystem::lookupPathImpl(
sys::path::const_iterator Start, sys::path::const_iterator End,
RedirectingFileSystem::Entry *From,
llvm::SmallVectorImpl<Entry *> &Entries) const {
#ifndef NDEBUG
assert(!isTraversalComponent(*Start) &&
!isTraversalComponent(From->getName()) &&
"Paths should not contain traversal components");
#endif
StringRef FromName = From->getName();
@ -2725,7 +2727,9 @@ void YAMLVFSWriter::addEntry(StringRef VirtualPath, StringRef RealPath,
bool IsDirectory) {
assert(sys::path::is_absolute(VirtualPath) && "virtual path not absolute");
assert(sys::path::is_absolute(RealPath) && "real path not absolute");
#ifndef NDEBUG
assert(!pathHasTraversal(VirtualPath) && "path traversal is not supported");
#endif
Mappings.emplace_back(VirtualPath, RealPath, IsDirectory);
}

View File

@ -14,7 +14,7 @@
#include "llvm/Config/llvm-config.h"
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Watchdog.inc"
#endif
#ifdef _WIN32

View File

@ -11,6 +11,8 @@
//
//===----------------------------------------------------------------------===//
#if !defined(__yggdrasil__)
#include "llvm/Support/raw_socket_stream.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Error.h"
@ -339,3 +341,5 @@ ssize_t raw_socket_stream::read(char *Ptr, size_t Size,
}
return raw_fd_stream::read(Ptr, Size);
}
#endif // defined(__yggdrasil__)

View File

@ -120,8 +120,8 @@ static char *pchar(int);
#define SP(t, s, c) print(m, t, s, c, stdout)
#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
#define NOTE(str) { if (m->eflags&REG_TRACE) (void)printf("=%s\n", (str)); }
static int nope = 0;
#else
static int nope = 0;
#define SP(t, s, c) /* nothing */
#define AT(t, p1, p2, s1, s2) /* nothing */
#define NOTE(s) /* nothing */
@ -1047,7 +1047,7 @@ print(struct match *m, const char *caption, states st, int ch, FILE *d)
(void)fprintf(d, "\n");
}
/*
/*
- at - print current situation
*/
static void

View File

@ -23,7 +23,7 @@
#include <string.h>
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#if defined(LLVM_ON_UNIX) || defined(__yggdrasil__)
#include "Unix/Host.inc"
#include <sched.h>
#endif