This is an archive of the discontinued LLVM Phabricator instance.

Fix static link on debian
Needs ReviewPublic

Authored by espindola on Nov 21 2017, 3:12 PM.

Details

Reviewers
tra
beanz
rnk
Summary

On fedora based distros libpthread.a has a single .o file created with ld -r. That means that just one reference will pull the entire library.

On debian based systems that is not the case and we need whole archive when static linking.

Without this a static linked lld will crash on startup. It calls std::thread functions which try to call the corresponding pthread_* function but fail because they use a weak reference to pthread_* which is resolved to 0.

Diff Detail

Event Timeline

rafael created this revision.Nov 21 2017, 3:12 PM

Only use whole-archive on static builds.

beanz edited edge metadata.Nov 27 2017, 10:16 AM

I don't see anything wrong with this patch as a workaround, but it seems like there might be a bigger issue here.

Is there a reason why std::thread is implemented with weak references to pthread? Is this libstdc++'s implementation or libcxx? Should we consider changes to the clang driver as well?

It's undesirable for user code that is using std::thread to require the user to list pthread as a dependency, and even worse if the pthread library needs to be linked with extra flags.

espindola commandeered this revision.Feb 22 2018, 10:15 AM
espindola added a reviewer: rafael.

ping