public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: The Cygwin Mailing List <cygwin@cygwin.com>
Subject: Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order
Date: Fri, 07 Jun 2019 11:58:00 -0000	[thread overview]
Message-ID: <1b4f079b-55d9-e5d0-7b4a-5134fa7710b7@dronecode.org.uk> (raw)
In-Reply-To: <ab8db982-e923-0ef0-e830-6fd2dca1aed2@gmail.com>

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

      reply	other threads:[~2019-06-07 11:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-07 10:04 Michael Haubenwallner
2019-06-07 11:22 ` JonY
2019-06-07 11:58   ` Jon Turney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b4f079b-55d9-e5d0-7b4a-5134fa7710b7@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).