Skip to content

Commit

Permalink
Add -link-internally support for MinGW and WebAssembly targets
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Jul 9, 2018
1 parent 631e29b commit 27e4ac0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,12 @@ add_custom_target(${LDMD_EXE} ALL DEPENDS ${LDMD_EXE_FULL})
# LLVM flags into account.
set(LDC_LINKERFLAG_LIST ${SANITIZE_LDFLAGS} ${LLVM_LIBRARIES} ${LLVM_LDFLAGS})
if(LDC_WITH_LLD)
# ELF and Mach-O formats supported since LLD 6.0.0, otherwise just Windows COFF
# ELF, Mach-O, MinGW and WebAssembly formats supported since LLD 6.0.0, otherwise just Windows COFF
if(NOT (LDC_LLVM_VER LESS 600))
if(MSVC)
list(APPEND LDC_LINKERFLAG_LIST lldDriver.lib lldCOFF.lib lldELF.lib lldMachO.lib lldYAML.lib lldReaderWriter.lib lldCommon.lib lldCore.lib)
list(APPEND LDC_LINKERFLAG_LIST lldDriver.lib lldMinGW.lib lldCOFF.lib lldELF.lib lldMachO.lib lldWasm.lib lldYAML.lib lldReaderWriter.lib lldCommon.lib lldCore.lib)
else()
set(LDC_LINKERFLAG_LIST -llldDriver -llldCOFF -llldELF -llldMachO -llldYAML -llldReaderWriter -llldCommon -llldCore ${LDC_LINKERFLAG_LIST})
set(LDC_LINKERFLAG_LIST -llldDriver -llldMinGW -llldCOFF -llldELF -llldMachO -llldWasm -llldYAML -llldReaderWriter -llldCommon -llldCore ${LDC_LINKERFLAG_LIST})
endif()
if(APPLE) # bug, should be fixed in LLVM 6.0.1
list(APPEND LDC_LINKERFLAG_LIST -lxml2)
Expand Down
6 changes: 5 additions & 1 deletion driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
argsBuilder.build(outputPath, defaultLibNames);

const auto fullArgs =
getFullArgs("ld.lld", argsBuilder.args, global.params.verbose);
getFullArgs("lld", argsBuilder.args, global.params.verbose);

// CanExitEarly == true means that LLD can and will call `exit()` when errors occur.
const bool CanExitEarly = false;
Expand All @@ -670,6 +670,10 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
#else
success = lld::mach_o::link(fullArgs);
#endif
} else if (global.params.targetTriple->isOSBinFormatCOFF()) {
success = lld::mingw::link(fullArgs);
} else if (global.params.targetTriple->isOSBinFormatWasm()) {
success = lld::wasm::link(fullArgs, CanExitEarly);
} else {
error(Loc(), "unknown target binary format for internal linking");
}
Expand Down
3 changes: 3 additions & 0 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ static std::string getOutputName() {
extension = global.dll_ext;
} else if (triple.isOSWindows()) {
extension = "exe";
} else if (triple.getArch() == llvm::Triple::wasm32 ||
triple.getArch() == llvm::Triple::wasm64) {
extension = "wasm";
}

if (global.params.exefile) {
Expand Down

0 comments on commit 27e4ac0

Please sign in to comment.