This is an archive of the discontinued LLVM Phabricator instance.

[Windows] Put init_seg(compiler/lib) in llvm.global_ctors
ClosedPublic

Authored by aeubanks on Aug 15 2022, 11:18 AM.

Details

Summary

Currently we treat initializers with init_seg(compiler/lib) as similar
to any other init_seg, they simply have a global variable in the proper
section (".CRT$XCC" for compiler/".CRT$XCL" for lib) and are added to
llvm.used. However, this doesn't match with how LLVM sees normal (or
init_seg(user)) initializers via llvm.global_ctors. This
causes issues like incorrect init_seg(compiler) vs init_seg(user)
ordering due to GlobalOpt evaluating constructors, and the
ability to remove init_seg(compiler/lib) initializers at all.

Currently we use 'A' for priorities less than 200. Use 200 for init_seg(compiler) (".CRT$XCC") and 400 for init_seg(lib) (".CRT$XCL"), which do not append the priority to the section name. Priorities between 200 and 400 use ".CRT$XCC${Priority}". This allows for some wiggle room for people/future extensions that want to add initializers between compiler and lib.

Fixes #56922

Diff Detail

Event Timeline

aeubanks created this revision.Aug 15 2022, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2022, 11:18 AM
aeubanks requested review of this revision.Aug 15 2022, 11:18 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 15 2022, 11:18 AM
rnk added a comment.Aug 15 2022, 12:59 PM

Please update the AttrDocs.td file to document the relationship between init_seg and init_priority on Windows.

Can we increase the threshold for library so that we can insert initializers between compiler and library in the future? Maybe Microsoft will come out with some new semantic level that goes between C and L.

This is my proposed mapping:

  • 101-199: A${N}, for very early things (ASan, I think)
  • 200: C, compiler
  • 201-399: C${N}, between compiler and library
  • 400: L, library
  • 401-65534: T${N}, after library, before user
  • U: user, 65535
aeubanks updated this revision to Diff 452798.Aug 15 2022, 1:50 PM

use 400 for lib, update documentation

aeubanks edited the summary of this revision. (Show Details)Aug 15 2022, 1:53 PM
rnk accepted this revision.Aug 15 2022, 3:19 PM

lgtm, thanks!

This revision is now accepted and ready to land.Aug 15 2022, 3:19 PM
This revision was landed with ongoing or failed builds.Aug 16 2022, 8:25 AM
This revision was automatically updated to reflect the committed changes.