Support external wasm-ld linker for WebAssembly targets

Overridable with `-linker`.
This commit is contained in:
Martin Kinkelin 2018-12-22 18:14:10 +01:00
parent 44877222d4
commit c7b17368c3
4 changed files with 24 additions and 9 deletions

View file

@ -129,7 +129,10 @@ commonSteps: &commonSteps
- run: - run:
name: Run LIT testsuite name: Run LIT testsuite
when: always when: always
command: cd ../ninja-ldc && ctest -V -R lit-tests command: |
cd ../ninja-ldc
# Temporarily add LLVM bin dir to PATH, so that e.g. wasm-ld is found.
PATH=$PWD/../llvm-$LLVM_VERSION/bin:$PATH ctest -V -R lit-tests
- run: - run:
name: Run DMD testsuite name: Run DMD testsuite
when: always when: always

View file

@ -703,16 +703,28 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
} }
#endif #endif
// find gcc for linking // build command-line for gcc-compatible linker driver
const std::string tool = getGcc(); // exception: invoke (ld-compatible) linker directly for WebAssembly targets
std::string tool;
std::unique_ptr<ArgsBuilder> argsBuilder;
#if LDC_LLVM_VER >= 500
if (global.params.targetTriple->isOSBinFormatWasm()) {
tool = getProgram("wasm-ld", &opts::linker);
argsBuilder = llvm::make_unique<LdArgsBuilder>();
} else {
#endif
tool = getGcc();
argsBuilder = llvm::make_unique<ArgsBuilder>();
#if LDC_LLVM_VER >= 500
}
#endif
// build arguments // build arguments
ArgsBuilder argsBuilder; argsBuilder->build(outputPath, defaultLibNames);
argsBuilder.build(outputPath, defaultLibNames);
Logger::println("Linking with: "); Logger::println("Linking with: ");
Stream logstr = Logger::cout(); Stream logstr = Logger::cout();
for (const auto &arg : argsBuilder.args) { for (const auto &arg : argsBuilder->args) {
if (!arg.empty()) { if (!arg.empty()) {
logstr << "'" << arg << "' "; logstr << "'" << arg << "' ";
} }
@ -720,5 +732,5 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
logstr << "\n"; // FIXME where's flush ? logstr << "\n"; // FIXME where's flush ?
// try to call linker // try to call linker
return executeToolAndWait(tool, argsBuilder.args, global.params.verbose); return executeToolAndWait(tool, argsBuilder->args, global.params.verbose);
} }

View file

@ -89,7 +89,7 @@ build:
# Build and run LDC D unittests # Build and run LDC D unittests
- ctest --output-on-failure -R ldc2-unittest - ctest --output-on-failure -R ldc2-unittest
# Run LIT testsuite, ignore the errors # Run LIT testsuite, ignore the errors
- ctest -V -R lit-tests || true - PATH=$PWD/../llvm/bin:$PATH ctest -V -R lit-tests || true
# Run DMD testsuite (non-debug only for now), ignore the errors # Run DMD testsuite (non-debug only for now), ignore the errors
- DMD_TESTSUITE_MAKE_ARGS='-j16 -k' ctest -V -R dmd-testsuite -E "-debug$" || true - DMD_TESTSUITE_MAKE_ARGS='-j16 -k' ctest -V -R dmd-testsuite -E "-debug$" || true
# Run druntime/Phobos unittests (non-debug only for now, excl. hanging core.thread), ignore the errors # Run druntime/Phobos unittests (non-debug only for now, excl. hanging core.thread), ignore the errors

View file

@ -1,7 +1,7 @@
// Compile and link directly to WebAssembly. // Compile and link directly to WebAssembly.
// REQUIRES: target_WebAssembly // REQUIRES: target_WebAssembly
// RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -link-internally %s %baremetal_args // RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm %s %baremetal_args
extern(C): // no mangling, no arguments order reversal extern(C): // no mangling, no arguments order reversal