Hi, I would like this patch reviewed and considered for commit when Stage 1 is active again.
Patch Description: A C++ thunk's section name is set to be the same as the original function's section name for which the thunk was created in order to place the two together. This is done in cp/method.c in function use_thunk. However, with function reordering turned on, the original function's section name can change to something like ".text.hot.<orginal>" or ".text.unlikely.<original>" in function default_function_section in varasm.c based on the node count of that function. The thunk function's section name is not updated to be the same as the original here and also is not always correct to do it as the original function can be hotter than the thunk. I have created a patch to not name the thunk function's section to be the same as the original function when function reordering is enabled. Thanks Sri
A C++ thunk's section name is set to be the same as the original function's section name for which the thunk was created in order to place the two together. This is done in cp/method.c in function use_thunk. However, with function reordering turned on, the original function's section name can change to something like ".text.hot.<orginal>" or ".text.unlikely.<original>" in function default_function_section in varasm.c based on the node count of that function. The thunk function's section name is not updated to be the same as the original here and also is not always correct to do it as the original function can be hotter than the thunk. I have created a patch to not name the thunk function's section to be the same as the original function when function reordering is enabled. Index: testsuite/g++.dg/thunk_section_name.C =================================================================== --- testsuite/g++.dg/thunk_section_name.C (revision 0) +++ testsuite/g++.dg/thunk_section_name.C (revision 0) @@ -0,0 +1,30 @@ +/* { dg-require-named-sections "" } */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-reorder-blocks-and-partition -ffunction-sections" } */ + +class base_class_1 +{ +public: + virtual void vfn () {} +}; + +class base_class_2 +{ +public: + virtual void vfn () {} +}; + +class need_thunk_class : public base_class_1, public base_class_2 +{ +public: + virtual void vfn () {} +}; + +int main (int argc, char *argv[]) +{ + base_class_1 *c = new need_thunk_class (); + c->vfn(); + return 0; +} + +/* { dg-final { scan-assembler "\.text\._ZThn8_N16need_thunk_class3vfnEv" } } */ Index: cp/method.c =================================================================== --- cp/method.c (revision 207517) +++ cp/method.c (working copy) @@ -362,8 +362,10 @@ use_thunk (tree thunk_fndecl, bool emit_p) { resolve_unique_section (thunk_fndecl, 0, flag_function_sections); - /* Output the thunk into the same section as function. */ - DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function); + /* Output the thunk into the same section as function if function reordering + is not switched on. */ + if (!flag_reorder_functions) + DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function); } }