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: List-Subscribe: List-Archive: List-Post: List-Help: , 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 References: From: Jon Turney 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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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