From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5065 Path: news.gmane.org!not-for-mail From: Stephen Thomas Newsgroups: gmane.linux.lib.musl.general Subject: RE: Linking musl with ld.gold Date: Tue, 6 May 2014 22:11:32 +0100 Message-ID: References: ,<20140506101410.GP12324@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="_e85b9571-00a8-4cd9-ae68-216533227a15_" X-Trace: ger.gmane.org 1399410723 8052 80.91.229.3 (6 May 2014 21:12:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 6 May 2014 21:12:03 +0000 (UTC) To: "musl@lists.openwall.com" Original-X-From: musl-return-5071-gllmg-musl=m.gmane.org@lists.openwall.com Tue May 06 23:11:58 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WhmeQ-0006dK-7o for gllmg-musl@plane.gmane.org; Tue, 06 May 2014 23:11:46 +0200 Original-Received: (qmail 13756 invoked by uid 550); 6 May 2014 21:11:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 13746 invoked from network); 6 May 2014 21:11:44 -0000 X-TMN: [X1k33ZfXhT20iS5dLMPmGncfN7oInxKn] X-Originating-Email: [scjthm@live.com] Importance: Normal In-Reply-To: <20140506101410.GP12324@port70.net> X-OriginalArrivalTime: 06 May 2014 21:11:32.0675 (UTC) FILETIME=[C18FD930:01CF696F] Xref: news.gmane.org gmane.linux.lib.musl.general:5065 Archived-At: --_e85b9571-00a8-4cd9-ae68-216533227a15_ Content-Type: multipart/alternative; boundary="_89c885d4-a08f-43d0-b3bd-5c03c4d321e1_" --_89c885d4-a08f-43d0-b3bd-5c03c4d321e1_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I think that I have managed to reproduce the problem=2C in as much isolatio= n as possible. I believe that there is a missing step in your test=2C which= is included in the build=2C and that is the creation of the archive. I may= have done something incorrect also=2C which is also very likely. I attach a simple script for running the tests on my machine. Unfortunately= =2C the system I use doesn't display indicate where ld.gold was being used = as it chooses to do this by changing the symlink to which ld points to. To summari(s/z)e when using ar to create an archive the weak symbol doesn't= appear to be overridden=2C using either ld.bfd nor ld.gold. The script tha= t was used to generate the output is attached and this should describe the = 4 test cases. Test case #2 is probably irrelevant=2C and the first two are = simply reproducing the results of your tests. Thomo gt-bld / # binutils-config --linker ld.bfd * Setting default linker to ld.b= fd for x86_64-pc-linux-gnu-2.24.51.0.3 ... gt-bld / # /tmp/badar.sh ***= *********************************************************Running with ...gc= c (Gentoo 4.8.2-r1 p1.4-ssptest=2C pie-0.5.9-ssptest) 4.8.2Copyright (C) 20= 13 Free Software Foundation=2C Inc.This is free software=3B see the source = for copying conditions. There is NOwarranty=3B not even for MERCHANTABILIT= Y or FITNESS FOR A PARTICULAR PURPOSE. GNU ld (Linux/GNU Binutils) 2.24.51.0.3.20140127Copyright 2014 Free Softwar= e Foundation=2C Inc.This program is free software=3B you may redistribute i= t under the terms ofthe GNU General Public License version 3 or (at your op= tion) a later version.This program has absolutely no warranty.*************= ***********************************************Case 0: 0*******************= ***************************************************************************= **************************Case 1: 42***************************************= *********************ar: creating a.a a.o:0000000000000000 r dummy0000000000000000 T f0000000000000000 V hasfoo**= **********************************************************Case 2: 0********= ****************************************************ar: creating a.a a.o:0000000000000000 r dummy0000000000000000 T f0000000000000000 V hasfoo b.o:0000000000000000 d foo0000000000000000 R hasfoo************************= ************************************Case 3: 0******************************= ******************************gt-bld / # binutils-config --linker ld.gold *= Setting default linker to ld.gold for x86_64-pc-linux-gnu-2.24.51.0.3 ... = = = [ ok ]gt-bld / # /tmp/badar.sh ***************************************= *********************Running with ...gcc (Gentoo 4.8.2-r1 p1.4-ssptest=2C p= ie-0.5.9-ssptest) 4.8.2Copyright (C) 2013 Free Software Foundation=2C Inc.T= his is free software=3B see the source for copying conditions. There is NO= warranty=3B not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOS= E. GNU gold (Linux/GNU Binutils 2.24.51.0.3.20140127) 1.11Copyright 2014 Free = Software Foundation=2C Inc.This program is free software=3B you may redistr= ibute it under the terms ofthe GNU General Public License version 3 or (at = your option) a later version.This program has absolutely no warranty.******= ******************************************************Case 0: 0************= ***************************************************************************= *********************************Case 1: 42********************************= ****************************ar: creating a.a a.o:0000000000000000 r dummy0000000000000000 T f0000000000000000 V hasfoo**= **********************************************************Case 2: 0********= ****************************************************ar: creating a.a a.o:0000000000000000 r dummy0000000000000000 T f0000000000000000 V hasfoo b.o:0000000000000000 d foo0000000000000000 R hasfoo************************= ************************************Case 3: 0******************************= ******************************=20 > Date: Tue=2C 6 May 2014 12:14:10 +0200 > From: nsz@port70.net > To: musl@lists.openwall.com > Subject: Re: [musl] Linking musl with ld.gold >=20 > * Stephen Thomas [2014-05-06 10:07:59 +0100]: > > I have come across a problem and it only appears when the gold linker i= s used. I am using the latest release of binutils=2C binutils-2.24.51.0.3. > > I discovered that busybox was not flushing stdout (as there was no prom= pt appearing) when using musl. Busybox calls fflush(NULL) which should flus= h stdout as done in src/stdio/fflush.c.=20 > > In that file I checked the value for __stdout_used and it came back as = 0. So I changed the declaration of the weak symbol to an extern FILE* __std= out_used and stdout was being flushed. > > Has anyone else seen this and have they reported this apparent bug in b= inutils? >=20 >=20 > i think we only reported a broken tls visibility issue against gold > https://sourceware.org/bugzilla/show_bug.cgi?id=3D16728 >=20 > you should try to reproduce the bug on a minimal example=2C eg. the > following code works here with gold (binutils 2.22) >=20 > // a.c > struct foo {int i=3B}=3B > static struct foo *const dummy =3D 0=3B > extern struct foo *const hasfoo __attribute__((weak=2C alias("dummy")))= =3B > int f(void) > { > return hasfoo ? hasfoo->i : 0=3B > } > // b.c > struct foo {int i=3B}=3B > static struct foo foo =3D {42}=3B > struct foo *const hasfoo =3D &foo=3B > // main.c > int f(void)=3B > int main() > { > return f()=3B > } >=20 > gcc main.o a.o -o t1 > gcc main.o a.o b.o -o t2 > ./t1 returns 0 > ./t2 returns 42 = --_89c885d4-a08f-43d0-b3bd-5c03c4d321e1_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I think that I have managed to r= eproduce the problem=2C in as much isolation as possible. I believe that th= ere is a missing step in your test=2C which is included in the build=2C and= that is the creation of the archive. I may have done something incorrect a= lso=2C which is also very likely.

