This is an archive of the discontinued LLVM Phabricator instance.

MS Compat: mark globals emitted in read-only sections const
ClosedPublic

Authored by hans on Oct 15 2014, 7:23 PM.

Details

Summary

They cannot be written to, so marking them const makes sense and may improve optimisation.

The actual motivation for doing this is to fix this kind of link error when compiling ATL:
warning LNK4254: section 'ATL' (C0000040) merged into '.rdata' (40000040) with different attributes

The warning comes from ATL headers putting variables in a special section which only has the "read" flag set. The flags to #pragma section don't actually affect the generated IR. However, if all variables in the section are const, the section becomes read-only.

I'm happy to break out the move of SectionFlags from Sema to ASTContext in a separate patch.

Diff Detail

Repository
rL LLVM

Event Timeline

hans updated this revision to Diff 14975.Oct 15 2014, 7:23 PM
hans retitled this revision from to MS Compat: mark globals emitted in read-only sections const.
hans updated this object.
hans edited the test plan for this revision. (Show Details)
hans added reviewers: majnemer, rnk.
hans added subscribers: Unknown Object (MLST), hansw.
majnemer accepted this revision.Oct 16 2014, 12:05 AM
majnemer edited edge metadata.
This revision is now accepted and ready to land.Oct 16 2014, 12:05 AM
hans closed this revision.Oct 16 2014, 2:03 PM
hans updated this revision to Diff 15048.

Closed by commit rL219960 (authored by @hans).