From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75485 invoked by alias); 5 Nov 2018 15:59:50 -0000 Mailing-List: contact libc-help-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: libc-help-owner@sourceware.org Received: (qmail 75470 invoked by uid 89); 5 Nov 2018 15:59:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:D*vnet.ibm.com, identify, Question, justify X-HELO: mail-qk1-f175.google.com Received: from mail-qk1-f175.google.com (HELO mail-qk1-f175.google.com) (209.85.222.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Nov 2018 15:59:47 +0000 Received: by mail-qk1-f175.google.com with SMTP id 189so15514374qkj.8 for ; Mon, 05 Nov 2018 07:59:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:references:from:openpgp:autocrypt:cc:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NkDyvrbACj+b3W0+Q+v0kCm15GM+l6u2X68Bv/YijLE=; b=eYwpXGtAP7qm0wupip0Syb+0oKzHglluNqrWyspvvIVFZlNSaTJH5Bi/loUAVuLhl5 INogIbCb2kVcxiRvC6l1cOiVdoObL6Ewd/Ed/pOoO+wrw6qFx06RxbNqJ1efdD0MmI3t QeiPjmVaTlSBVZJ20LAngbD4+4K7h38pVyXFs= Return-Path: Received: from [192.168.1.132] ([201.82.189.205]) by smtp.googlemail.com with ESMTPSA id a9-v6sm4590243qtg.70.2018.11.05.07.59.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 07:59:44 -0800 (PST) To: libc-help@sourceware.org References: From: Adhemerval Zanella Openpgp: preference=signencrypt Cc: Stefan Liebler , Andreas Krebbel Subject: Re: Question about s390 THREAD_SET_STACK_GUARD Message-ID: Date: Mon, 05 Nov 2018 15:59:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-11/txt/msg00003.txt.bz2 On 02/11/2018 19:40, Gc Frix wrote: > Hello, > > I was looking through the s390 sources and I noticed something I don't > quite understand. From sysdeps/s390/nptl/tls.h: > > ``` > /* Set the stack guard field in TCB head. */ > #define THREAD_SET_STACK_GUARD(value) \ > do \ > { \ > __asm__ __volatile__ ("" : : : "a0", "a1"); \ > THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \ > } \ > while (0) > > /* For reference, here's THREAD_SETMEM and THREAD_SELF. */ > #define THREAD_SETMEM(descr, member, value) \ > descr->member = (value) > > # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ()) > ``` > > I can't figure out what the point of the asm in THREAD_SET_STACK_GUARD > is. I know that for s390x, the thread pointer is split between a0 and > a1, and that __builtin_thread_pointer() is a GCC builtin that represents > them (__builtin_thread_pointer is completely undocumented for s390, by > the way). What I don't understand is why the asm is necessary at all. > The most I can figure is that it's meant to force a reload from a0 and > a1, but why? Shouldn't they only ever get modified by context switches > after they get set? > > I'm new to glibc, so I apologize if this is a dumb question. > > Regards, > Giancarlo Frix > For s390x the only symbol which the asm volatile seems to interfere is security_init from ld.so: $ diff -u ld-base.disas ld-patched.disas --- ld-base.disas 2018-11-05 10:02:30.575798123 -0200 +++ ld-patched.disas 2018-11-05 10:04:58.812381637 -0200 @@ -167,19 +167,19 @@ 1236: 07 07 nopr %r7 0000000000001238 : - 1238: c0 40 00 01 36 20 larl %r4,27e78 <_dl_random> - 123e: e3 30 40 00 00 04 lg %r3,0(%r4) - 1244: b2 4f 00 10 ear %r1,%a0 - 1248: eb 11 00 20 00 0d sllg %r1,%r1,32 - 124e: b2 4f 00 11 ear %r1,%a1 - 1252: e3 50 30 00 00 04 lg %r5,0(%r3) - 1258: a5 54 00 ff nihh %r5,255 - 125c: c0 20 00 01 32 fe larl %r2,27858 <__pointer_chk_guard_local> - 1262: a7 09 00 00 lghi %r0,0 - 1266: e3 50 10 28 00 24 stg %r5,40(%r1) - 126c: e3 10 30 08 00 04 lg %r1,8(%r3) - 1272: e3 00 40 00 00 24 stg %r0,0(%r4) - 1278: e3 10 20 00 00 24 stg %r1,0(%r2) + 1238: c0 10 00 01 36 20 larl %r1,27e78 <_dl_random> + 123e: b2 4f 00 20 ear %r2,%a0 + 1242: eb 22 00 20 00 0d sllg %r2,%r2,32 + 1248: e3 40 10 00 00 04 lg %r4,0(%r1) + 124e: b2 4f 00 21 ear %r2,%a1 + 1252: c0 30 00 01 33 03 larl %r3,27858 <__pointer_chk_guard_local> + 1258: e3 50 40 00 00 04 lg %r5,0(%r4) + 125e: a5 54 00 ff nihh %r5,255 + 1262: e3 50 20 28 00 24 stg %r5,40(%r2) + 1268: a7 29 00 00 lghi %r2,0 + 126c: e3 20 10 00 00 24 stg %r2,0(%r1) + 1272: e3 10 40 08 00 04 lg %r1,8(%r4) + 1278: e3 10 30 00 00 24 stg %r1,0(%r3) 127e: 07 fe br %r14 - ld-base.disas: master glibc - ld-patched.disas: master glibc with the asm removed. I can't identify any significant change that indeed justify the asm requirement neither git log gives any indication why this change was added. Stefan and Andreas, do you why and if this is required for s390?