I attach a simple scri= pt for running the tests on my machine. Unfortunately=2C the system I use d= oesn't display indicate where ld.gold was being used as it chooses to do th= is by changing the symlink to which ld points to.

= To summari(s/z)e when using ar to create an archive the weak symbol doesn't= appear to be overridden=2C using either ld.bfd nor ld.gold. The script tha= t was used to generate the output is attached and this should describe the = 4 test cases. Test case #2 is probably irrelevant=2C and the first two are = simply reproducing the results of your tests.

Thomo

<= span style=3D"font-size: 12pt=3B">gt-bld / # =3Bbinutils-config --linker ld.bfd
 = =3B* Setting default linker to ld.bfd for x86_64-pc-linux-gnu-2.24.51.0.3 .= ..  =3B  =3B =3B
gt-bld / # /tmp/badar.sh = =3B
************************************************************<= /div>
Running with ...
gcc (Gentoo 4.8.2-r1 p1.4-ssptest=2C p= ie-0.5.9-ssptest) 4.8.2
Copyright (C) 2013 Free Software Foundati= on=2C Inc.
This is free software=3B see the source for copying co= nditions.  =3BThere is NO
warranty=3B not even for MERCHANTAB= ILITY or FITNESS FOR A PARTICULAR PURPOSE.

GNU ld = (Linux/GNU Binutils) 2.24.51.0.3.20140127
Copyright 2014 Free Sof= tware Foundation=2C Inc.
This program is free software=3B you may= redistribute it under the terms of
the GNU General Public Licens= e version 3 or (at your option) a later version.
This program has= absolutely no warranty.
****************************************= ********************
Case 0: 0
************************= ************************************
****************************= ********************************
Case 1: 42
***********= *************************************************
ar: creating a.= a

