Bug 17196 - .rsrc section from archive members are ignored (all Windows targets)
Summary: .rsrc section from archive members are ignored (all Windows targets)
Status: RESOLVED NOTABUG
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-24 13:31 UTC by Benjamin Gerard
Modified: 2022-08-03 11:01 UTC (History)
2 users (show)

See Also:
Host:
Target: *-*-mingw32 *-pc-cygwin
Build:
Last reconfirmed:


Attachments
simple example project (30.04 KB, application/x-xz)
2014-07-24 13:31 UTC, Benjamin Gerard
Details
Modified test case that shows how to use a symbolic workaround (1.45 KB, application/force-download)
2014-08-26 10:31 UTC, Nick Clifton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Gerard 2014-07-24 13:31:55 UTC
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
Comment 1 Nick Clifton 2014-08-26 10:30:32 UTC
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
Comment 2 Nick Clifton 2014-08-26 10:31:15 UTC
Created attachment 7759 [details]
Modified test case that shows how to use a symbolic workaround
Comment 3 Benjamin Gerard 2014-08-26 12:03:20 UTC
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
Comment 4 Alan Modra 2022-08-03 11:01:50 UTC
.