From 30afe2f8223094fa81e32baeb0d96bdd0ce68c63 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 29 Nov 2020 17:34:42 +0200 Subject: [PATCH] Update LLVM in the hope of fixing the lld crash Signed-off-by: Dimitar Dobrev --- .github/workflows/llvm-win.yml | 5 +++++ build/build.sh | 2 ++ build/lld.ps1 | 11 +++++++++++ build/llvm/LLVM-commit | 2 +- build/llvm/LLVM.lua | 1 - src/CppParser/Link.cpp | 7 +++++++ src/CppParser/ParseExpr.cpp | 2 +- src/CppParser/Parser.cpp | 10 +++------- 8 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 build/lld.ps1 diff --git a/.github/workflows/llvm-win.yml b/.github/workflows/llvm-win.yml index 8b6cb003..514e7377 100644 --- a/.github/workflows/llvm-win.yml +++ b/.github/workflows/llvm-win.yml @@ -53,6 +53,11 @@ jobs: shell: bash run: build/build.sh clone_llvm working-directory: C:\CppSharp + + - name: Patch LLD + shell: powershell + run: build/lld.ps1 + working-directory: C:\CppSharp - name: Build LLVM shell: bash diff --git a/build/build.sh b/build/build.sh index 65f04f6f..2e73801a 100755 --- a/build/build.sh +++ b/build/build.sh @@ -125,6 +125,8 @@ clone_llvm() build_llvm() { + rm -rf "$builddir/../Directory.Build.props" + rm -rf "$builddir/../Directory.Packages.props" "$builddir/premake.sh" --file="$builddir/llvm/LLVM.lua" build_llvm --os=$os --arch=$platform --configuration=$configuration } diff --git a/build/lld.ps1 b/build/lld.ps1 new file mode 100644 index 00000000..8203ba92 --- /dev/null +++ b/build/lld.ps1 @@ -0,0 +1,11 @@ +$driver = 'C:\CppSharp\build\llvm\llvm-project\lld\COFF\Driver.cpp' +$patched = $false +if (Test-Path $driver) { + $content = ((Get-Content $driver) -replace 'static void createImportLibrary(bool asLib) {', 'static void createImportLibrary(bool asLib) { return;') + [IO.File]::WriteAllLines($driver, $content) + $patched = $true +} + +if (!$patched) { + Write-Warning "This hack is no longer needed and should be removed." +} diff --git a/build/llvm/LLVM-commit b/build/llvm/LLVM-commit index 962728c3..88c24477 100644 --- a/build/llvm/LLVM-commit +++ b/build/llvm/LLVM-commit @@ -1 +1 @@ -0c8f9b8099fd0500cd885bc699924e20371014ff \ No newline at end of file +c40cea6f083a8a67ea950e058e16d37bb04e8c4b \ No newline at end of file diff --git a/build/llvm/LLVM.lua b/build/llvm/LLVM.lua index 9465bc61..ec5a6ad3 100644 --- a/build/llvm/LLVM.lua +++ b/build/llvm/LLVM.lua @@ -260,7 +260,6 @@ function cmake(gen, conf, builddir, options) .. ' -DLLVM_TOOL_DSYMUTIL_BUILD=false' .. ' -DLLVM_TOOL_GOLD_BUILD=false' .. ' -DLLVM_TOOL_LLC_BUILD=false' - .. ' -DLLVM_TOOL_LLD_BUILD=false' .. ' -DLLVM_TOOL_LLDB_BUILD=false' .. ' -DLLVM_TOOL_LLGO_BUILD=false' .. ' -DLLVM_TOOL_LLI_BUILD=false' diff --git a/src/CppParser/Link.cpp b/src/CppParser/Link.cpp index d97d831d..f259dd4c 100644 --- a/src/CppParser/Link.cpp +++ b/src/CppParser/Link.cpp @@ -79,7 +79,9 @@ void Parser::LinkMSVC(const LinkerOptions* LinkerOptions, args.push_back(LibraryPath.data()); args.push_back("-dll"); + args.push_back("-noentry"); args.push_back("libcmt.lib"); + args.push_back("libucrt.lib"); std::vector Libraries; for (const auto& Library : LinkerOptions->Libraries) @@ -93,6 +95,11 @@ void Parser::LinkMSVC(const LinkerOptions* LinkerOptions, std::string Out("-out:" + std::string(Output)); args.push_back(Out.data()); + SmallString<1024> Outputsees(Dir); + sys::path::append(Outputsees, Stem + ".lib"); + std::string Outsees("-implib:" + std::string(Outputsees)); + args.push_back(Outsees.data()); + lld::coff::link(args, false, outs(), errs()); #endif } diff --git a/src/CppParser/ParseExpr.cpp b/src/CppParser/ParseExpr.cpp index 841181e4..c175eba6 100644 --- a/src/CppParser/ParseExpr.cpp +++ b/src/CppParser/ParseExpr.cpp @@ -2074,7 +2074,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr) _S->hasPlaceholderType = S->hasPlaceholderType(); _S->typeAsWritten = GetQualifiedType(S->getTypeAsWritten()); _S->isListInitialization = S->isListInitialization(); - _S->arg_size = S->arg_size(); + _S->arg_size = S->getNumArgs(); for (auto _E : S->arguments()) { auto _ES = WalkExpression(_E); diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 5998e7f3..4cb9dd41 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -100,8 +100,6 @@ static CppAbi GetClassLayoutAbi(clang::TargetCXXABI::Kind abi) return CppAbi::ARM; case clang::TargetCXXABI::iOS: return CppAbi::iOS; - case clang::TargetCXXABI::iOS64: - return CppAbi::iOS64; default: llvm_unreachable("Unsupported C++ ABI kind"); } @@ -229,8 +227,6 @@ ConvertToClangTargetCXXABI(CppSharp::CppParser::AST::CppAbi abi) return TargetCXXABI::GenericARM; case CppSharp::CppParser::AST::CppAbi::iOS: return TargetCXXABI::iOS; - case CppSharp::CppParser::AST::CppAbi::iOS64: - return TargetCXXABI::iOS64; } llvm_unreachable("Unsupported C++ ABI."); @@ -3710,7 +3706,7 @@ AST::ExpressionObsolete* Parser::WalkVariableInitializerExpression(const clang:: return WalkExpressionObsolete(Expr); clang::Expr::EvalResult result; - if (Expr->EvaluateAsConstantExpr(result, clang::Expr::ConstExprUsage::EvaluateForCodeGen, c->getASTContext(), false)) + if (Expr->EvaluateAsConstantExpr(result, c->getASTContext())) { std::string s; llvm::raw_string_ostream out(s); @@ -4423,9 +4419,9 @@ static ArchType ConvertArchType(unsigned int archType) } template -static void ReadELFDependencies(const llvm::object::ELFFile* ELFFile, CppSharp::CppParser::NativeLibrary*& NativeLib) +static void ReadELFDependencies(const llvm::object::ELFFile& ELFFile, CppSharp::CppParser::NativeLibrary*& NativeLib) { - ELFDumper ELFDumper(ELFFile); + ELFDumper ELFDumper(&ELFFile); for (const auto& Dependency : ELFDumper.getNeededLibraries()) NativeLib->Dependencies.push_back(Dependency.str()); }