linker (binutils ld) is unable to resolve weak symbol, depends on object file order

JonY 10walls@gmail.com
Fri Jun 7 11:22:00 GMT 2019


On 6/7/19 10:04 AM, Michael Haubenwallner wrote:
> Hi,
> 
> so I'm encountering a strange problem related to object file order passed to
> the linker, with any binutils and gcc version available to setup-x86_64.exe:
> 
> $ cat weak-func.c
> extern void weakfunc() __attribute__((weak));
> void weakfunc() {}
> 
> $ cat weak-main.c
> extern void weakfunc() __attribute__((weak));
> int main() { weakfunc(); }
> 
> $ gcc -o weak.exe weak-func.c weak-main.c
> SUCCESS
> 
> But then, changing the order of input files on the command line does break
> (does work on Linux of course):
> 
> $ gcc -o weak.exe weak-main.c weak-func.c
> /usr/lib/gcc/x86_64-pc-cygwin/8.3.0/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccIthYHe.o:weak-main.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `weakfunc'
> collect2: error: ld returned 1 exit status
> 
> So the difference is that the object providing weakfunc is passed to
> the linker after the object requiring weakfunc.
> 
> Attached is the weak-func.sh script that does perform these commands.
> 
> Thanks!
> /haubi/
> 

Unfortunately, PE doesn't really have a concept of weak symbols like
ELF, and is known to be broken in binutils.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20190607/c00b1ba9/attachment.sig>


More information about the Cygwin mailing list