Last active
November 28, 2024 08:22
-
-
Save anutosh491/a221dec245e05758fbb75c6a76217686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //===----------------- Wasm.cpp - Wasm Interpreter --------------*- C++ -*-===// | |
| // | |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| // See https://llvm.org/LICENSE.txt for license information. | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| // | |
| //===----------------------------------------------------------------------===// | |
| // | |
| // This file implements interpreter support for code execution in WebAssembly. | |
| // | |
| //===----------------------------------------------------------------------===// | |
| #include "Wasm.h" | |
| #include "IncrementalExecutor.h" | |
| #include <llvm/IR/LegacyPassManager.h> | |
| #include <llvm/IR/Module.h> | |
| #include <llvm/MC/TargetRegistry.h> | |
| #include <llvm/Target/TargetMachine.h> | |
| #include <clang/Interpreter/Interpreter.h> | |
| #include <string> | |
| // namespace lld { | |
| // namespace wasm { | |
| // bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| // llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); | |
| // } // namespace wasm | |
| // } // namespace lld | |
| // namespace lld { | |
| // struct DriverDef; | |
| // struct Result; | |
| // Result *lldMain(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| // llvm::raw_ostream &stderrOS, llvm::ArrayRef<DriverDef> drivers); | |
| // namespace wasm { | |
| // bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| // llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); | |
| // } // namespace wasm | |
| // } // namespace lld | |
| namespace lld { | |
| enum Flavor { | |
| Invalid, | |
| Gnu, // -flavor gnu | |
| MinGW, // -flavor gnu MinGW | |
| WinLink, // -flavor link | |
| Darwin, // -flavor darwin | |
| Wasm, // -flavor wasm | |
| }; | |
| using Driver = bool (*)(llvm::ArrayRef<const char *>, llvm::raw_ostream &, | |
| llvm::raw_ostream &, bool, bool); | |
| struct DriverDef { | |
| Flavor f; | |
| Driver d; | |
| }; | |
| struct Result { | |
| int retCode; | |
| bool canRunAgain; | |
| }; | |
| Result lldMain(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| llvm::raw_ostream &stderrOS, llvm::ArrayRef<DriverDef> drivers); | |
| namespace wasm { | |
| bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); | |
| } // namespace wasm | |
| } // namespace lld | |
| #include <dlfcn.h> | |
| namespace clang { | |
| WasmIncrementalExecutor::WasmIncrementalExecutor( | |
| llvm::orc::ThreadSafeContext &TSC) | |
| : IncrementalExecutor(TSC) {} | |
| llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { | |
| std::string ErrorString; | |
| const llvm::Target *Target = llvm::TargetRegistry::lookupTarget( | |
| PTU.TheModule->getTargetTriple(), ErrorString); | |
| if (!Target) { | |
| return llvm::make_error<llvm::StringError>("Failed to create Wasm Target: ", | |
| llvm::inconvertibleErrorCode()); | |
| } | |
| llvm::TargetOptions TO = llvm::TargetOptions(); | |
| llvm::TargetMachine *TargetMachine = Target->createTargetMachine( | |
| PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_); | |
| PTU.TheModule->setDataLayout(TargetMachine->createDataLayout()); | |
| std::string ObjectFileName = PTU.TheModule->getName().str() + ".o"; // For the wasm object | |
| std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm"; // For the wasm binary | |
| // verify if PTU is unique | |
| llvm::outs() << "LLVM IR for Module: " << PTU.TheModule->getName() << "\n"; | |
| PTU.TheModule->print(llvm::outs(), nullptr); | |
| llvm::outs() << "\n"; | |
| std::error_code Error; | |
| llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error); | |
| llvm::legacy::PassManager PM; | |
| if (TargetMachine->addPassesToEmitFile(PM, ObjectFileOutput, nullptr, | |
| llvm::CodeGenFileType::ObjectFile)) { | |
| return llvm::make_error<llvm::StringError>( | |
| "Wasm backend cannot produce object.", llvm::inconvertibleErrorCode()); | |
| } | |
| if (!PM.run(*PTU.TheModule)) { | |
| return llvm::make_error<llvm::StringError>("Failed to emit Wasm object.", | |
| llvm::inconvertibleErrorCode()); | |
| } | |
| ObjectFileOutput.close(); | |
| std::vector<const char *> LinkerArgs = {"wasm-ld", | |
| "-shared", | |
| "--trace", | |
| "--verbose", | |
| "--import-memory", | |
| "--export-all", | |
| "--experimental-pic", | |
| "--stack-first", | |
| "--allow-undefined", | |
| ObjectFileName.c_str(), | |
| "-o", | |
| BinaryFileName.c_str()}; | |
| const lld::DriverDef WasmDriver = {lld::Flavor::Wasm, &lld::wasm::link}; | |
| std::vector<lld::DriverDef> WasmDriverArgs; | |
| WasmDriverArgs.push_back(WasmDriver); | |
| lld::Result Result = lld::lldMain(LinkerArgs, llvm::outs(), llvm::errs(), WasmDriverArgs); | |
| // int Result = | |
| // lld::wasm::link(LinkerArgs, llvm::outs(), llvm::errs(), false, false); | |
| if (Result.retCode != 0) | |
| return llvm::make_error<llvm::StringError>( | |
| "Failed to link incremental module", llvm::inconvertibleErrorCode()); | |
| void *LoadedLibModule = | |
| dlopen(BinaryFileName.c_str(), RTLD_NOW | RTLD_GLOBAL); | |
| if (LoadedLibModule == nullptr) { | |
| llvm::errs() << dlerror() << '\n'; | |
| return llvm::make_error<llvm::StringError>( | |
| "Failed to load incremental module", llvm::inconvertibleErrorCode()); | |
| } | |
| return llvm::Error::success(); | |
| } | |
| llvm::Error WasmIncrementalExecutor::removeModule(PartialTranslationUnit &PTU) { | |
| return llvm::make_error<llvm::StringError>("Not implemented yet", | |
| llvm::inconvertibleErrorCode()); | |
| } | |
| llvm::Error WasmIncrementalExecutor::runCtors() const { | |
| // This seems to be automatically done when using dlopen() | |
| return llvm::Error::success(); | |
| } | |
| llvm::Error WasmIncrementalExecutor::cleanUp() { | |
| // Can't call cleanUp through IncrementalExecutor as it | |
| // tries to deinitialize JIT which hasn't been initialized | |
| return llvm::Error::success(); | |
| } | |
| WasmIncrementalExecutor::~WasmIncrementalExecutor() = default; | |
| } // namespace clang | |
| // cmake -DCMAKE_BUILD_TYPE=Debug \ | |
| // -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \ | |
| // -DLLVM_TARGETS_TO_BUILD="WebAssembly" \ | |
| // -DLLVM_INCLUDE_BENCHMARKS=OFF \ | |
| // -DLLVM_INCLUDE_EXAMPLES=OFF \ | |
| // -DLLVM_INCLUDE_TESTS=OFF \ | |
| // -DLLVM_ENABLE_LIBEDIT=OFF \ | |
| // -DLLVM_ENABLE_PROJECTS="clang;lld" \ | |
| // -DLLVM_ENABLE_THREADS=OFF \ | |
| // -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ | |
| // -DCLANG_ENABLE_ARCMT=OFF \ | |
| // -DCLANG_ENABLE_BOOTSTRAP=OFF \ | |
| // -DLLVM_ENABLE_ZSTD=OFF \ | |
| // -DLLVM_ENABLE_LIBXML2=OFF \ | |
| // -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \ | |
| // ../llvm | |
| // cmake -DCMAKE_BUILD_TYPE=Debug \ | |
| // -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \ | |
| // -DLLVM_TARGETS_TO_BUILD="WebAssembly" \ | |
| // -DLLVM_INCLUDE_BENCHMARKS=OFF \ | |
| // -DLLVM_INCLUDE_EXAMPLES=OFF \ | |
| // -DLLVM_INCLUDE_TESTS=OFF \ | |
| // -DLLVM_ENABLE_LIBEDIT=OFF \ | |
| // -DLLVM_ENABLE_PROJECTS="clang;lld" \ | |
| // -DLLVM_ENABLE_THREADS=OFF \ | |
| // -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ | |
| // -DCLANG_ENABLE_ARCMT=OFF \ | |
| // -DCLANG_ENABLE_BOOTSTRAP=OFF \ | |
| // -DLLVM_ENABLE_ZSTD=OFF \ | |
| // -DLLVM_ENABLE_LIBXML2=OFF \ | |
| // -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF \ | |
| // -DCMAKE_TOOLCHAIN_FILE=/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \ | |
| // -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \ | |
| // ../llvm | |
| --------------------------xxx--------------- | |
| diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h | |
| index 13582b899dc2..784bb7cb999a 100644 | |
| --- a/clang/include/clang/Support/Compiler.h | |
| +++ b/clang/include/clang/Support/Compiler.h | |
| @@ -16,6 +16,9 @@ | |
| #include "llvm/Support/Compiler.h" | |
| +#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | |
| +#define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT | |
| +#define CLANG_EXPORT_TEMPLATE | |
| /// CLANG_ABI is the main export/visibility macro to mark something as | |
| /// explicitly exported when clang is built as a shared library with everything | |
| /// else that is unannotated having hidden visibility. | |
| diff --git a/clang/lib/Interpreter/CMakeLists.txt b/clang/lib/Interpreter/CMakeLists.txt | |
| index df7ea82e0dad..bf70cdfbee01 100644 | |
| --- a/clang/lib/Interpreter/CMakeLists.txt | |
| +++ b/clang/lib/Interpreter/CMakeLists.txt | |
| @@ -16,6 +16,7 @@ set(LLVM_LINK_COMPONENTS | |
| if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS) | |
| set(WASM_SRC Wasm.cpp) | |
| set(WASM_LINK lldWasm) | |
| + set(COMMON_LINK lldCommon) | |
| endif() | |
| add_clang_library(clangInterpreter | |
| @@ -47,6 +48,7 @@ add_clang_library(clangInterpreter | |
| clangSema | |
| clangSerialization | |
| ${WASM_LINK} | |
| + ${COMMON_LINK} | |
| ) | |
| if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS) | |
| diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp | |
| index 5dc67f637509..887b494ff98f 100644 | |
| --- a/clang/lib/Interpreter/Interpreter.cpp | |
| +++ b/clang/lib/Interpreter/Interpreter.cpp | |
| @@ -201,6 +201,7 @@ IncrementalCompilerBuilder::CreateCpp() { | |
| Argv.push_back("-target"); | |
| Argv.push_back("wasm32-unknown-emscripten"); | |
| Argv.push_back("-shared"); | |
| + Argv.push_back("-fvisibility=default"); | |
| #endif | |
| Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end()); | |
| diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp | |
| index 79efbaa03982..abe60abf59b6 100644 | |
| --- a/clang/lib/Interpreter/Wasm.cpp | |
| +++ b/clang/lib/Interpreter/Wasm.cpp | |
| @@ -22,13 +22,58 @@ | |
| #include <string> | |
| +// namespace lld { | |
| +// namespace wasm { | |
| +// bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| +// llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); | |
| +// } // namespace wasm | |
| +// } // namespace lld | |
| + | |
| +// namespace lld { | |
| +// struct DriverDef; | |
| +// struct Result; | |
| +// Result *lldMain(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| +// llvm::raw_ostream &stderrOS, llvm::ArrayRef<DriverDef> drivers); | |
| + | |
| +// namespace wasm { | |
| +// bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| +// llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); | |
| +// } // namespace wasm | |
| +// } // namespace lld | |
| + | |
| namespace lld { | |
| +enum Flavor { | |
| + Invalid, | |
| + Gnu, // -flavor gnu | |
| + MinGW, // -flavor gnu MinGW | |
| + WinLink, // -flavor link | |
| + Darwin, // -flavor darwin | |
| + Wasm, // -flavor wasm | |
| +}; | |
| + | |
| +using Driver = bool (*)(llvm::ArrayRef<const char *>, llvm::raw_ostream &, | |
| + llvm::raw_ostream &, bool, bool); | |
| + | |
| +struct DriverDef { | |
| + Flavor f; | |
| + Driver d; | |
| +}; | |
| + | |
| +struct Result { | |
| + int retCode; | |
| + bool canRunAgain; | |
| +}; | |
| + | |
| +Result lldMain(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| + llvm::raw_ostream &stderrOS, llvm::ArrayRef<DriverDef> drivers); | |
| + | |
| namespace wasm { | |
| bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, | |
| llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); | |
| } // namespace wasm | |
| } // namespace lld | |
| + | |
| #include <dlfcn.h> | |
| namespace clang { | |
| @@ -51,13 +96,19 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { | |
| llvm::TargetMachine *TargetMachine = Target->createTargetMachine( | |
| PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_); | |
| PTU.TheModule->setDataLayout(TargetMachine->createDataLayout()); | |
| - std::string OutputFileName = PTU.TheModule->getName().str() + ".wasm"; | |
| + std::string ObjectFileName = PTU.TheModule->getName().str() + ".o"; // For the wasm object | |
| + std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm"; // For the wasm binary | |
| + | |
| + // verify if PTU is unique | |
| + llvm::outs() << "LLVM IR for Module: " << PTU.TheModule->getName() << "\n"; | |
| + PTU.TheModule->print(llvm::outs(), nullptr); | |
| + llvm::outs() << "\n"; | |
| std::error_code Error; | |
| - llvm::raw_fd_ostream OutputFile(llvm::StringRef(OutputFileName), Error); | |
| + llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error); | |
| llvm::legacy::PassManager PM; | |
| - if (TargetMachine->addPassesToEmitFile(PM, OutputFile, nullptr, | |
| + if (TargetMachine->addPassesToEmitFile(PM, ObjectFileOutput, nullptr, | |
| llvm::CodeGenFileType::ObjectFile)) { | |
| return llvm::make_error<llvm::StringError>( | |
| "Wasm backend cannot produce object.", llvm::inconvertibleErrorCode()); | |
| @@ -69,27 +120,31 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { | |
| llvm::inconvertibleErrorCode()); | |
| } | |
| - OutputFile.close(); | |
| + ObjectFileOutput.close(); | |
| std::vector<const char *> LinkerArgs = {"wasm-ld", | |
| "-shared", | |
| "--import-memory", | |
| - "--no-entry", | |
| - "--export-all", | |
| "--experimental-pic", | |
| "--stack-first", | |
| "--allow-undefined", | |
| - OutputFileName.c_str(), | |
| + ObjectFileName.c_str(), | |
| "-o", | |
| - OutputFileName.c_str()}; | |
| - int Result = | |
| - lld::wasm::link(LinkerArgs, llvm::outs(), llvm::errs(), false, false); | |
| - if (!Result) | |
| + BinaryFileName.c_str()}; | |
| + | |
| + const lld::DriverDef WasmDriver = {lld::Flavor::Wasm, &lld::wasm::link}; | |
| + std::vector<lld::DriverDef> WasmDriverArgs; | |
| + WasmDriverArgs.push_back(WasmDriver); | |
| + lld::Result Result = lld::lldMain(LinkerArgs, llvm::outs(), llvm::errs(), WasmDriverArgs); | |
| + | |
| + // int Result = | |
| + // lld::wasm::link(LinkerArgs, llvm::outs(), llvm::errs(), false, false); | |
| + if (Result.retCode != 0) | |
| return llvm::make_error<llvm::StringError>( | |
| "Failed to link incremental module", llvm::inconvertibleErrorCode()); | |
| void *LoadedLibModule = | |
| - dlopen(OutputFileName.c_str(), RTLD_NOW | RTLD_GLOBAL); | |
| + dlopen(BinaryFileName.c_str(), RTLD_NOW | RTLD_GLOBAL); | |
| if (LoadedLibModule == nullptr) { | |
| llvm::errs() << dlerror() << '\n'; | |
| return llvm::make_error<llvm::StringError>( | |
| @@ -109,7 +164,7 @@ llvm::Error WasmIncrementalExecutor::runCtors() const { | |
| return llvm::Error::success(); | |
| } | |
| -llvm::Error WasmIncrementalExecutor::cleanUp() const { | |
| +llvm::Error WasmIncrementalExecutor::cleanUp() { | |
| // Can't call cleanUp through IncrementalExecutor as it | |
| // tries to deinitialize JIT which hasn't been initialized | |
| return llvm::Error::success(); | |
| @@ -118,3 +173,39 @@ llvm::Error WasmIncrementalExecutor::cleanUp() const { | |
| WasmIncrementalExecutor::~WasmIncrementalExecutor() = default; | |
| } // namespace clang | |
| + | |
| +// cmake -DCMAKE_BUILD_TYPE=Debug \ | |
| +// -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \ | |
| +// -DLLVM_TARGETS_TO_BUILD="WebAssembly" \ | |
| +// -DLLVM_INCLUDE_BENCHMARKS=OFF \ | |
| +// -DLLVM_INCLUDE_EXAMPLES=OFF \ | |
| +// -DLLVM_INCLUDE_TESTS=OFF \ | |
| +// -DLLVM_ENABLE_LIBEDIT=OFF \ | |
| +// -DLLVM_ENABLE_PROJECTS="clang;lld" \ | |
| +// -DLLVM_ENABLE_THREADS=OFF \ | |
| +// -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ | |
| +// -DCLANG_ENABLE_ARCMT=OFF \ | |
| +// -DCLANG_ENABLE_BOOTSTRAP=OFF \ | |
| +// -DLLVM_ENABLE_ZSTD=OFF \ | |
| +// -DLLVM_ENABLE_LIBXML2=OFF \ | |
| +// -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \ | |
| +// ../llvm | |
| + | |
| +// cmake -DCMAKE_BUILD_TYPE=Debug \ | |
| +// -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \ | |
| +// -DLLVM_TARGETS_TO_BUILD="WebAssembly" \ | |
| +// -DLLVM_INCLUDE_BENCHMARKS=OFF \ | |
| +// -DLLVM_INCLUDE_EXAMPLES=OFF \ | |
| +// -DLLVM_INCLUDE_TESTS=OFF \ | |
| +// -DLLVM_ENABLE_LIBEDIT=OFF \ | |
| +// -DLLVM_ENABLE_PROJECTS="clang;lld" \ | |
| +// -DLLVM_ENABLE_THREADS=OFF \ | |
| +// -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ | |
| +// -DCLANG_ENABLE_ARCMT=OFF \ | |
| +// -DCLANG_ENABLE_BOOTSTRAP=OFF \ | |
| +// -DLLVM_ENABLE_ZSTD=OFF \ | |
| +// -DLLVM_ENABLE_LIBXML2=OFF \ | |
| +// -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF \ | |
| +// -DCMAKE_TOOLCHAIN_FILE=/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \ | |
| +// -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \ | |
| +// ../llvm | |
| \ No newline at end of file | |
| diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp | |
| index 6b60ebb18e82..0ff22b0e1555 100644 | |
| --- a/lld/Common/ErrorHandler.cpp | |
| +++ b/lld/Common/ErrorHandler.cpp | |
| @@ -31,6 +31,7 @@ static StringRef getSeparator(const Twine &msg) { | |
| } | |
| ErrorHandler::~ErrorHandler() { | |
| + llvm::outs() << "ErrorHandler destroyed\n"; | |
| if (cleanupCallback) | |
| cleanupCallback(); | |
| } | |
| diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h | |
| index eb32ce80f4a3..309d0a12dbc4 100644 | |
| --- a/lld/wasm/Config.h | |
| +++ b/lld/wasm/Config.h | |
| @@ -165,4 +165,4 @@ void errorOrWarn(const llvm::Twine &msg); | |
| } // namespace lld::wasm | |
| -#endif | |
| +#endif | |
| \ No newline at end of file | |
| diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp | |
| index 8d01ff839ddf..fe3ecf0a53bc 100644 | |
| --- a/lld/wasm/Driver.cpp | |
| +++ b/lld/wasm/Driver.cpp | |
| @@ -454,8 +454,10 @@ getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) { | |
| } | |
| static StringRef getEntry(opt::InputArgList &args) { | |
| + log("-- getentry mein aata hai na ?"); | |
| auto *arg = args.getLastArg(OPT_entry, OPT_no_entry); | |
| if (!arg) { | |
| + log("-- entry point based on shared"); | |
| if (args.hasArg(OPT_relocatable)) | |
| return ""; | |
| if (args.hasArg(OPT_shared)) | |
| diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp | |
| index aeac1a51824f..11806c26af8e 100644 | |
| --- a/lld/wasm/Writer.cpp | |
| +++ b/lld/wasm/Writer.cpp | |
| @@ -851,6 +851,8 @@ void Writer::calculateTypes() { | |
| // 5. The signatures of all defined tags | |
| for (ObjFile *file : ctx.objectFiles) { | |
| + log("-- Processing object file: in calculateTypes "); | |
| + log(file->getName().str()); | |
| ArrayRef<WasmSignature> types = file->getWasmObj()->types(); | |
| for (uint32_t i = 0; i < types.size(); i++) | |
| if (file->typeIsUsed[i]) | |
| @@ -944,6 +946,8 @@ static void finalizeIndirectFunctionTable() { | |
| static void scanRelocations() { | |
| for (ObjFile *file : ctx.objectFiles) { | |
| + log("-- Processing object file: in scanRelocations "); | |
| + log(file->getName().str()); | |
| LLVM_DEBUG(dbgs() << "scanRelocations: " << file->getName() << "\n"); | |
| for (InputChunk *chunk : file->functions) | |
| scanRelocations(chunk); | |
| @@ -1027,6 +1031,8 @@ OutputSegment *Writer::createOutputSegment(StringRef name) { | |
| void Writer::createOutputSegments() { | |
| for (ObjFile *file : ctx.objectFiles) { | |
| + log("-- Processing object file: in createOutputSegments "); | |
| + log(file->getName().str()); | |
| for (InputChunk *segment : file->segments) { | |
| if (!segment->live) | |
| continue; | |
| @@ -1660,6 +1666,8 @@ void Writer::calculateInitFunctions() { | |
| return; | |
| for (ObjFile *file : ctx.objectFiles) { | |
| + log("-- Processing object file: in calculateInitFunctions "); | |
| + log(file->getName().str()); | |
| const WasmLinkingData &l = file->getWasmObj()->linkingData(); | |
| for (const WasmInitFunc &f : l.InitFunctions) { | |
| FunctionSymbol *sym = file->getFunctionSymbol(f.Symbol); | |
| @@ -1710,7 +1718,7 @@ void Writer::run() { | |
| if (!ctx.isPic && WasmSym::definedTableBase) | |
| WasmSym::definedTableBase->setVA(config->tableBase); | |
| - log("-- createOutputSegments"); | |
| + log("-- createOutputSegments changed"); | |
| createOutputSegments(); | |
| log("-- createSyntheticSections"); | |
| createSyntheticSections(); | |
| diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake | |
| index e36a71f522d8..fb014634c78a 100644 | |
| --- a/llvm/cmake/modules/CrossCompile.cmake | |
| +++ b/llvm/cmake/modules/CrossCompile.cmake | |
| @@ -84,6 +84,8 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype) | |
| -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}" | |
| -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" | |
| -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" | |
| + -DCMAKE_C_COMPILER="clang" | |
| + -DCMAKE_CXX_COMPILER="clang++" | |
| ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR} | |
| ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}} | |
| -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE | |
| diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h | |
| index 1563d1346898..caa66c4ea559 100644 | |
| --- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h | |
| +++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h | |
| @@ -43,10 +43,10 @@ struct jit_descriptor { | |
| }; | |
| } | |
| -extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult | |
| +extern "C" __attribute__((visibility("default"))) llvm::orc::shared::CWrapperFunctionResult | |
| llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size); | |
| -extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult | |
| +extern "C" __attribute__((visibility("default"))) llvm::orc::shared::CWrapperFunctionResult | |
| llvm_orc_registerJITLoaderGDBAllocAction(const char *Data, size_t Size); | |
| #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_JITLOADERGDB_H | |
| diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h | |
| index aa9951a23b99..6faa3c8c4787 100644 | |
| --- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h | |
| +++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h | |
| @@ -17,13 +17,13 @@ | |
| #include "llvm/Support/Compiler.h" | |
| #include <cstdint> | |
| -extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult | |
| +extern "C" __attribute__((visibility("default"))) llvm::orc::shared::CWrapperFunctionResult | |
| llvm_orc_registerJITLoaderPerfImpl(const char *Data, uint64_t Size); | |
| -extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult | |
| +extern "C" __attribute__((visibility("default"))) llvm::orc::shared::CWrapperFunctionResult | |
| llvm_orc_registerJITLoaderPerfStart(const char *Data, uint64_t Size); | |
| -extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult | |
| +extern "C" __attribute__((visibility("default"))) llvm::orc::shared::CWrapperFunctionResult | |
| llvm_orc_registerJITLoaderPerfEnd(const char *Data, uint64_t Size); | |
| #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_JITLOADERPERF_H | |
| \ No newline at end of file | |
| diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h | |
| index f9c57b89f1f0..d91479b9ddc2 100644 | |
| --- a/llvm/include/llvm/Support/Compiler.h | |
| +++ b/llvm/include/llvm/Support/Compiler.h | |
| @@ -100,6 +100,9 @@ | |
| #define LLVM_MSC_PREREQ(version) 0 | |
| #endif | |
| +#define LLVM_ABI __attribute__((visibility("default"))) | |
| +#define LLVM_TEMPLATE_ABI __attribute__((visibility("default"))) | |
| +#define LLVM_EXPORT_TEMPLATE | |
| /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked | |
| /// into a shared library, then the class should be private to the library and | |
| /// not accessible from outside it. Can also be used to mark variables and | |
| diff --git a/llvm/lib/IR/PassInstrumentation.cpp b/llvm/lib/IR/PassInstrumentation.cpp | |
| index 94ad124a6c77..deaf35bca42b 100644 | |
| --- a/llvm/lib/IR/PassInstrumentation.cpp | |
| +++ b/llvm/lib/IR/PassInstrumentation.cpp | |
| @@ -17,9 +17,9 @@ | |
| namespace llvm { | |
| -template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Module *>; | |
| -template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Function *>; | |
| -template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Loop *>; | |
| +template struct Any::TypeId<const Module *>; | |
| +template struct Any::TypeId<const Function *>; | |
| +template struct Any::TypeId<const Loop *>; | |
| void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName, | |
| StringRef PassName) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment