This is an archive of the discontinued LLVM Phabricator instance.

Don't dllexport reference temporaries
ClosedPublic

Authored by hans on Feb 4 2022, 2:24 AM.

Details

Summary

Even if the reference itself is dllexport, the temporary should not be -- in fact, we're already giving it internal linkage, so dllexporting it is not just wasteful, but will fail to link, as in the example below:

$ cat /tmp/a.cc
void _DllMainCRTStartup() {}
const int __declspec(dllexport) &foo = 42;

$ clang-cl -fuse-ld=lld /tmp/a.cc /Zl /link /dll /out:a.dll
lld-link: error: <root>: undefined symbol: int const &foo::$RT1

Diff Detail

Event Timeline

hans requested review of this revision.Feb 4 2022, 2:24 AM
hans created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2022, 2:24 AM
mstorsjo accepted this revision.Feb 4 2022, 3:23 AM

LGTM, seems reasonable!

This revision is now accepted and ready to land.Feb 4 2022, 3:23 AM
This revision was landed with ongoing or failed builds.Feb 4 2022, 7:34 AM
This revision was automatically updated to reflect the committed changes.