From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mumit Khan To: gas2@cygnus.com Subject: i386-pe named linkonce section switching problem Date: Wed, 02 Sep 1998 08:56:00 -0000 Message-id: <9809021556.AA06709@modi.xraylith.wisc.edu> X-SW-Source: 1998/msg00214.html Platform : i386-pe (mingw32, cygwin32, etc) binutils : everything upto and including 980830 compiler : egcs-1.1 The following C++ code shows an odd problem with switching named linkonce sections within the same object file, and such code shows up in C++ with jump tables. Essentially, we lose the linkonce directive after the switch. If you compile the following without optimization (ie., no inlining), then in the assembly output of 'func(char)', the compiler generates the initial code in section '.text$func__Fc' marked linkonce; then it switches to .text (we're not using .rdata for x86-win32 yet) for the jump table and switches back to .text$func__Fc for the rest. In the process of switching back, the linkonce is lost and the linker finds multiple definitions if the inline function is included elsewere as well. If I add a ``.linkonce discard'' to the second .section .text$func__Fc when it switches back, the linkonce is preserved, but the final executable crashes. Any ideas on a fix? Regards, Mumit ======================= bug.cc ========================== inline int func(char c) { switch (c) { case 'a':return 1; case 't':return 2; case 'g':return 3; case 'c':return 4; case 'n':return 5; } } int func2(char c) { return func(c); } ======================= build ========================== % i386-mingw32-gcc bug.cc ============== nm output =========================================== bug.o: file format pe-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000080 00000000 00000000 000000b4 2**2 CONTENTS, ALLOC, LOAD, RELOC, CODE 1 .data 00000000 00000000 00000000 00000000 2**2 ALLOC, LOAD, DATA 2 .bss 00000000 00000000 00000000 00000000 2**2 ALLOC 3 .text$func__Fc 00000060 00000000 00000000 00000134 2**2 CONTENTS, ALLOC, LOAD, RELOC, CODE ======================= bug.s ========================== .file "bug.cc" gcc2_compiled.: ___gnu_compiled_cplusplus: .text .align 4 .globl _func2__Fc .def _func2__Fc; .scl 2; .type 32; .endef _func2__Fc: pushl %ebp movl %esp,%ebp subl $16,%esp movl 8(%ebp),%eax movb %al,-1(%ebp) movsbl -1(%ebp),%eax pushl %eax call _func__Fc addl $4,%esp movl %eax,%edx movl %edx,%eax jmp L11 jmp L12 jmp L11 .p2align 4,,7 L12: L11: leave ret .section .text$func__Fc,"x" .linkonce discard .align 4 .globl _func__Fc .def _func__Fc; .scl 2; .type 32; .endef _func__Fc: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax movb %al,%dl movb %dl,%cl addb $-97,%cl movsbl %cl,%eax cmpl $19,%eax ja L2 movl L8(,%eax,4),%eax jmp *%eax .p2align 4,,7 .text L8: .long L3 .long L2 .long L6 .long L2 .long L2 .long L2 .long L5 .long L2 .long L2 .long L2 .long L2 .long L2 .long L2 .long L7 .long L2 .long L2 .long L2 .long L2 .long L2 .long L4 .section .text$func__Fc,"x" .p2align 4,,7 L3: movl $1,%eax jmp L1 .p2align 4,,7 L4: movl $2,%eax jmp L1 .p2align 4,,7 L5: movl $3,%eax jmp L1 .p2align 4,,7 L6: movl $4,%eax jmp L1 .p2align 4,,7 L7: movl $5,%eax jmp L1 .p2align 4,,7 L9: L2: jmp L10 jmp L1 .p2align 4,,7 L10: L1: leave ret .def _func__Fc; .scl 2; .type 32; .endef =======================================================================