From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18927 invoked by alias); 7 Jun 2019 11:58:42 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 18920 invoked by uid 89); 7 Jun 2019 11:58:42 -0000 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 Received: from rgout0406.bt.lon5.cpcloud.co.uk (HELO rgout04.bt.lon5.cpcloud.co.uk) (65.20.0.219) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Jun 2019 11:58:40 +0000 X-OWM-Source-IP: 86.184.210.21 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-SNCR-VADESECURE: CLEAN Received: from [192.168.1.102] (86.184.210.21) by rgout04.bt.lon5.cpcloud.co.uk (9.0.019.26-1) (authenticated as jonturney@btinternet.com) id 5C55FFA90C098F0E for cygwin@cygwin.com; Fri, 7 Jun 2019 12:58:36 +0100 Subject: Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order To: The Cygwin Mailing List References: From: Jon Turney Message-ID: <1b4f079b-55d9-e5d0-7b4a-5134fa7710b7@dronecode.org.uk> Date: Fri, 07 Jun 2019 11:58:00 -0000 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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2019-06/txt/msg00095.txt.bz2 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