Ok. Jakub Jelinek <ja...@redhat.com> wrote:
Hi! On various targets we emit thunks into the same section as the corresponding method they are thunking to. Unfortunately, the thunk_fndecl had a DECL_COMDAT_GROUP set earlier to the thunk name, which results in assembly like: .section .text._ZN1TI1WI1XEE1hEP1A,"axG",@progbits,_ZThn8_N1TI1WI1XEE1hEP1A,comdat .weak _ZThn8_N1TI1WI1XEE1hEP1A .type _ZThn8_N1TI1WI1XEE1hEP1A, @function _ZThn8_N1TI1WI1XEE1hEP1A: .LFB4: .cfi_startproc subq $8, %rdi jmp .LTHUNK0 .cfi_endproc .LFE4: .size _ZThn8_N1TI1WI1XEE1hEP1A, .-_ZThn8_N1TI1WI1XEE1hEP1A .align 2 .weak _ZN1TI1WI1XEE1hEP1A .type _ZN1TI1WI1XEE1hEP1A, @function _ZN1TI1WI1XEE1hEP1A: .LFB3: .cfi_startproc subq $40, %rsp .cfi_def_cfa_offset 48 movl (%rsi), %edx decl %edx cmpl $4, %edx ja .L3 movq 8(%rsi), %rax jmp *.L8(,%rdx,8) .section .rodata._ZN1TI1WI1XEE1hEP1A,"aG",@progbits,_ZN1TI1WI1XEE1hEP1A,comdat .align 8 .align 4 .L8: .quad .L4 Note the .text._ZN1TI1WI1XEE1hEP1A section uses incorrectly _ZThn8_N1TI1WI1XEE1hEP1A comdat group instead of _ZN1TI1WI1XEE1hEP1A, but e.g. the .rodata section for it already uses the right comdat group name, therefore e.g. if the same method is compiled with different optimization options with no need for .rodata in another CU and that CU's _ZThn8_N1TI1WI1XEE1hEP1A would be picked and this CU's _ZN1TI1WI1XEE1hEP1A, it will fail to link. This patch makes sure it uses the right thunk name. When mixing 4.6 compiled objects compiled before/after this patch, if just the .text section is used, I think the worst thing that can happen is that both comdat groups stay but as the symbols are weak, it will just result in larger code. If more than one section is used for the method+thunks and mixed comdat groups were used before, it was a problem already before. On the trunk this issue went away with Honza's cgraph thunk reorg, the make_decl_one_only for the thunk's comdat group is gone and it does cgraph_add_to_same_comdat_group. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for 4.6? Maybe for 4.5 also afterwards (4.4 wasn't emitting comdat groups). 2011-09-07 Jakub Jelinek <ja...@redhat.com> PR c++/50255 * method.c (use_thunk): If emitting thunk into the same section as function, use the same DECL_COMDAT_GROUP as well. --- gcc/cp/method.c.jj 2011-05-19 11:48:00.000000000 +0200 +++ gcc/cp/method.c 2011-09-07 17:15:37.000000000 +0200 @@ -360,6 +360,8 @@ use_thunk (tree thunk_fndecl, bool emit_ /* Output the thunk into the same section as function. */ DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function); + if (DECL_COMDAT_GROUP (function)) + make_decl_one_only (thunk_fndecl, DECL_COMDAT_GROUP (function)); } } Jakub