From owner-svn-src-head@freebsd.org Fri Oct 27 15:22:02 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B26ACE483B1; Fri, 27 Oct 2017 15:22:02 +0000 (UTC) (envelope-from brooks@spindle.one-eyed-alien.net) Received: from spindle.one-eyed-alien.net (spindle.one-eyed-alien.net [199.48.129.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 79C2F6A068; Fri, 27 Oct 2017 15:22:02 +0000 (UTC) (envelope-from brooks@spindle.one-eyed-alien.net) Received: by spindle.one-eyed-alien.net (Postfix, from userid 3001) id EA5075A9F12; Fri, 27 Oct 2017 15:21:54 +0000 (UTC) Date: Fri, 27 Oct 2017 15:21:54 +0000 From: Brooks Davis To: Konstantin Belousov Cc: mmel@freebsd.org, Dimitry Andric , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org, kib@freebsd.org Subject: Re: svn commit: r324938 - head/contrib/jemalloc/include/jemalloc/internal Message-ID: <20171027152154.GA31598@spindle.one-eyed-alien.net> References: <201710232131.v9NLV4Rb068825@repo.freebsd.org> <38db6f4e-72b8-6ffd-4529-f15ca32bad54@freebsd.org> <6FD27DFB-5039-4E33-B131-EF5391DD1630@FreeBSD.org> <6eff6e66-4987-8753-105f-b6a5b8234ff3@freebsd.org> <20171027150841.GH2566@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ibTvN161/egqYuK8" Content-Disposition: inline In-Reply-To: <20171027150841.GH2566@kib.kiev.ua> User-Agent: Mutt/1.9.1 (2017-09-22) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Oct 2017 15:22:02 -0000 --ibTvN161/egqYuK8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 27, 2017 at 06:08:41PM +0300, Konstantin Belousov wrote: > On Fri, Oct 27, 2017 at 02:53:26PM +0200, Michal Meloun wrote: > > Sorry for top posting > > That's pity, we have clear problem in rtld code :( > > See: > > ----------------------------------------------------- > > RESCUE WITHOUT JEMALLOC_ALIGNED(16); > > ----------------------------------------------------- > > Program Headers: > > TLS 0xa732b0 0x00a832b0 0x00a832b0 0x00b40 0x011bc R 0x8 > > Section Headers: > > 04 .tdata .tbss .init_array .fini_array .jcr .got > > Dump: > > 00a832b0 <__je_tsd_tls+0xa832b0>: > > a832b0: 00000005 > >=20 > > GDB > > (gdb) b tsd_fetch_impl > > Breakpoint 1 at 0x7c4c08: tsd_fetch_impl. (6 locations) > > (gdb) r > > Starting program: /usr/src/rescue.noalign sh > >=20 > > Breakpoint 1, tsd_fetch_impl (init=3Dtrue, minimal=3Dfalse) at > > /usr/src/contrib/jemalloc/include/jemalloc/internal/tsd.h:261 > > 261 tsd_t *tsd =3D tsd_get(init); > > (gdb) n > > 263 if (!init && tsd_get_allocates() && tsd =3D=3D NULL) { > >=20 > > (gdb) p tsd > > $1 =3D (tsd_t *) 0x20c83008 > >=20 > > (gdb) p *tsd > > $2 =3D {state =3D 5 '\005', .... > >=20 > > (gdb) p *((tsd_t *)0x00a832b0) > > $3 =3D {state =3D 5 '\005', ... > >=20 > >=20 > >=20 > > ----------------------------------------------------- > > RESCUE WITH JEMALLOC_ALIGNED(16); > > ----------------------------------------------------- > > Program Headers: > > TLS 0xa732b0 0x00a832b0 0x00a832b0 0x00b40 0x011bc R 0x10 > > Section Headers: > > 04 .tdata .tbss .init_array .fini_array .jcr .got > > Dump: > > 00a832b0 <__je_tsd_tls+0xa832b0>: > > a832b0: 00000005 > >=20 > > GDB > > (gdb) b tsd_fetch_impl > > Breakpoint 1 at 0x7c4c08: tsd_fetch_impl. (6 locations) > > (gdb) r > > Starting program: /usr/obj/usr/src/rescue/rescue/rescue sh > > Breakpoint 1, tsd_fetch_impl (init=3Dtrue, minimal=3Dfalse) at > > /usr/src/contrib/jemalloc/include/jemalloc/internal/tsd.h:261 > > 261 tsd_t *tsd =3D tsd_get(init); > > (gdb) n > > 263 if (!init && tsd_get_allocates() && tsd =3D=3D NULL) { > >=20 > > (gdb) p tsd > > $1 =3D (tsd_t *) 0x20c83010 > >=20 > > (gdb) p *tsd > > $2 =3D {state =3D 0 '\000', ... > >=20 > > (gdb) p *((tsd_t *)0x00a832b0) > > $3 =3D {state =3D 5 '\005', ... > >=20 > > !!!! BUT p *(tsd - 8 bytes) !!!!!!!!!! > > (gdb) p *((tsd_t *)0x20c83008) > > $4 =3D {state =3D 5 '\005', ... > >=20 > > ----------------------------------------------------- > > So it's clear that: > >=20 > > - both binaries are valid, .tdata section have valid data. > > - requested alignment is propagated to binary. > > - .tdata section is properly loaded to memory because > > p *((tsd_t *)0x00a832b0) is {state =3D 5 '\005' > > in both cases > >=20 > > - a per thread copy of .tdata respect requested alignment > > but the original data was copied to unaligned address. > > because for aligned binary > > p *tsd is {state =3D 0 '\000', ... > > p *(tsd - 8 bytes) is {state =3D 5 '\005' > >=20 > > I'm right? > > Kib, please, can you help us? >=20 > Does it happen for rescue binary ? >=20 > Note that the binary is linked static, so the problem is in lib/libc/gen/= tls.c > and not in rtld. There, I do not see any real use of the phdr' p_align > value. >=20 > BTW, is rescue linked to libthr ? There isn't alignment support for TLS in static binaries. I've fixed this in CheriBSD and am planning to upstream the fixes at some point. The fix for variant I is in: https://github.com/CTSRD-CHERI/cheribsd/commit/3cfb124ebb9fdb545dad8436a04d= d58c05b33f4b -- Brooks --ibTvN161/egqYuK8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJZ808SAAoJEKzQXbSebgfA+9MIAIEYWbrBn0EtgniKuEX99BfB ojzlnG8wxeujn/Hm33lfcDVNUSfjILiZoZxwIGR9Y8ENCSyfmMGmdv9s4CQzM9Ci ihesHFajDjrrsOYCt4mm774gJtc8eDoHbN+NN46QXbdZSLX+s2qTROeLcN5SUGH/ GrQwH13Kjda1bfOoD0XyS+qqjBD3F6YPScIdxsf/zpwFcZJI85UqkwSeGKU9oXlT 3EhJCDk4q29pXMKLUTkK59oQvHVftKXi55NcZv7Fzu2f5D7ijFe+TQ9urxd5QRag yFcvMUipkVolsviweVNlLDhGWhYdNMWFHTgtDI4YQvRgPHbvRS7RtvkSVKpL9gA= =ggcJ -----END PGP SIGNATURE----- --ibTvN161/egqYuK8--