* i386-pe named linkonce section switching problem
@ 1998-09-02 8:56 Mumit Khan
1998-09-05 16:02 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: Mumit Khan @ 1998-09-02 8:56 UTC (permalink / raw)
To: gas2
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
=======================================================================
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: i386-pe named linkonce section switching problem
1998-09-02 8:56 i386-pe named linkonce section switching problem Mumit Khan
@ 1998-09-05 16:02 ` Ian Lance Taylor
1998-09-06 15:29 ` Mumit Khan
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 1998-09-05 16:02 UTC (permalink / raw)
To: khan; +Cc: gas2
Date: Wed, 02 Sep 1998 10:56:13 -0500
From: Mumit Khan <khan@xraylith.wisc.edu>
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.
The appended patch appears to fix this problems.
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.
I doubt the patch would fix this problem.
Ian
Index: config/obj-coff.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gas/config/obj-coff.c,v
retrieving revision 1.155
diff -u -r1.155 obj-coff.c
--- obj-coff.c 1998/07/13 20:00:37 1.155
+++ obj-coff.c 1998/09/05 23:01:11
@@ -1214,6 +1214,12 @@
if (flags != SEC_NO_FLAGS)
{
+ flagword oldflags;
+
+ oldflags = bfd_get_section_flags (stdoutput, sec);
+ oldflags &= SEC_LINK_ONCE | SEC_LINK_DUPLICATES;
+ flags |= oldflags;
+
if (! bfd_set_section_flags (stdoutput, sec, flags))
as_warn (_("error setting flags for \"%s\": %s"),
bfd_section_name (stdoutput, sec),
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: i386-pe named linkonce section switching problem
1998-09-05 16:02 ` Ian Lance Taylor
@ 1998-09-06 15:29 ` Mumit Khan
0 siblings, 0 replies; 3+ messages in thread
From: Mumit Khan @ 1998-09-06 15:29 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gas2
On Sat, 5 Sep 1998, Ian Lance Taylor wrote:
>
> The appended patch appears to fix this problems.
>
[ patch deleted ]
I tried that already, and the example code simply crashes in etext(). I'm
not sure where to look at this point. Here's what I've found (after
applying your patch):
case 1: jump table in linkonce section. Doesn't work.
.section .text$func__Fc,"x"
.linkonce discard
.align 4
.globl _func__Fc
.#define _func__Fc; .scl 2; .type 32; .endef
_func__Fc:
# ...
.text # making it .section rdata doesn't help either.
# ...
.section .text$func__Fc,"x"
The section is marked linkonce correctly, but crash at etext() at
program startup.
case 2: other sections such .drectve in the middle does work.
Obviously, section switching while in a named section does work for
innocuous ones like .drectve, but not for anything like .text/.data/etc.
Any ideas where to look?
Regards,
Mumit
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-09-06 15:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-02 8:56 i386-pe named linkonce section switching problem Mumit Khan
1998-09-05 16:02 ` Ian Lance Taylor
1998-09-06 15:29 ` Mumit Khan
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).