a.o:
0000000000000000 r dummy
0000000000000000 T f
0000000000000000 V hasfoo
******= ******************************************************
Case 2: 0<= /div>
************************************************************
ar: creating a.a

a.o:
000000000000= 0000 r dummy
0000000000000000 T f
0000000000000000 V ha= sfoo

b.o:
0000000000000000 d foo
0000000000000000 R hasfoo
************************************= ************************
Case 3: 0
********************= ****************************************
gt-bld =3B/ # binutils-config --linker ld.gold
<= div> =3B* Setting default linker to ld.gold for x86_64-pc-linux-gnu-2.2= 4.51.0.3 ...  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B &n= bsp=3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  = =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B &n= bsp=3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  = =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B &n= bsp=3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  = =3B  =3B  =3B  =3B  =3B[ ok ]
gt-bld =3B/ # /tmp/badar.sh =3B
**= **********************************************************
Runnin= g with ...
gcc (Gentoo 4.8.2-r1 p1.4-ssptest=2C pie-0.5.9-ssptest= ) 4.8.2
Copyright (C) 2013 Free Software Foundation=2C Inc.
=
This is free software=3B see the source for copying conditions.  = =3BThere is NO
warranty=3B not even for MERCHANTABILITY or FITNES= S FOR A PARTICULAR PURPOSE.

GNU gold (Linux/GNU Bi= nutils 2.24.51.0.3.20140127) 1.11
Copyright 2014 Free Software Fo= undation=2C Inc.
This program is free software=3B you may redistr= ibute it under the terms of
the GNU General Public License versio= n 3 or (at your option) a later version.
This program has absolut= ely no warranty.
************************************************= ************
Case 0: 0
********************************= ****************************
************************************= ************************
Case 1: 42
*******************= *****************************************
ar: creating a.a
<= div>
a.o:
0000000000000000 r dummy
000000= 0000000000 T f
0000000000000000 V hasfoo
**************= **********************************************
Case 2: 0
************************************************************
ar= : creating a.a

a.o:
0000000000000000 r d= ummy
0000000000000000 T f
0000000000000000 V hasfoo

b.o:
0000000000000000 d foo
00000= 00000000000 R hasfoo
********************************************= ****************
Case 3: 0
****************************= ********************************
 =3B

