Skip to content

Enable cross-static-lib generation for LLVM 3.9+#2030

Merged
kinke merged 7 commits intoldc-developers:masterfrom
kinke:crossLib
Apr 8, 2017
Merged

Enable cross-static-lib generation for LLVM 3.9+#2030
kinke merged 7 commits intoldc-developers:masterfrom
kinke:crossLib

Conversation

@kinke
Copy link
Member

@kinke kinke commented Mar 11, 2017

By directly integrating LLVM's llvm-lib.exe driver to generate static libs for MSVC targets and a heavily stripped-down version of the llvm-ar tool for the other targets.

For the moment, just testing if it basically works on Linux and OSX too (works fine here on Win64; able to produce libs for x86 and x86_64 Linux...) and which older LLVM versions aren't supported. I removed the llvm-ar logic for modifying an existing lib (insertion order...), I guess it'll have to be put in again for the final implementation. :/

@kinke kinke force-pushed the crossLib branch 2 times, most recently from 237ecf3 to eeb0c80 Compare March 12, 2017 02:45
@kinke kinke changed the title [Experimental] Enable cross-static-lib generation [WIP] Enable cross-static-lib generation for LLVM 3.9+ Mar 12, 2017
@kinke
Copy link
Member Author

kinke commented Mar 12, 2017

Replacing objects in existing libs (and keeping old non-replaced members) re-added.

By directly integrating LLVM's `llvm-lib.exe` driver to generate static
libs for MSVC targets and a stripped-down version of the `llvm-ar` tool
for the other targets.

Introduce command-line option `-archiver=<file>` to allow the user to
specify an external archiver to be invoked.
@kinke
Copy link
Member Author

kinke commented Mar 12, 2017

ldc2 executable size delta with this PR for my RelWithDebInfo LDC with RelWithDebInfo LLVM 3.9.1 (X86 targets only) on Win64, LLVM linked statically: +86 KB (25.2M vs. 25.3M).

For invoking MS tools such as link.exe and lib.exe, which require
compatible PATH, LIB, LIBPATH etc.

We previously wrapped the invokation of the tool with a batch file taking
care of setting up the environment and then calling the actual tool.

I changed this to first invoke another batch file setting up its
environment and then dumping all environment variables to a file. LDC then
parses this file and updates its own environment variables. Later spawned
child processes then inherit the updated environment, and the tools will
be located by LLVM in updated PATH.

This allows LDC to keep track of the used Visual C++ installation (and
could so set up additional runtime libs required since VS 2015, something
we would have needed some time back when we still supported VS 2013). It's
also required as a prerequisite for integrating LLD as in-process linker
on Windows.

I quickly looked into the option of setting up the environment manually,
but the MS batch files are full of quirks, mixtures of registry and
file-system lookups, checking for existence of misc. headers to filter out
bogus installations etc. With VS 2017, there's nothing in the registry at
all anymore (at least for the Build Tools); MS expose a COM interface for
querying the VS installer... But at least they still provide the batch
files.
@kinke
Copy link
Member Author

kinke commented Mar 13, 2017

The 3rd commit seems to work fine (has to be tested manually, AppVeyor uses a preset environment) and paves the way for integrating LLD. Enough for tonight though. ;)

kinke added 4 commits March 13, 2017 23:03
And get rid of redundant cmdline option -archiver.
And warn if no Visual C++ installation is detected, similar to the now
suppressed warning issued by the batch file.
@kinke kinke changed the title [WIP] Enable cross-static-lib generation for LLVM 3.9+ Enable cross-static-lib generation for LLVM 3.9+ Mar 13, 2017
@kinke
Copy link
Member Author

kinke commented Mar 14, 2017

Interesting - this time the spurious OSX failure/segfault wasn't core.thread, but std.net.curl; first time I see that.

@kinke kinke mentioned this pull request Mar 18, 2017
@kinke
Copy link
Member Author

kinke commented Mar 25, 2017

Any concerns? To me, this is currently mostly a shortcut for guys having to cross-link externally. Handling a single static lib instead of a multitude of objects is just more convenient. And for MSVC targets, I noticed that the static lib file size for a Phobos-hello-world is reduced by a very rough 10% [IIRC] compared to VS 2015 lib.exe (for both 32/64-bit targets).

@kinke kinke added this to the 1.3.0 milestone Mar 27, 2017
@kinke kinke merged commit 1dfe11c into ldc-developers:master Apr 8, 2017
@kinke kinke deleted the crossLib branch April 8, 2017 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant