public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
@ 2009-07-29 16:07 ramiro dot polla at gmail dot com
2009-07-29 16:10 ` [Bug target/40905] " pinskia at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: ramiro dot polla at gmail dot com @ 2009-07-29 16:07 UTC (permalink / raw)
To: gcc-bugs
GCC creates invalid executable when an array from one DLL is accessed from
another DLL in a function with __attribute__((cold)).
----------
$ cat dll1.c
int foo[2] = {0, 1};
$ cat dll2.c
extern int foo[2];
__attribute__((cold))
int bar(void)
{
return foo[1];
}
$ cat main.c
int bar(void);
int main()
{
bar();
return 0;
}
$ cat Makefile
CC=i686-mingw32-gcc-4.4.1
all:
$(CC) -shared -o dll1.dll dll1.c
$(CC) -shared -o dll2.dll dll2.c dll1.dll -O2
$(CC) -o main.exe main.c dll1.dll dll2.dll
$ make
i686-mingw32-gcc-4.4.1 -shared -o dll1.dll dll1.c
i686-mingw32-gcc-4.4.1 -shared -o dll2.dll dll2.c dll1.dll -O2
Info: resolving _foo by linking to __imp__foo (auto-import)
/opt/i686-mingw32/lib/gcc/i686-mingw32/4.4.1/../../../../i686-mingw32/bin/ld:
warning: auto-importing has been activated without --enable-auto-import
specified on the command line.
This should work unless it involves constant data structures referencing
symbols from auto-imported DLLs.
i686-mingw32-gcc-4.4.1 -o main.exe main.c dll1.dll dll2.dll
$ ./main.exe
err:module:attach_process_dlls "dll2.dll" failed to initialize, aborting
err:module:LdrInitializeThunk Main exe initialization for
L"Z:\\home\\ramiro\\code\\smalls\\gcc_bug\\main.exe" failed, status c0000005
----------
This error message is from wine, but it also fails on Windows XP.
The auto-import warning seems to fit perfectly here but the same test doesn't
fail at -O1, or if __attribute__((cold)) is removed.
--
Summary: GCC creates invalid executable with auto-imported DLL
and __attribute__((cold))
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: regression
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ramiro dot polla at gmail dot com
GCC target triplet: i686-mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
@ 2009-07-29 16:10 ` pinskia at gcc dot gnu dot org
2009-07-30 3:44 ` ramiro dot polla at gmail dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-07-29 16:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-07-29 16:10 -------
IIRC the cold attribute does a couple of things. The only thing I think that
might cause this is putting it into a .text.cold section.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|regression |target
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
2009-07-29 16:10 ` [Bug target/40905] " pinskia at gcc dot gnu dot org
@ 2009-07-30 3:44 ` ramiro dot polla at gmail dot com
2009-07-30 3:59 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ramiro dot polla at gmail dot com @ 2009-07-30 3:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from ramiro dot polla at gmail dot com 2009-07-30 03:43 -------
I might be guessing wildly since I don't know that much about PE, but this is
what more I've found:
It crashes loading the dll in __pei386_runtime_relocator at address 65ec12a8:
65ec1290 <__pei386_runtime_relocator>:
65ec1290: 55 push %ebp
65ec1291: b9 28 40 ec 65 mov $0x65ec4028,%ecx
65ec1296: 89 e5 mov %esp,%ebp
65ec1298: eb 14 jmp 65ec12ae
<__pei386_runtime_relocator+0x1e>
65ec129a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
65ec12a0: 8b 51 04 mov 0x4(%ecx),%edx
65ec12a3: 8b 01 mov (%ecx),%eax
65ec12a5: 83 c1 08 add $0x8,%ecx
65ec12a8: 01 82 00 00 ec 65 add %eax,0x65ec0000(%edx)
65ec12ae: 81 f9 30 40 ec 65 cmp $0x65ec4030,%ecx
65ec12b4: 72 ea jb 65ec12a0
<__pei386_runtime_relocator+0x10>
65ec12b6: 5d pop %ebp
65ec12b7: c3 ret
In the same testcase compiled without -O2, I get the sole entry of
runtime_pseudo_reloc in __RUNTIME_PSEUDO_RELOC_LIST__ (the equivalent to
0x65ec4028) is:
addend = 0x00000004
target = 0x000011d5
and the .text section is:
0 .text 00000344 67701000 67701000 00000400 2**4
CONTENTS, ALLOC, LOAD, CODE, DATA
With -O2 it is:
addend = 0x00000004
target = 0x00002005
0 .text 00000334 65ec1000 65ec1000 00000600 2**4
CONTENTS, ALLOC, LOAD, CODE, DATA
1 .text.unlikely 0000000c 65ec2000 65ec2000 00000a00 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
Is it possible that it triggers the exception trying to write in text.unlikely
which is READONLY?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
2009-07-29 16:10 ` [Bug target/40905] " pinskia at gcc dot gnu dot org
2009-07-30 3:44 ` ramiro dot polla at gmail dot com
@ 2009-07-30 3:59 ` pinskia at gcc dot gnu dot org
2009-07-30 8:00 ` dannysmith at users dot sourceforge dot net
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-07-30 3:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2009-07-30 03:59 -------
Doesn't DLL source need to be compiled with -fPIC to allow it to work?
So what is happening is you are getting a runtime relocation inside the
.text.unlikely section which should not happen for DLLs I think ...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
` (2 preceding siblings ...)
2009-07-30 3:59 ` pinskia at gcc dot gnu dot org
@ 2009-07-30 8:00 ` dannysmith at users dot sourceforge dot net
2009-09-04 13:27 ` ktietz at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2009-07-30 8:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from dannysmith at users dot sourceforge dot net 2009-07-30 08:00 -------
(In reply to comment #2)
>
> Is it possible that it triggers the exception trying to write in text.unlikely
> which is READONLY?
>
Exactly. This is a linker, not a compiler issue. If you are using a
relatively recent binutils and mingw run time, the addition of the switch
-Wl,--enable-runtime-pseudo-reloc-v2 should get around the READONLY problem.
Otherwise, you could always just add __declspec (dllimport) to
extern int foo[2]; and so retain portability with the rest of the PE-COFF
world.
Danny
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
` (3 preceding siblings ...)
2009-07-30 8:00 ` dannysmith at users dot sourceforge dot net
@ 2009-09-04 13:27 ` ktietz at gcc dot gnu dot org
2009-09-12 10:56 ` ktietz at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ktietz at gcc dot gnu dot org @ 2009-09-04 13:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from ktietz at gcc dot gnu dot org 2009-09-04 13:27 -------
(In reply to comment #4)
> (In reply to comment #2)
>
> >
> > Is it possible that it triggers the exception trying to write in text.unlikely
> > which is READONLY?
> >
>
> Exactly. This is a linker, not a compiler issue. If you are using a
> relatively recent binutils and mingw run time, the addition of the switch
> -Wl,--enable-runtime-pseudo-reloc-v2 should get around the READONLY problem.
> Otherwise, you could always just add __declspec (dllimport) to
> extern int foo[2]; and so retain portability with the rest of the PE-COFF
> world.
>
> Danny
>
Right, this is a linker issue (or runtime issue of pseudo-relocation). But
newer mingw32's runtime uses new code for v1 relocations, too. So for it, this
issue should be solved, too.
So can we close this bug?
Cheers,
Kai
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
` (4 preceding siblings ...)
2009-09-04 13:27 ` ktietz at gcc dot gnu dot org
@ 2009-09-12 10:56 ` ktietz at gcc dot gnu dot org
2010-04-05 9:18 ` ktietz at gcc dot gnu dot org
2010-05-23 7:41 ` ktietz at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: ktietz at gcc dot gnu dot org @ 2009-09-12 10:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from ktietz at gcc dot gnu dot org 2009-09-12 10:55 -------
I added you to this thread, as you merged new pseudo-relocation code to
mingw.org's runtime.
--
ktietz at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dannysmith at users dot
| |sourceforge dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
` (5 preceding siblings ...)
2009-09-12 10:56 ` ktietz at gcc dot gnu dot org
@ 2010-04-05 9:18 ` ktietz at gcc dot gnu dot org
2010-05-23 7:41 ` ktietz at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: ktietz at gcc dot gnu dot org @ 2010-04-05 9:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from ktietz at gcc dot gnu dot org 2010-04-05 09:17 -------
(In reply to comment #6)
> I added you to this thread, as you merged new pseudo-relocation code to
> mingw.org's runtime.
>
As cygwin and mingw.org are supporting now new linker generated
runtime-pseudo-relocation, could you please confirm that your issue is solved.
I tested your issue and for me it works with recent version of cygwin/mingw.org
runtimes.
Kai
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/40905] GCC creates invalid executable with auto-imported DLL and __attribute__((cold))
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
` (6 preceding siblings ...)
2010-04-05 9:18 ` ktietz at gcc dot gnu dot org
@ 2010-05-23 7:41 ` ktietz at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: ktietz at gcc dot gnu dot org @ 2010-05-23 7:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from ktietz at gcc dot gnu dot org 2010-05-23 07:41 -------
As there is no feed-back for some time now. I've tested this issue with recent
mingw runtimes and the issue is solved.
As this isse is related to old pseudo-relocation and linker, and not related to
gcc itself, I close this bug as works-for-me.
--
ktietz at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WORKSFORME
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-05-23 7:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-29 16:07 [Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold)) ramiro dot polla at gmail dot com
2009-07-29 16:10 ` [Bug target/40905] " pinskia at gcc dot gnu dot org
2009-07-30 3:44 ` ramiro dot polla at gmail dot com
2009-07-30 3:59 ` pinskia at gcc dot gnu dot org
2009-07-30 8:00 ` dannysmith at users dot sourceforge dot net
2009-09-04 13:27 ` ktietz at gcc dot gnu dot org
2009-09-12 10:56 ` ktietz at gcc dot gnu dot org
2010-04-05 9:18 ` ktietz at gcc dot gnu dot org
2010-05-23 7:41 ` ktietz at gcc dot gnu dot org
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).