[PATCH] MS Compat: mark globals emitted in read-only sections const

Hans Wennborg hans at chromium.org
Wed Oct 15 19:23:48 PDT 2014


Hi majnemer, rnk,

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.

http://reviews.llvm.org/D5812

Files:
  include/clang/AST/ASTContext.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CodeGenModule.cpp
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaAttr.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGen/sections.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5812.14975.patch
Type: text/x-patch
Size: 9153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141016/e7dc7f2f/attachment.bin>


More information about the cfe-commits mailing list