Extremely slow linking with clang, ld from XCode 7.3

I just upgraded from XCode 7.2 to XCode 7.3. I have a moderately large C++ project that used to take a few seconds to link. With the new linker, the same project now takes multiple minutes to link.


This only happens with our debug builds. If I switch the compile flags from "-O0" to "-O2" (no other changes to any command-line arguments), linking goes back to its usual speed. ("-O1" is just as slow as "-O0".)


I ran the "Instruments" Time Profiler against "ld"; it's spending virtually all of its time in stack frames that start like this:


ld (4948)

Main Thread 0x3cd90

start

main

ld::passes::dedup::doPass(Options const&, ld::Internal&)

std::__1::unordered_map<ld::Atom const*, std::__1::vector<ld::Atom const*, std::__1::allocator<ld::Atom const*> >, ld::passes::dedup::atom_hashing, ld::passes::dedup::atom_equal, std::__1::allocator<std::__1::pair<ld::Atom const* const, std::__1::vector<ld::Atom const*, std::__1::allocator<ld::Atom const*> > > > >::operator[](ld::Atom const* const&)


Does this look familiar to anyone? Any suggestions?

Replies

Update: "-O0 -fvisibility-inlines-hidden" makes link times fast again. That's an adequate workaround for me for now, though I'd still be interested to understand the underlying problem / what changed in the latest release.

I ran into the exact same isse and the "-fvisibility-inlines-hidden" flag is not a good solution in my case: it causes lots of warnings about inconsistent linkage with a third party library that I can't rebuild ... Any update about this issue?

You can add "-Xlinker -no_deduplicate" to linker flags for debug builds. That's what Xcode do, but I don't know why ...