[Bug regression/40905] New: GCC creates invalid executable with auto-imported DLL and __attribute__((cold))

ramiro dot polla at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jul 29 16:07:00 GMT 2009


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



More information about the Gcc-bugs mailing list