>=3B Date= : Tue=2C 6 May 2014 12:14:10 +0200
>=3B From: nsz@port70.net
>=3B= To: musl@lists.openwall.com
>=3B Subject: Re: [musl] Linking musl wit= h ld.gold
>=3B
>=3B * Stephen Thomas <=3Bscjthm@live.com>=3B= [2014-05-06 10:07:59 +0100]:
>=3B >=3B I have come across a problem= and it only appears when the gold linker is used. I am using the latest re= lease of binutils=2C binutils-2.24.51.0.3.
>=3B >=3B I discovered th= at busybox was not flushing stdout (as there was no prompt appearing) when = using musl. Busybox calls fflush(NULL) which should flush stdout as done in= src/stdio/fflush.c.
>=3B >=3B In that file I checked the value for= __stdout_used and it came back as 0. So I changed the declaration of the w= eak symbol to an extern FILE* __stdout_used and stdout was being flushed.>=3B >=3B Has anyone else seen this and have they reported this appar= ent bug in binutils?
>=3B
>=3B
>=3B i think we only report= ed a broken tls visibility issue against gold
>=3B https://sourceware.= org/bugzilla/show_bug.cgi?id=3D16728
>=3B
>=3B you should try to= reproduce the bug on a minimal example=2C eg. the
>=3B following code= works here with gold (binutils 2.22)
>=3B
>=3B // a.c
>=3B= struct foo {int i=3B}=3B
>=3B static struct foo *const dummy =3D 0=3B=
>=3B extern struct foo *const hasfoo __attribute__((weak=2C alias("du= mmy")))=3B
>=3B int f(void)
>=3B {
>=3B return hasfo= o ? hasfoo->=3Bi : 0=3B
>=3B }
>=3B // b.c
>=3B struct foo= {int i=3B}=3B
>=3B static struct foo foo =3D {42}=3B
>=3B struct= foo *const hasfoo =3D &=3Bfoo=3B
>=3B // main.c
>=3B int f(vo= id)=3B
>=3B int main()
>=3B {
>=3B return f()=3B
= >=3B }
>=3B
>=3B gcc main.o a.o -o t1
>=3B gcc main.o a.o= b.o -o t2
>=3B ./t1 returns 0
>=3B ./t2 returns 42
= --_89c885d4-a08f-43d0-b3bd-5c03c4d321e1_-- --_e85b9571-00a8-4cd9-ae68-216533227a15_ Content-Type: application/x-sh Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="badar.sh" IyEvYmluL3NoIC1lCkFSPWFyCk5NPW5tCkNDPWdjYwpDRkxBR1M9IiIKI3VzZSBnY2MtYXIgYW5k IGdjYy1ubSB3aGVuIHVzaW5nIC1mbHRvIC1mdXNlLWxpbmtlci1wbHVnaW4iCkZMSVNUPSJhLmMg Yi5jIG1haW4uYyBhLm8gYi5vIG1haW4ubyBhLmEgYSIKY2QgL3RtcAppZiBbICIkKGxzIC1sICR7 RkxJU1R9IDI+IC9kZXYvbnVsbCB8IHdjIC1sKSIgIT0gIjAiIF0gOyB0aGVuCiAgICBlY2hvICJT b3JyeSBvbmUgb2YgdGhlc2UgZmlsZXMgZXhpc3RzICR7RkxJU1R9IGFuZCBJIHdvdWxkIGxpa2Ug dG8gb3ZlcndyaXRlIHRoZW0iCiAgICBleGl0IDEKZmkKY2F0ID4gYS5jIDw8IF9FT0YKLy8gYS5j CnN0cnVjdCBmb28ge2ludCBpO307CnN0YXRpYyBzdHJ1Y3QgZm9vICpjb25zdCBkdW1teSA9IDA7 CmV4dGVybiBzdHJ1Y3QgZm9vICpjb25zdCBoYXNmb28gX19hdHRyaWJ1dGVfXygod2VhaywgYWxp YXMoImR1bW15IikpKTsKaW50IGYodm9pZCkKewogICAgcmV0dXJuIGhhc2ZvbyA/IGhhc2Zvby0+ aSA6IDA7Cn0KX0VPRgpjYXQgPiBiLmMgPDwgX0VPRgovLyBiLmMKc3RydWN0IGZvbyB7aW50IGk7 fTsKc3RhdGljIHN0cnVjdCBmb28gZm9vID0gezQyfTsKc3RydWN0IGZvbyAqY29uc3QgaGFzZm9v ID0gJmZvbzsKX0VPRgpjYXQgPiBtYWluLmMgPDwgX0VPRgovLyBtYWluLmMKaW50IGYodm9pZCk7 CmludCBtYWluKCkKewogICAgcmV0dXJuIGYoKTsKfQpfRU9GCiR7Q0N9ICR7Q0ZMQUdTfSAtYyBh LmMKJHtDQ30gJHtDRkxBR1N9IC1jIGIuYwoke0NDfSAke0NGTEFHU30gLWMgbWFpbi5jCiR7Q0N9 ICR7Q0ZMQUdTfSAtbyBhIG1haW4ubyBhLm8KZWNobyAiKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqIgplY2hvICJSdW5uaW5nIHdpdGgg Li4uIgpnY2MgLS12ZXJzaW9uCmxkIC0tdmVyc2lvbgplY2hvICIqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioiCnJldD0wCi4vYSB8fCBy ZXQ9JHs/fQplY2hvICJDYXNlIDA6ICR7cmV0fSIKZWNobyAiKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqIgpybSAtZiBhLmEgYQoke0ND fSAke0NGTEFHU30gLW8gYSBtYWluLm8gYS5vIGIubwplY2hvICIqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioiCnJldD0wCi4vYSB8fCBy ZXQ9JHs/fQplY2hvICJDYXNlIDE6ICR7cmV0fSIKZWNobyAiKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqIgpybSAtZiBhLmEgYQoke0FS fSByIGEuYSBhLm8KJHtOTX0gYS5hCiR7Q0N9ICR7Q0ZMQUdTfSAtbyBhIG1haW4ubyBhLmEKZWNo byAiKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqIgpyZXQ9MAouL2EgfHwgcmV0PSR7P30KZWNobyAiQ2FzZSAyOiAke3JldH0iCmVjaG8g IioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKiIKcm0gLWYgYS5hIGEKJHtBUn0gciBhLmEgYS5vIGIubwoke05NfSBhLmEKJHtDQ30gJHtD RkxBR1N9IC1vIGEgbWFpbi5vIGEuYQplY2hvICIqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioiCnJldD0wCi4vYSB8fCByZXQ9JHs/fQpl Y2hvICJDYXNlIDM6ICR7cmV0fSIKZWNobyAiKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqIgpybSAtZiBhLmMgYi5jIG1haW4uYyBhLm8g Yi5vIG1haW4ubyBhLmEgYQo= --_e85b9571-00a8-4cd9-ae68-216533227a15_--