[cfe-dev] libcxx and weak attribute

Nico Rieck nico.rieck at gmail.com
Fri Sep 13 12:42:17 PDT 2013


On 13.09.2013 18:49, Reid Kleckner wrote:
> Maybe Rui knows more about how Microsoft does this.  He had to implement
> some weak symbol fallback stuff in lld to link the Visual C++ runtime.  I
> wonder if operator new was the feature that required this functionality.

They don't do anything special because the linker can resolve functions 
even if they aren't decorated with dllimport. So if a local definition 
is not present the linker picks up the exported one from the runtime 
DLL. The last patch wrt visibility already takes care of not decorating 
them with dllimport (but dllexport when building). It should be 
sufficient here to just drop the weak attribute for MSVC.

With COFF's weak externals it's possible to provide weak variants but 
this requires linking in the object files directly, usually by merging 
them into the import library. MSVC doesn't provide any means to produce 
such symbols so it's irrelevant there. Clang with D1309 can and this is 
what I've done locally in libc++abi (though I'm not sure if it's worth 
the ugly CMake contortions...).

-Nico



More information about the cfe-dev mailing list