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; q=dns; s=default; b=UT0k umzixGwj9aWW+WahNtwH877JyxYzc9F9xjNiVz/MbZ81WXnJyekF3j/LoMgjuxF7 Nccn5h7R1o/+jCj8b+EQYPVZOuMXYtunGwm/Urgfr+amvOWLXlAHdfdB1k21+uw5 FAEW+pPJCS22P9dlOTvPaxw5nMF7eltnj6sCmIM= 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; s=default; bh=7RU0g2cq+I IoG6gWWIUpQEH5HrQ=; b=SJQg5IuDQuPlA0n+P+ipe+UPYthtNjfsDjtVnIwv3Y Qcwfpta7FF6ujiSaTqsT5x3mSphxfCoPpSpgQpJ/M8/gpALQ/XCnJHUgvO3V20p5 GI5pRc9tICXo/GZYokZH4rjrjBZM3y3IgDb5Wa5YGb/xdyhE2+IHcHBIEqg2J3dX 0= 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=-9.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:mail-pl, HX-HELO:sk:mail-pl, HX-Spam-Relays-External:sk:mail-pl, H*RU:sk:mail-pl X-HELO: mail-pl1-f182.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to; bh=yzMhxnqUzeTeUS8SfNKu08xaUVOxGyOsDlRI8BH5bI0=; b=KiipwtSJ404C/bp2Dynu+VG26zZfgGr7qsv1hDX5F0KsCIU59+bw/amxn8f1ineta2 cafYZLgcqTrrCwyYqJpbARQ1Hec+muDRx9VahwOJm44/WPfuMX5DsLbu3m48utGVu7bU UYGrR4FlkiX5W3RS+lna4n+xwxZ6XtJB9mScnqKEF+b17PGwu8cfJr0ei/Z/w7dQg/2k liF3/lPZNR9NpYKVzZTtlqAJmVRsUJH6zUHhKKKfoqqWT74Bom83EzW49WSdCOVAES6a 3vjmaIpLyio63rULim6z6tcWiV+5zXSxiszd1xw4m1aofG6SnXP/bDFjW2a33JTtvgcU MKLA== Subject: Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order To: cygwin AT cygwin DOT com References: From: JonY <10walls AT gmail DOT com> Openpgp: preference=signencrypt Message-ID: Date: Fri, 7 Jun 2019 11:22:45 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="DU9vNDhezDyjoahZJ2JWed9wr9wlnLgIL" X-IsSubscribed: yes --DU9vNDhezDyjoahZJ2JWed9wr9wlnLgIL Content-Type: multipart/mixed; boundary="HWAFqoOKSLSV6FYYvtyiX6ZKqsjzCm6Nw"; protected-headers="v1" From: JonY <10walls AT gmail DOT com> To: cygwin AT cygwin DOT com Message-ID: Subject: Re: linker (binutils ld) is unable to resolve weak symbol, depends on object file order References: In-Reply-To: --HWAFqoOKSLSV6FYYvtyiX6ZKqsjzCm6Nw Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 6/7/19 10:04 AM, Michael Haubenwallner wrote: > Hi, >=20 > 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.e= xe: >=20 > $ cat weak-func.c > extern void weakfunc() __attribute__((weak)); > void weakfunc() {} >=20 > $ cat weak-main.c > extern void weakfunc() __attribute__((weak)); > int main() { weakfunc(); } >=20 > $ gcc -o weak.exe weak-func.c weak-main.c > SUCCESS >=20 > But then, changing the order of input files on the command line does break > (does work on Linux of course): >=20 > $ 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 >=20 > So the difference is that the object providing weakfunc is passed to > the linker after the object requiring weakfunc. >=20 > Attached is the weak-func.sh script that does perform these commands. >=20 > Thanks! > /haubi/ >=20 Unfortunately, PE doesn't really have a concept of weak symbols like ELF, and is known to be broken in binutils. --HWAFqoOKSLSV6FYYvtyiX6ZKqsjzCm6Nw-- --DU9vNDhezDyjoahZJ2JWed9wr9wlnLgIL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE5QrdnbBX9Ppk4bbPcTtf4pwUXUUFAlz6SQUACgkQcTtf4pwU XUX3TBAAjtwH2FD59iajikVuR3ayDhG1bXv2P5Tpnqx6dOUS012ReS9YaAUjidqZ UJLYn9QrBvCYior0vV6nxLaxPSe/eUKgDKaC72o3nzu9Vlv69M/5UPY8Qc5q1GNo LrkdoNnV1l4fHfSKLpGEqKFU9U7li4uyoKRl9WuSuLUJed41ULBKl2fiRvf6LpWa gZ9WjjXlFveUOE/WMek55YTcEo0t1XFeBqu2Leqvj1uRxcHB+CROHVxMmrzIvVhR JhB2xmm6auB9fLh1bIVakp2WPy2ig7iRehdQimnyxjyF6QJP2Y5gNdqSUcudUkUT MmxNeAyR3j60J+dTNT3rw0LgSunrmKgSjJS6ua7LcHgiXUBJJ74aHvQQN8BZ3DGB Az2A0Js1DJXZ5sue4cYZbZn5EWNqphu6lqOidvtf/D4UwxEf8Wne/aBiY26C8RKS oA14DenjZW5468fjABIyYWSfIzA1oo2I/bGpMJC4vEB4rAqED4a9gLj2pu9b5Hgj 5XS8AsQPOv/EgBGwKMFDP8jYKwWEuBePXfjzTDhT91LilVXUys1HRHg50gKF3bCN PSV+T37ks2MAQ/Z9b5lv0oO/w7LiIeJ+eaZG53W9we+sA0wuotgSlQNgDOHy51Qq Ha0fBKdR3jwRa5CRcZLxv/wTgd+B0ZvPKIbix/eBmgHy400cVt0= =XtgN -----END PGP SIGNATURE----- --DU9vNDhezDyjoahZJ2JWed9wr9wlnLgIL--