delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/06/07/07:59:35

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=aejszN2PDruKyhlz
iAXUw2GaRZduzzFEOOII/oL0FvovMzy67UIfLhjh5gUbfc/BNh3FaNFF+qi8iv12
fHfeP8qAFtFoztcdrzxOjqoDgIH5VwIE7OYL1D4bc0zLKc9Amb3SeFoMalxXeICM
JZNstq/7c8xn9tc7vDYAJPTa140=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=F13hmaDgynwb68dArjmiF7
H3CD4=; b=GidTmWJ+VlBL9hzoU7BlLXekryuRU6nSE4hJjH5qoM9+dTn5zypXKb
Q0NSbbz5A2Q/N5KNguHgemCC2yUAlu484M1CGgadfmOmlxQ2Hcm7zT+UKRIm9nVK
JfPx/HKpEUDDjZfEFLwy3Zqz5HAG2UgtEdro2IzuwDhO5c99f2Kgw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=H*Ad:D*uk, Unfortunately, H*r:9.0.019
X-HELO: rgout04.bt.lon5.cpcloud.co.uk
X-OWM-Source-IP: 86.184.210.21 (GB)
X-OWM-Env-Sender: jonturney AT btinternet DOT com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-SNCR-VADESECURE: CLEAN
Subject: Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order
To: The Cygwin Mailing List <cygwin AT cygwin DOT com>
References: <c302ea94-ae7b-f7b1-9d8f-0c2e31dc6bc7 AT ssi-schaefer DOT com> <ab8db982-e923-0ef0-e830-6fd2dca1aed2 AT gmail DOT com>
From: Jon Turney <jon DOT turney AT dronecode DOT org DOT uk>
Message-ID: <1b4f079b-55d9-e5d0-7b4a-5134fa7710b7@dronecode.org.uk>
Date: Fri, 7 Jun 2019 12:58:35 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0
MIME-Version: 1.0
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019