On 06/10/2016 10:56 AM, Andrew Burgess wrote:
The global flag `user_defined_section_attribute' is set while parsing C
code when the section attribute is encountered. The flag is set when
anything has the section attribute applied to it, functions or data.
The only place this global was used was within the gate function for
partitioning blocks (pass_partition_blocks::gate), however, the
partitioning is done during compilation, while the flag is set earlier,
during the parsing. The flag is then cleared again during the final
compilation pass.
The result is that if any function or data has a section attribute then
the flag will be set to true during the file parse pass. The first
compiled function will then skip the partition-blocks pass, and the flag
will be set back to false during the final-pass on the first function.
After then, the flag is never set to true again.
The guarding of the partition-blocks pass does not appear to be
necessary, given that applying a section attribute correctly
overrides the hot/cold section partitioning (this is taken care if in
varasm.c).
gcc/ChangeLog:
* gcc/bb-reorder.c: Remove 'toplev.h' include.
(pass_partition_blocks::gate): No longer check
user_defined_section_attribute.
* gcc/c-family/c-common.c (handle_section_attribute): No longer
set user_defined_section_attribute.
* gcc/final.c (rest_of_handle_final): Likewise.
* gcc/toplev.c: Remove definition of user_defined_section_attribute.
* gcc/toplev.h: Remove declaration of
user_defined_section_attribute.
user_defined_section_attribute was introduced as part of the hot/cold
partitioning changes.
https://gcc.gnu.org/ml/gcc-patches/2004-07/msg01545.html
What's supposed to happen is hot/cold partitioning is supposed to be
turned off for the function which has the a user defined section
attribute.
So proper behaviour is to set the flag to true when the attribute is
parsed and turn it off when we're finished with the current function.
The gate for hot/cold partitioning should check the value of the flag
and avoid hot/cold partitioning when the flag is true.
So AFAICT everything is working as it should. Keep in mind that
multiple functions might have user defined section attributes.
So what might be better to do here is introduce a test to verify proper
behavior.
Jeff