* linker (binutils ld) is unable to resolve weak symbol, depends on object file order
@ 2019-06-07 10:04 Michael Haubenwallner
2019-06-07 11:22 ` JonY
0 siblings, 1 reply; 3+ messages in thread
From: Michael Haubenwallner @ 2019-06-07 10:04 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 979 bytes --]
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/
[-- Attachment #2: weak-func.sh --]
[-- Type: application/x-shellscript, Size: 373 bytes --]
[-- Attachment #3: Type: text/plain, Size: 219 bytes --]
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order
2019-06-07 10:04 linker (binutils ld) is unable to resolve weak symbol, depends on object file order Michael Haubenwallner
@ 2019-06-07 11:22 ` JonY
2019-06-07 11:58 ` Jon Turney
0 siblings, 1 reply; 3+ messages in thread
From: JonY @ 2019-06-07 11:22 UTC (permalink / raw)
To: cygwin
[-- Attachment #1.1: Type: text/plain, Size: 1242 bytes --]
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.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order
2019-06-07 11:22 ` JonY
@ 2019-06-07 11:58 ` Jon Turney
0 siblings, 0 replies; 3+ messages in thread
From: Jon Turney @ 2019-06-07 11:58 UTC (permalink / raw)
To: The Cygwin Mailing List
On 07/06/2019 12:22, JonY wrote:
> 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.
see also: https://cygwin.com/faq.html#faq.programming.linker and the
mail linked therein.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-07 11:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 10:04 linker (binutils ld) is unable to resolve weak symbol, depends on object file order Michael Haubenwallner
2019-06-07 11:22 ` JonY
2019-06-07 11:58 ` Jon Turney
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).