[cfe-dev] Recent changes regarding section type conflicts and #pragma clang section

Bruno De Fraine via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 9 05:05:49 PDT 2020


Hello Lucas,

We observe two issues regarding your commits "[Clang][Sema] Capturing section type conflicts between #pragma clang section":
https://github.com/llvm/llvm-project/commit/0dac639f285a53dffe3239ec5561fa0fc2da0daf
https://github.com/llvm/llvm-project/commit/9d39df03a984ff4bed7d441a110d44976a8ab21b

A first observation is that once a section has been used as bss argument in a #pragma clang section, it is no longer possible to use this section in an explicit section annotation on a variable, even if this variable is zero-initialized:
https://godbolt.org/z/oiNHk3

[ In contrast, for a section used as the rodata argument, you *can* still do this, provided that the variable is "const":
https://godbolt.org/z/wJvYiW ]

The problem for bss sections seems to be related to the newly introduced "PSF_ZeroInit" flag?

A second issue is that #pragma clang section provided a way to assign multiple variables to the same data section, mixing const, non-const and zero-initialized variables. When using an explicit section attribute, clang and gcc disallow to use the same section for const and non-const variables: https://godbolt.org/z/S76vKm (but you can mix zero-initialized and non-zero-initialized variables)

An implicit section annotation using #pragma clang section allowed to work around this, by specifying the same data section in the pragma:

              #pragma clang section data="mydata" bss="mydata" rodata="mydata"

This is an example using clang-10: https://godbolt.org/z/vxty7T

This is now rejected, and granted, it was an abuse of the #pragma clang section. But is it not valid to assign both const and non-const variables to the same data section? Either with an explicit annotation or implicit?

Regards,
Bruno De Fraine

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200609/55add597/attachment.html>


More information about the cfe-dev mailing list