From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42948 invoked by alias); 7 Jun 2019 10:04:49 -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 42940 invoked by uid 89); 7 Jun 2019 10:04:49 -0000 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 Received: from atfriesa01.ssi-schaefer.com (HELO atfriesa01.ssi-schaefer.com) (193.186.16.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Jun 2019 10:04:48 +0000 Received: from samail03.wamas.com (HELO mailhost.salomon.at) ([172.28.33.235]) by atfriesa01.ssi-schaefer.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2019 12:04:44 +0200 Received: from [172.28.42.244] by mailhost.salomon.at with esmtp (Exim 4.77) (envelope-from ) id 1hZBjn-000806-W5; Fri, 07 Jun 2019 12:04:44 +0200 To: cygwin@cygwin.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, 07 Jun 2019 10:04:00 -0000 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" X-SW-Source: 2019-06/txt/msg00092.txt.bz2 --------------DE594A2A9434DC3CF1F20BD3 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 979 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" Content-length: 509 IyEgL3Vzci9iaW4vZW52IGJhc2gKCnNldCAtZXgKCmNhdCA+IHdlYWstZnVu Yy5jIDw8J0VPRicKZXh0ZXJuIHZvaWQgd2Vha2Z1bmMoKSBfX2F0dHJpYnV0 ZV9fKCh3ZWFrKSk7CnZvaWQgd2Vha2Z1bmMoKSB7fQpFT0YKCmNhdCA+IHdl YWstbWFpbi5jIDw8J0VPRicKZXh0ZXJuIHZvaWQgd2Vha2Z1bmMoKSBfX2F0 dHJpYnV0ZV9fKCh3ZWFrKSk7CmludCBtYWluKCkgeyB3ZWFrZnVuYygpOyB9 CkVPRgoKJHtDQzotZ2NjfSAtbyB3ZWFrLmV4ZSB3ZWFrLWZ1bmMuYyB3ZWFr LW1haW4uYyAmJiA6ICdQQVNTJyB8fCA6ICdGQUlMJwoke0NDOi1nY2N9IC1v IHdlYWsuZXhlIHdlYWstbWFpbi5jIHdlYWstZnVuYy5jICYmIDogJ1BBU1Mn IHx8IDogJ0ZBSUwnCg== --------------DE594A2A9434DC3CF1F20BD3 Content-Type: text/plain; charset=us-ascii Content-length: 219 -- 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--