From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by sourceware.org (Postfix) with ESMTPS id 8B42B3858C39 for ; Thu, 7 Oct 2021 09:19:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B42B3858C39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=denx.de Received: from ktm (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 4EFD68347C; Thu, 7 Oct 2021 11:19:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1633598373; bh=tu7xArGeF0FsMqddaYDKJ0RWtwf5tUF3rMQJi6F3Yyg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=v3fbQpqaN+bfF7GUuSmkbPh14Hga+Evi+9jT5AsmbUmjXKB9v8KpnXbplD1EMxfvY ObSPt1OwcGA1w1GgtjviDD2suzx7bCojGRVtB4YO5B7v54QmhRSNeE7yHjB7+GriAi ldiUU7ibpYAwUQaNaruMhy3qNXi0DRoKNbDFNjqgozBPyC4DKune9HcNmwMeSXs5zt BqqPPFLqffbFluQ65z7XS0NV8MG9tat47FKFSKtxOnOAcBsaCQDzF/acQrcHJvAtsr FBFL6XesctlIMJEj8GjdaTACa8fuxZAbzpWKXSP0DE1TzfRcCVhNbE9xwTvxcsdpw1 9XrlsYj3bDRDw== Date: Thu, 7 Oct 2021 11:19:26 +0200 From: Lukasz Majewski To: Szabolcs Nagy Cc: Fangrui Song , Adhemerval Zanella , Florian Weimer , Joseph Myers , Andreas Schwab , libc-alpha Subject: Re: [PATCH] dl: Use "adr" assembler command to get proper load address Message-ID: <20211007111926.30db4c4f@ktm> In-Reply-To: <20211006125517.GE2700@arm.com> References: <20210907131616.23472-1-lukma@denx.de> <20210907164906.yt6nonvfyhvbrx6p@google.com> <20210907193227.6047f9cc@ktm> <20210907174417.sctsswphsyae4mpc@google.com> <20211005094554.2f28d6bd@ktm> <20211006075721.qnv6qabroytcsido@google.com> <20211006110321.5f1a9610@ktm> <20211006134344.63395242@ktm> <20211006125517.GE2700@arm.com> Organization: denx.de X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/sI7wLUcjctvkMULVpSmfO/s"; protocol="application/pgp-signature" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 09:19:37 -0000 --Sig_/sI7wLUcjctvkMULVpSmfO/s Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi Szabolcs, > The 10/06/2021 13:43, Lukasz Majewski wrote: > > Please find in-depth analyze about the issue: > >=20 > > It was tested with Beagle Bone Black (BBB) and QEMU (the same binary > > rootfs images). > > (If needed I will upload images and script to run QEMU to some > > server for reproduction). > > Branch: https://github.com/lmajewski/y2038_glibc/commits/y2038_edge > > =20 >=20 > i think it is easier to look at if you upload the broken > ld.so binary. or at least readelf -aW ld.so output. Please find working and broken ld-linux-armhf.so.3: https://owncloud.denx.de/s/wtAfktG6pXLffSA >=20 > > On working setup to trigger the core dump: > > /home/root/ld-linux-armhf.so.3 /sbin/init > > gdb ./ld-linux-armhf.so.3 core > >=20 > > (and the /home/root/ld-linux-armhf.so.3 is the "broken" one). > >=20 > >=20 > > Not working (patch [1] not applied): > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >=20 > > All the code is located in _dl_start in elf/rtld.c and > > elf/get-dynamic-info.h files: > >=20 > > (gdb) p/x $r5 > > $46 =3D 0xb6fc8000 > > r5 is set from the elf_machine_load_address() > >=20 > > Then we enter the elf_get_dynamic_info() > >=20 > > 0xb6fc95fc 99 ADJUST_DYN_INFO (DT_SYMTAB); > > 0xb6fc95f8 <_dl_start+308>: 04 30 92 15 ldrne r3, [r2, > > #4] =3D> 0xb6fc95fc <_dl_start+312>: 05 30 83 10 addne r3, r3, > > r5 0xb6fc9600 <_dl_start+316>: 04 30 82 15 strne r3, [r2, #4] > > (gdb) p/x $r3 > > $63 =3D 0x410003f4 > > (gdb) p/x $r5 > > $64 =3D 0xb6fc8000 =20 >=20 > it seems r5 is already wrong here, it's not the runtime > address of 0. (looks more like the runtime address of > 0x41000000) The r5 is set according to the change in patch which now I'm trying to fix. To be more specific - r5 is set according to code in patch SHA1: bca0f5cbc9257c13322b99e55235c4f21ba0bd82 >=20 > likely something goes wrong with the computation of r5. Before the SHA1: bca0f5cbc9257c13322b99e55235c4f21ba0bd82 patch r5 was computed with using 'adr' assembler instruction, not set from some constant value. asm ("adr %0, _dl_start" : "=3Dr" (pcrel_addr)); And r5 value was 0x75fc8000 >=20 > > Links: > > [1] - > > https://github.com/lmajewski/y2038_glibc/commit/e67e0f589b88a44be8f8b9b= 770b08950dd7e5bd5 > >=20 > > readelf -e ld-linux-armhf.so.3=20 > >=20 > > [10] .plt PROGBITS 41000994 000994 000050 04 > > AX 0 0 4 [11] .text PROGBITS 41000a00 000a00 > > 01fed0 00 AX 0 0 64 [12] .rodata PROGBITS > > 410208d0 0208d0 004b24 00 A 0 0 4 [13] .ARM.extab > > PROGBITS 410253f4 0253f4 000018 00 A 0 0 4 [14] > > .ARM.exidx ARM_EXIDX 4102540c 02540c 0000c8 00 AL 11 > > 0 4 [15] .data.rel.ro PROGBITS 41036200 026200 000cf4 > > 00 WA 0 0 8 [16] .dynamic DYNAMIC 41036ef4 > > 026ef4 0000c8 08 WA 5 0 4 [17] .got PROGBITS > > 41036fbc 026fbc 000040 04 WA 0 0 4 =20 >=20 > why are all addresses >0x41000000 ? > in a shared library i expect all those addresses > to be close to 0. On this real HW system (the rootfs which is running) - libc.so.6 also has address > 0x41000000 libm.so.6 also has the value > 0x41200000 (Entry point address: 0x412c9190) The offset of > 0x41000000 looks a bit strange indeed, but it is still less than the kernel space. Moreover, with position independent code it shall not matter. >=20 > is this made by some modified binutils? I've double checked the ld-linux-armhf.so.3 and after build it has: (Entry point address: 0xa00) which seems to be correct. So it looks like during installation of the glibc (on the Yocto/OE created rootfs) the elf header is modified and this 0x41000000 offset is added. Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de --Sig_/sI7wLUcjctvkMULVpSmfO/s Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmFeu54ACgkQAR8vZIA0 zr1ITwgAtZfMioIbHgT96z5FaPAokF2IXWBTst0EhQiw7bv1cN3xoewcKQhR/Jv1 j4pyb5MkS9NyKmLhngS1ZH3TKtkZr0K1dXGQwuJYA4SkOgKz75c6Q5CQ4ePdRb6K YzT96O8Wz6N9L1kAcHVIOngUysleDhNjV0FSV+Cpj6nYX2f2fBhJdHN8RVzJWQgG /EhTVM0gQma9pzT7djgnftKRYnCgRHpXKFw1+v5v/GO6/NGT/F9E8arrUko6BYlX 9SJ83sogyk6CbWBgasSKBZEWwTSiHG7TbpcsftISxwLQs9VS8LpZi+++JqXx16SI W1dg/LibBLAcDRlKedXLolO93mnoGQ== =v3ly -----END PGP SIGNATURE----- --Sig_/sI7wLUcjctvkMULVpSmfO/s--