Created attachment 7723 [details] simple example project The .rsrc section is discarded by ld when it comes from an archive (.a) member for all tested Windows targets (cygwin and mingw). Included an example project: $ make CC=i686-pc-mingw32 info > i686-pc-mingw32-gcc -m32 -mwin32 -mwindows -c -o rsrcbug.o rsrcbug.c > i686-pc-mingw32-windres -o resource.o resource.rc > i686-pc-mingw32-gcc -m32 -mwin32 -mwindows -o rsrcbug-ok.exe rsrcbug.o resource.o > i686-pc-mingw32-ar rc resource.a resource.o > i686-pc-mingw32-ranlib resource.a > i686-pc-mingw32-gcc -m32 -mwin32 -mwindows -o rsrcbug-failed.exe rsrcbug.o resource.a > > ************* rsrcbug-ok.exe > Entry 2 0000b000 0000010c Resource Directory [.rsrc] > 8 .rsrc 0000010c 0040b000 0040b000 00004800 2**2 > [ 50](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x0000003f rsrcbug.c > [945](sec 9)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 .rsrc > > ************* rsrcbug-failed.exe > Entry 2 00000000 00000000 Resource Directory [.rsrc] > [ 50](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x0000003f rsrcbug.c > > ************* resource.o > Entry 2 00000000 00000000 Resource Directory [.rsrc] > 0 .rsrc 0000010c 00000000 00000000 0000003c 2**2 > [ 0](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 .rsrc > RELOCATION RECORDS FOR [.rsrc]: > 00000048 rva32 .rsrc > > ************* rsrcbug.o > Entry 2 00000000 00000000 Resource Directory [.rsrc] > [ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x00000000 rsrcbug.c > > ************* resource.a > Entry 2 00000000 00000000 Resource Directory [.rsrc] > 0 .rsrc 0000010c 00000000 00000000 0000003c 2**2 > [ 0](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 .rsrc > RELOCATION RECORDS FOR [.rsrc]: > 00000048 rva32 .rsrc
Hi Benjamin, This is not a bug. It is a feature, or mis-feature if you prefer. The problem is that the resource.o file in the resource.a archive only contains a .rsrc section. It does not contain any symbols. The linker only pulls object files out of an archive if they contain symbols that are needed by other objects in the link. So when you link rsrcbug.o with resource.a there are no unresolved symbols in rsrcbug.o and so nothing is pulled out of the archive. There are a couple of possible workarounds for this problem: * You could like with --whole-archive added before resource.a. This will force the linker to include the resource.o file even though nothing references it. Ie: i686-pc-mingw32-gcc -m32 -mwin32 -mwindows -o rsrcbug-failed.exe \ -Wl,--whole-archive rsrcbug.o resource.a -Wl,--no-whole-archive Of course this does negate one of the benefits of using archives - namely that normally only the files that your program needs are extracted from the library. * You could add a symbol to resource.o and then reference this symbol from rsrcbug.o. See the uploaded variation on your test archive for an example of how this can be done. Cheers Nick
Created attachment 7759 [details] Modified test case that shows how to use a symbolic workaround
It makes perfect sense. I'll see which workaround suit my case better. Thank you for your time and sorry for the false alert. Cheers, Ben
.