This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Make -print-libgcc-file-name print compiler-rt lib when used
ClosedPublic

Authored by mgorny on Oct 6 2016, 11:44 AM.

Details

Summary

Make the -print-libgcc-file-name option print an appropriate compiler
runtime library, that is libgcc.a if gcc runtime is used
and an appropriate compiler-rt library if that runtime is used.

The main use for this is to allow linking executables built with
-nodefaultlibs (e.g. to avoid linking to the standard C++ library) to
the compiler runtime library, e.g. using:

clang++ ... -nodefaultlibs $(clang++ ... -print-libgcc-file-name)

in which case currently a program built like this linked to the gcc
runtime unconditionally. The patch fixes it to use compiler-rt libraries
instead when compiler-rt is the active runtime.

Diff Detail

Event Timeline

mgorny updated this revision to Diff 73829.Oct 6 2016, 11:44 AM
mgorny retitled this revision from to [Driver] Make -print-libgcc-file-name print compiler-rt lib when used .
mgorny updated this object.
mgorny added a reviewer: ddunbar.
mgorny added a subscriber: cfe-commits.
bruno added a reviewer: bruno.Oct 6 2016, 1:51 PM
bruno added a subscriber: bruno.

Testcase?

docs/CommandGuide/clang.rst
398

You can probably drop the "appropriately"

include/clang/Driver/Options.td
1865

Same here

mgorny updated this revision to Diff 73855.Oct 6 2016, 2:43 PM
mgorny marked 2 inline comments as done.

Updated the docs. I'll look into the test case tomorrow.

mgorny updated this revision to Diff 73887.Oct 7 2016, 12:04 AM

A simple test case included.

bruno accepted this revision.Oct 7 2016, 9:38 AM
bruno edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 7 2016, 9:38 AM

Thanks for the review.

This revision was automatically updated to reflect the committed changes.

It seems that my test doesn't work on Darwin, and I should exclude the libgcc part there. Do you happen to have any suggestion how to do that?

I'm going to wait for other buildbots to finish to see if I haven't broken any other platform, then revert it and look for a proper way to restrict the tests.

mgorny reopened this revision.Oct 7 2016, 1:14 PM
This revision is now accepted and ready to land.Oct 7 2016, 1:14 PM
mgorny planned changes to this revision.Oct 7 2016, 1:14 PM

Reverted, I need to update it to run libgcc part of the test only on platforms supporting that.

mgorny updated this revision to Diff 73979.Oct 7 2016, 1:28 PM
mgorny edited edge metadata.
mgorny removed rL LLVM as the repository for this revision.
This revision is now accepted and ready to land.Oct 7 2016, 1:28 PM
mgorny requested a review of this revision.Oct 7 2016, 1:29 PM
mgorny edited edge metadata.

I have updated the patch to include a feature check for platforms rejecting -rtlib=libgcc and split the test appropriately. Could you re-review, please?

mgorny updated this revision to Diff 74062.Oct 9 2016, 2:31 AM
mgorny added a reviewer: ggreif.

Including a fix for montavista toolchain checks that miss passing -rtlib= and therefore could fail depending on DEFAULT_* value.

mgorny updated this revision to Diff 74063.Oct 9 2016, 2:40 AM

I'm sorry, I mixed branches up. Here's the correct patch with both updates.

phosek added a subscriber: phosek.Oct 10 2016, 12:30 AM

I have submitted the same change D25256 a few days ago but this one seems to be getting more traction so I'm going to abandon mine in favor of this one.

lib/Driver/Driver.cpp
1000

I think you should use TC.getCompilerRT rather than TC.getCompilerRTArgString here.

mgorny marked an inline comment as done.Oct 10 2016, 2:39 AM
mgorny updated this revision to Diff 74111.Oct 10 2016, 2:41 AM

Updated to use TC.getCompilerRT().

ggreif accepted this revision.Oct 10 2016, 5:26 AM
ggreif edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Oct 10 2016, 5:26 AM

Thanks for the review.

bruno accepted this revision.Oct 10 2016, 9:32 AM
bruno edited edge metadata.

LGTM

mgorny closed this revision.Oct 10 2016, 10:01 AM

r283746