From: Mumit Khan <khan@xraylith.wisc.edu>
To: gas2@cygnus.com
Subject: i386-pe named linkonce section switching problem
Date: Wed, 02 Sep 1998 08:56:00 -0000 [thread overview]
Message-ID: <9809021556.AA06709@modi.xraylith.wisc.edu> (raw)
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
=======================================================================
next reply other threads:[~1998-09-02 8:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-09-02 8:56 Mumit Khan [this message]
1998-09-05 16:02 ` Ian Lance Taylor
1998-09-06 15:29 ` Mumit Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9809021556.AA06709@modi.xraylith.wisc.edu \
--to=khan@xraylith.wisc.edu \
--cc=gas2@cygnus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).