This is an archive of the discontinued LLVM Phabricator instance.

MS ABI: adding template static member in the linker directive section to make sure init function can be called before main.
ClosedPublic

Authored by jyu2 on Feb 12 2019, 4:57 PM.

Details

Summary

A MS only run time problem, because the init function for template static member is not getting called when the template static member is not reference. To be able to evoke the init function, MS put the template static member in the linker directive section, that cause init function gets call. As Reid suggest; add template static data member to llvm.used that cause compiler to emit a similar -include directive into the linker directive section.

The bug is report in:
//bugs.llvm.org/show_bug.cgi?id=40323

Diff Detail

Event Timeline

jyu2 created this revision.Feb 12 2019, 4:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2019, 4:57 PM
jyu2 retitled this revision from Fix runtime problem from //bugs.llvm.org/show_bug.cgi?id=40323 to MS ABI: adding template static member in the linker directive section to make sure init function can be called before main..Mar 18 2019, 10:03 AM
jyu2 edited the summary of this revision. (Show Details)
rnk added a comment.Mar 18 2019, 11:03 AM

Apparently I wrote this comment long ago and never hit send.

lib/CodeGen/CGDeclCXX.cpp
484

We might really want isOSBinFormatCOFF, since I think the same issue affects Windows Itanium with -OPT:REF and LLD.

rnk accepted this revision.Mar 18 2019, 11:21 AM

lgtm

lib/CodeGen/CGDeclCXX.cpp
484

On reflection, it's probably best not to mess with mingw for now. Let's just commit this as is.

This revision is now accepted and ready to land.Mar 18 2019, 11:21 AM
jyu2 added a comment.Mar 18 2019, 9:03 PM
In D58160#1433458, @rnk wrote:

lgtm

Thank you so much Reid!

jyu2 closed this revision.Apr 3 2019, 10:46 AM

Closed by commit rG0b28b8b09be7: Bug-40323: MS ABI adding template static member in the linker directive section… (authored by jyu2).