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:to:from:subject:message-id:date:mime-version :content-type; q=dns; s=default; b=OwFGenXfxZgLSdP6ATvEyaf48Av2/ J6XeZeiaUluDugV6GIdVLRESVHwuq2cVOLhvFjghXGWUAQEIZXZUjk4ZezV4+Cyt PI46damjCHx0dlOMAMVBMp9ZCaZLDIxf44aCB1K+6oiIbJvkUtQaVQp5YaoJ4c0B pbwjBcOLO2ub5c= 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:to:from:subject:message-id:date:mime-version :content-type; s=default; bh=ZJr+MVMrtIBweuaA4D4wKfbq1ZI=; b=cr4 6tgGP6J0tW6druPhYEI8pnQYA/3ABctT+yAJ0zG13SdTmME9udRMA60RcHBNCHGk apA4bMS+wncV3dAoug/44hmWd6l3LitVR+2NQAfE2igQEArSCzhOJv6gUiTbU2Jc Hh0S1csW7abXXbOhJYYkNepgv7r9HbWLLLWyyArE= 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=-6.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: atfriesa01.ssi-schaefer.com To: cygwin AT cygwin DOT com From: Michael Haubenwallner Subject: linker (binutils ld) is unable to resolve weak symbol, depends on object file order Openpgp: preference=signencrypt Message-ID: Date: Fri, 7 Jun 2019 12:04:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------DE594A2A9434DC3CF1F20BD3" --------------DE594A2A9434DC3CF1F20BD3 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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/ --------------DE594A2A9434DC3CF1F20BD3 Content-Type: application/x-shellscript; name="weak-func.sh" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="weak-func.sh" IyEgL3Vzci9iaW4vZW52IGJhc2gKCnNldCAtZXgKCmNhdCA+IHdlYWstZnVu Yy5jIDw8J0VPRicKZXh0ZXJuIHZvaWQgd2Vha2Z1bmMoKSBfX2F0dHJpYnV0 ZV9fKCh3ZWFrKSk7CnZvaWQgd2Vha2Z1bmMoKSB7fQpFT0YKCmNhdCA+IHdl YWstbWFpbi5jIDw8J0VPRicKZXh0ZXJuIHZvaWQgd2Vha2Z1bmMoKSBfX2F0 dHJpYnV0ZV9fKCh3ZWFrKSk7CmludCBtYWluKCkgeyB3ZWFrZnVuYygpOyB9 CkVPRgoKJHtDQzotZ2NjfSAtbyB3ZWFrLmV4ZSB3ZWFrLWZ1bmMuYyB3ZWFr LW1haW4uYyAmJiA6ICdQQVNTJyB8fCA6ICdGQUlMJwoke0NDOi1nY2N9IC1v IHdlYWsuZXhlIHdlYWstbWFpbi5jIHdlYWstZnVuYy5jICYmIDogJ1BBU1Mn IHx8IDogJ0ZBSUwnCg== --------------DE594A2A9434DC3CF1F20BD3 Content-Type: text/plain; charset=us-ascii -- 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 --------------DE594A2A9434DC3CF1F20BD3--