Skip to content

Commit

Permalink
Merge pull request #2951 from kinke/externalWasmLd
Browse files Browse the repository at this point in the history
Support external wasm-ld linker for WebAssembly targets
  • Loading branch information
kinke committed Jan 8, 2019
2 parents 26b57fe + 794907b commit b8d5ac9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions driver/linker-gcc.cpp
Expand Up @@ -703,22 +703,34 @@ 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 << "' ";
} }
} }
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);
} }
2 changes: 1 addition & 1 deletion shippable.yml
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/baremetal/lit.local.cfg
@@ -1,4 +1,16 @@
import subprocess

# Define `%baremetal_args` as LDC args making sure # Define `%baremetal_args` as LDC args making sure
# * no ldc2.conf file is used (=> no implicit command-line args), and # * no ldc2.conf file is used (=> no implicit command-line args), and
# * the empty object.d in ./inputs is imported (=> no TypeInfo, ModuleInfo, Object...). # * the empty object.d in ./inputs is imported (=> no TypeInfo, ModuleInfo, Object...).
config.substitutions.append( ('%baremetal_args', '-conf= -I' + config.test_source_root + '/baremetal/inputs') ) config.substitutions.append( ('%baremetal_args', '-conf= -I' + config.test_source_root + '/baremetal/inputs') )

# Add "link_WebAssembly" feature if we can link wasm (-link-internally or wasm-ld in PATH).
if config.ldc_with_lld:
config.available_features.add('link_WebAssembly')
else:
try:
if (subprocess.call(["wasm-ld", "--version"]) == 0):
config.available_features.add('link_WebAssembly')
except OSError:
pass
1 change: 1 addition & 0 deletions tests/baremetal/wasm.d
@@ -1,6 +1,7 @@
// Compile and link directly to WebAssembly. // Compile and link directly to WebAssembly.


// REQUIRES: target_WebAssembly // REQUIRES: target_WebAssembly
// REQUIRES: internal_lld
// RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -link-internally %s %baremetal_args // RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -link-internally %s %baremetal_args


extern(C): // no mangling, no arguments order reversal extern(C): // no mangling, no arguments order reversal
Expand Down
1 change: 1 addition & 0 deletions tests/baremetal/wasm2.d
@@ -1,6 +1,7 @@
// A more complex wasm example using Phobos templates (=> -betterC to keep it simple). // A more complex wasm example using Phobos templates (=> -betterC to keep it simple).


// REQUIRES: target_WebAssembly // REQUIRES: target_WebAssembly
// REQUIRES: link_WebAssembly
// RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -betterC %s // RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -betterC %s


extern(C): extern(C):
Expand Down
2 changes: 1 addition & 1 deletion tests/lit.site.cfg.in
Expand Up @@ -25,7 +25,7 @@ config.dynamic_compile = @LDC_DYNAMIC_COMPILE@
config.plugins_supported = "@LDC_ENABLE_PLUGINS@" == "ON" config.plugins_supported = "@LDC_ENABLE_PLUGINS@" == "ON"
config.gnu_make_bin = "@GNU_MAKE_BIN@" config.gnu_make_bin = "@GNU_MAKE_BIN@"
config.ldc_host_arch = "@LDC_HOST_ARCH@" config.ldc_host_arch = "@LDC_HOST_ARCH@"
config.ldc_with_lld = "@LDC_WITH_LLD@" config.ldc_with_lld = "@LDC_WITH_LLD@" == "ON"


config.name = 'LDC' config.name = 'LDC'


Expand Down

0 comments on commit b8d5ac9

Please sign in to comment.