This is an archive of the discontinued LLVM Phabricator instance.

Add support for -rtlib option and -stdlib option to the mingw driver
ClosedPublic

Authored by martell on Jul 15 2015, 1:16 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

martell updated this revision to Diff 29819.Jul 15 2015, 1:16 PM
martell retitled this revision from to Add support for -rtlib option and -stdlib option to the mingw driver.
martell updated this object.
martell added a reviewer: yaron.keren.
martell updated this revision to Diff 29821.Jul 15 2015, 1:25 PM

Set libgcc and libstdc++ as default so this can be considered as a fix for the 3.7 branch :)

yaron.keren added a subscriber: cfe-commits.
rnk added inline comments.Jul 15 2015, 1:59 PM
tools/clang/lib/Driver/MinGWToolChain.cpp
206 ↗(On Diff #29821)

You don't need to override this, you can simply override GetDefaultRuntimeLibType() and leave the base class behavior for this.

tools/clang/lib/Driver/ToolChains.h
546–552 ↗(On Diff #29821)

So far as I can tell, none of these overrides have any functionality change other than creating a place for TODOs. I'd rather just wait until we're ready to change the behavior, and then we can see how to do it with the least duplication.

tools/clang/lib/Driver/Tools.cpp
9064 ↗(On Diff #29821)

Can't this just be AddRunTimeLibs() and then it won't require changing AddLibGCC?

9085 ↗(On Diff #29821)

ditto

martell updated this revision to Diff 29983.Jul 17 2015, 2:09 AM

Updated to address rnk's suggested changes

ping :)

tools/clang/lib/Driver/MinGWToolChain.cpp
158 ↗(On Diff #29821)

Not quite sure if using "v1" here is okay ?

206 ↗(On Diff #29821)

Ahh I see that function now.
This makes it easier :)

I don't see a GetDefaultCXXStdlibType maybe that is something that should be added after 3.7

tools/clang/lib/Driver/ToolChains.h
546–552 ↗(On Diff #29821)

I actually have the behavior changed in my builds, this makes it easier to change but your point makes perfect sense.
I can remove this part of the patch :)

tools/clang/lib/Driver/Tools.cpp
9064 ↗(On Diff #29821)

static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)

and

void MinGW::Linker::AddLibGCC(const ArgList &Args, ArgStringList &CmdArgs)

Are completely separate function and one is not belong to a class hierarchy so this isn't possible I don't think

The name change was done to clarify what exactly it was

yaron.keren edited edge metadata.Jul 20 2015, 12:26 AM

I just added support for Arch Linux to MinGWToolChain.cpp. It appears that all permutations of {"usr" "lib" "lib64" "gcc" gcc-ver Arch } for the mingw include and lib directories actually exist on the various platforms.

Anyhow please rebase the patch to the current SVN.

martell updated this revision to Diff 30156.Jul 20 2015, 7:37 AM
martell edited edge metadata.

Updated to latest SVN as requested by Yaron

rnk added inline comments.Jul 20 2015, 9:11 AM
tools/clang/lib/Driver/Tools.cpp
9087 ↗(On Diff #30156)

You still don't need this, see the static helper AddRunTimeLibs() in Tools.cpp. It already has all this logic, and shares it across tools. We should make the mingw linker tool use it, just like the gnutools linker does.

martell updated this revision to Diff 30221.Jul 20 2015, 5:39 PM

I hope this is what you meant rnk :)

Added a comment regarding libunwind

tools/clang/lib/Driver/Tools.cpp
2307 ↗(On Diff #30221)

Still not sure what way is the best location for installing libunwind is

lib/clang/3.8.0/lib/windows/libclang_rt.unwind-x86_64.a
lib/clang/3.8.0/lib/windows/libclang_rt.unwind-x86.a
etc
via
CmdArgs.push_back(Args.MakeArgString(getCompilerRT(TC, "unwind")));
or

lib/libunwind.a
via
CmdArgs.push_back("-lunwind");

Thoughts?

martell updated this revision to Diff 30310.Jul 21 2015, 7:20 PM

Changed the default to libgcc_eh so that we can get this merged.

We can deal with using a libunwind later.
Only a few days left to get this approved and merged in

martell updated this revision to Diff 30322.Jul 21 2015, 11:33 PM

Updated to latest svn.

After some hard testing on windows I discovered we do not need to pass the exception library when using libc++.dll because it is a shared library.

That is the reason why the code already contains
if (!TC.getTriple().isOSWindows())

since we don't handle a OPT_static_libgcc equivalent for compiler-rt
it makes more sense to leave this code alone

Please Review

Many Thanks
Martell

rnk accepted this revision.Jul 22 2015, 8:54 AM
rnk edited edge metadata.

I hope this is what you meant rnk :)

I see, your change was better as it was. I put back AddLibGCC and I'm going to commit it like that. Please test it and let me know if it still works, and then we can try to merge to 3.7.

This revision is now accepted and ready to land.Jul 22 2015, 8:54 AM
rnk added inline comments.Jul 22 2015, 8:55 AM
tools/clang/lib/Driver/Tools.cpp
7845 ↗(On Diff #30322)

I had to change this to Triple.isOSCygMing() to make the existing windows-cross toolchain driver test pass. It expected --as-needed to be passed along.

This revision was automatically updated to reflect the committed changes.
This comment was removed by martell.
tools/clang/lib/Driver/Tools.cpp
5 ↗(On Diff #30322)

This if specifically breaks mingw-w64

That's why I changed it to

TC.getTriple().isWindowsMSVCEnvironment()

13 ↗(On Diff #30322)

You sure you didn't revert all this by accident ?

the lib extension is now broken on mingw-w64 also ???

15 ↗(On Diff #30322)

ditto

Yup looks good to me.
Please ignore previous comment.
I dunno what phabricator is doing :)