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 D99393858C60 for ; Thu, 7 Oct 2021 14:58:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D99393858C60 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 1A61482F08; Thu, 7 Oct 2021 16:58:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1633618690; bh=UFCEMmNK/KoWZwOVW77x3h+cnlM6h7x6CMAqTI7IQHY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GkurelME2r3PcnCwnD9T1FJdSTKDH5XWxACmaMqnJgRM7M60W37WV3V/I1WMV+tgF l9r89u6KR4+z2XSwFP93B5jpPQisUFWulzcJMa1vJTI4xCcT45ETfUfZsxzZEGVfdT LvWPpHF9FenxW+5gyol0WpJ94Z4WcgTaeNE5uT1Gy8nTl1yt4Scx93ePCZk1AwgKZq 0OGdMXHwsIf5wwOfh0eys8QjtIbQ/1Qvvu/kVf6+7NyJvgu7FFo9JyuePMQZ9RyHaT R3sT/rE2vlo3XG8lDUP+HLacSaiwqlJIrVlavSmiKGFnyAkNOo03kVuoCEMlckkGSg qF/nxhIXJi4dQ== Date: Thu, 7 Oct 2021 16:58:03 +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: <20211007165803.4d2ac70c@ktm> In-Reply-To: <20211007141526.GF2700@arm.com> References: <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> <20211007111926.30db4c4f@ktm> <20211007120038.1445bbd3@ktm> <20211007141526.GF2700@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_/6GsMHaBG1gQ_o+srrGQ2L+D"; 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.4 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 14:58:13 -0000 --Sig_/6GsMHaBG1gQ_o+srrGQ2L+D Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi Szabolcs, > The 10/07/2021 12:00, Lukasz Majewski wrote: > > On Thu, 7 Oct 2021 11:19:26 +0200 > > Lukasz Majewski wrote: =20 > > > Please find working and broken ld-linux-armhf.so.3: > > > https://owncloud.denx.de/s/wtAfktG6pXLffSA =20 >=20 > thanks. >=20 > i can confirm that this crashes on an aarch64 machine too > (that supports running arm binaries), so not just a qemu > problem. >=20 >=20 > > > > > Links: > > > > > [1] - > > > > > https://github.com/lmajewski/y2038_glibc/commit/e67e0f589b88a44be= 8f8b9b770b08950dd7e5bd5 > > > > >=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. =20 > > >=20 > > > 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) > > >=20 > > > 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 > > > >=20 > > > > is this made by some modified binutils? =20 > > >=20 > > > I've double checked the ld-linux-armhf.so.3 and after build it > > > has: (Entry point address: 0xa00) which seems to be > > > correct. > > >=20 > > > 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. > > > =20 > >=20 > > And indeed it is the case. Yocto/OE by default perform prelinking > > (use prelink program) to speedup start time of dynamic program. > >=20 > > The prelink [1] itself assigns some virtual addresses to all > > required shared objects (in our case for /sbin/init), so no clashes > > are encountered. > >=20 > > And using prelink is a _default_ behaviour in Yocto/OE poky distro. > >=20 > > Links: > > [1] - https://linux.die.net/man/8/prelink =20 >=20 > ah prelinking. >=20 > ok so &__ehdr_start is supposed to point to the > elf header, which supposed to start at address 0 > within the elf image. >=20 > but with prelinking everthing is moved by a fixed > offset (including the elf header), so __ehdr_start > is no longer has 0 address. I think that __ehdr_start now points to > 0x41000000. >=20 > i don't immediately know what's the best fix for this. I think that getting the address with 'adr' ASM instruction was more robust, as it was not relying on the set constant (__ehdr_start). 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_/6GsMHaBG1gQ_o+srrGQ2L+D Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmFfCvsACgkQAR8vZIA0 zr0uxQf/abKz/e+rhnhqKvmWGmZHYNM11Y/turyZo97ikOxfG2muSIKVkjrC7P3S fmJXgsfkJgyTNwXdmOzteWiWlDDlCPwNUd4VsVgaJnH3uAW7ZUWbJZwepQUaNAZp H3YtRQ0sOmF1rX6u162gFjJofj58Pv+88nY6Dy1q3kbp22nAxsMvAuodOxCH3nno XMLaD0hcLjjnAm9FoM2/WB7ghAYBpkMPeMR3zhMP5Hbu7Kfv+eFe4IK7I0RGE5U5 soNUixapEiOPJ10zhru67PzudFHqBYewCvdZBGa05s46QPry/MpymBrnZEsoH9gb lvbDS7jBI0kEnd9pWv0tMPD0gnxS/A== =D+pe -----END PGP SIGNATURE----- --Sig_/6GsMHaBG1gQ_o+srrGQ2L+D--