From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mr4.vodafonemail.de (mr4.vodafonemail.de [145.253.228.164]) by sourceware.org (Postfix) with ESMTPS id EDA4C3858C83 for ; Tue, 15 Feb 2022 17:58:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EDA4C3858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nexgo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nexgo.de Received: from smtp.vodafone.de (unknown [10.0.0.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mr4.vodafonemail.de (Postfix) with ESMTPS id 4Jypjs4HQFz1ypf for ; Tue, 15 Feb 2022 17:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexgo.de; s=vfde-smtpout-mb-15sep; t=1644947921; bh=U6Ng418rTWg6WxIcUjFQV/NxwV1O3f51S1tELKmS3Sk=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=m0j6E5RiMlKCzgpXVIobizCoum+wHzn4N89cH13cqjLuU2JRAQIRZlz8wOPSZfXeL mxAW2kkgdaf5Xgl+oAGzp8IOenQFWSyRnDwUVkvf7KQl11aWPmfCBfOMWOldlIPe2N Sx3gGpgxWd/Z0pXIOujeCLzMziQPk00Thn1I7i/8= Received: from Gertrud (p5b2f3a9b.dip0.t-ipconnect.de [91.47.58.155]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 4Jypjr6Xm3zMksT for ; Tue, 15 Feb 2022 17:58:37 +0000 (UTC) From: Achim Gratz To: binutils@sourceware.org Subject: Re: [Bug] DWARF-5 section names in PE/PEP and weak symbols References: <878rwvrlz9.fsf@Rainer.invalid> <87mtiumsgt.fsf@Rainer.invalid> <87y22d7lss.fsf@Otto.invalid> Date: Tue, 15 Feb 2022 18:58:30 +0100 In-Reply-To: <87y22d7lss.fsf@Otto.invalid> (ASSI's message of "Mon, 14 Feb 2022 12:02:59 +0100") Message-ID: <87bkz8hv09.fsf@Rainer.invalid> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 3398 X-purgate-ID: 155817::1644947921-000004B8-D9287AAC/0/0 X-Spam-Status: No, score=-3029.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Feb 2022 17:58:45 -0000 So here's another attempt at getting to the bottom of this. The failing gnulib test was using fputs, the actually failing gnulib module was calling thrd_exit if the weak symbol resolved non-NULL and serendipitously I've stumbled upon snprintf behaving differently=E2=80=A6 --8<---------------cut here---------------start------------->8--- #include #include #include #pragma weak fputs #pragma weak thrd_exit #pragma weak snprintf #pragma weak asnprintf #pragma weak vsnprintf int main () { char buf[256] =3D "snprintf was not called.\n"; printf( "snprintf =3D> %014p\tis %sequal NULL\n", snprintf, ((snprintf = =3D=3D NULL) ? "" : "not ") ); printf( "fputs =3D> %014p\tis %sequal NULL\n", fputs, ((fputs = =3D=3D NULL) ? "" : "not ") ); printf( "thrd_exit =3D> %014p\tis %sequal NULL\n", thrd_exit, ((thrd_exit= =3D=3D NULL) ? "" : "not ") ); if (snprintf !=3D NULL) snprintf(buf, sizeof(buf), "%s\n", "sprintf called through symbol"); printf( "%s", buf ); return (fputs =3D=3D NULL); } --8<---------------cut here---------------end--------------->8--- This is what happens: --8<---------------cut here---------------start------------->8--- ...packages/binutils-gdb/build (2130)# gcc -Wl,--trace-symbol=3D{fputs,snpr= intf,thrd_exit} -c -o weak_test.o weak_test.c ...packages/binutils-gdb/build (2131)# gcc -Wl,--trace-symbol=3D{fputs,{a,v= ,}snprintf,thrd_exit} -o weak_test weak_test.o /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: weak_= test.o: reference to snprintf /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: weak_= test.o: reference to thrd_exit /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: weak_= test.o: reference to fputs /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /usr/= lib/gcc/x86_64-pc-cygwin/11/../../../../lib/libcygwin.a(t-d000578.o): defin= ition of fputs /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /usr/= lib/gcc/x86_64-pc-cygwin/11/../../../../lib/libcygwin.a(t-d001527.o): defin= ition of thrd_exit ...packages/binutils-gdb/build (2132)# ./weak_test ; echo $? snprintf =3D> 0x000000000000 is equal NULL fputs =3D> 0x0001004012e0 is not equal NULL thrd_exit =3D> 0x000100401300 is not equal NULL snprintf was not called. 0 ...packages/binutils-gdb/build (2133)# nm weak_test.o /bin/cygwin1.dll | eg= rep ' (fputs|[av]?snprintf|thrd_exit)$' U fputs w snprintf U thrd_exit 00000001801abb10 T asnprintf 00000001801b1610 T fputs 00000001801c0380 T snprintf 00000001801849a0 T thrd_exit 00000001801eec30 T vsnprintf --8<---------------cut here---------------end--------------->8--- So, snprintf seems to behave as expected (it resolves NULL) and the two other symbols are resolved even though they should not. If they had resolved to the actual address things might even work, but the actual values explain nicely why a program calling through the pointer crashes in various horrible ways (depending on what actually is mapped there). Regards, Achim. --=20 +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ SD adaptation for Waldorf rackAttack V1.04R1: http://Synth.Stromeko.net/Downloads.html#WaldorfSDada