- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 270
Integrate LLD for ELF and Mach-O targets too #2203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Sadly doesn't work just yet on Linux: LLVM's command-line parser is first used by LDC, then later (in the same process) by LLD. Probably needs to be reset inbetween or something like that. I hoped the shared cmdline options would make LLD automatically inherit them (without having to add them explicitly to the LLD command line), so ideally those wouldn't be reset. | 
| Same problem for MSVC targets; so LLVM 5.0 broke  | 
| LLD needs a patch; working locally. | 
| Alright, I just tested linking a Phobos-hello-world with the [patched] integrated LLD 5.0 on Ubuntu 16.04. After adding a whole lotta linker flags normally added by gcc (and obtainable via  LLD 5.0 patch, skipping parsing the (unused)  --- a/COFF/Driver.cpp
+++ b/COFF/Driver.cpp
@@ -696,7 +696,8 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
   V.push_back("lld-link (LLVM option parsing)");
   for (auto *Arg : Args.filtered(OPT_mllvm))
     V.push_back(Arg->getValue());
-  cl::ParseCommandLineOptions(V.size(), V.data());
+  if (V.size() > 1)
+    cl::ParseCommandLineOptions(V.size(), V.data());
   // Handle /errorlimit early, because error() depends on it.
   if (auto *Arg = Args.getLastArg(OPT_errorlimit)) {
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -245,7 +245,8 @@ static void initLLVM(opt::InputArgList &Args) {
   V.push_back("lld (LLVM option parsing)");
   for (auto *Arg : Args.filtered(OPT_mllvm))
     V.push_back(Arg->getValue());
-  cl::ParseCommandLineOptions(V.size(), V.data());
+  if (V.size() > 1)
+    cl::ParseCommandLineOptions(V.size(), V.data());
 }
 // Some command line options or some combinations of them are not allowed.LLVM's lazy-created globals scheme via  LTO on Windows works for a Phobos-hello-world when using an external LLD ( | 
| Follow-up: 
 | 
| Reviving this (with LLD 6.0.0 requirement, to simplify the CMake setup), as there's more interest recently (for cross-linking and possibly Android). The actually required linker flags aren't that many as in my example above (i.e., all default ones used by gcc), e.g., the following list of additional LDC flags should suffice to cross-link to Linux/ARM (based on https://forum.dlang.org/post/hlzedmugsxcrcoxpxbuj@forum.dlang.org):  | 
| On Linux x64 Ubuntu 16.04, with LLVM 6.0.0 and Release CMake config,  Btw, LLD 6.0.0 ships with new support for MinGW and WebAssembly. | 
LLD 5.0.0+ would work too, but as there's a new lldCommon library for LLD 6.0.0 (and no more lldConfig), simply require 6.0.0+ to keep the CMake setup reasonably simple.
Requires/includes #2148 and additionallyRequires LLD 5.0+. Still completely untested. ;)