From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 32F4E3858D28 for ; Wed, 12 Apr 2023 15:27:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32F4E3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681313253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7eOtLMOnD9+Wslz931AVKqYbp176MZpTOzAQjGoVgIA=; b=Ex9qEzWClkHppSzeUh9v6cgTnytT/Sj+XKH+nBwMh7P7YEQqALWjsMLduwoELROnv6hxhS 5us0hI3xjkfoLKQXOK1+AFBp/8Q/k77EPjShnuHK/Ty50dGd/L1cyYoKh92j+g4nKLlps4 570yQbr9h0QaIuWz5IGIgdArd5/ej/U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-478-zylQrjvYMgOb7VWkfsKAtg-1; Wed, 12 Apr 2023 11:27:30 -0400 X-MC-Unique: zylQrjvYMgOb7VWkfsKAtg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83036101A54F; Wed, 12 Apr 2023 15:27:30 +0000 (UTC) Received: from oak (unknown [10.22.34.175]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61B0F1415117; Wed, 12 Apr 2023 15:27:30 +0000 (UTC) Date: Wed, 12 Apr 2023 11:27:29 -0400 From: Joe Simmons-Talbott To: Adhemerval Zanella Netto Cc: Florian Weimer , Joe Simmons-Talbott via Libc-alpha Subject: Re: [PATCH 2/2] aarch64: Set the syscall register right before doing the syscall. Message-ID: <20230412152455.GB2106608@oak> References: <20230411133004.2268170-1-josimmon@redhat.com> <20230411133004.2268170-3-josimmon@redhat.com> <87h6tmil4j.fsf@oldenburg.str.redhat.com> <87a5zeieym.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Apr 11, 2023 at 01:39:31PM -0300, Adhemerval Zanella Netto wrote: > > > On 11/04/23 13:03, Florian Weimer wrote: > > * Adhemerval Zanella Netto: > > > >> On 11/04/23 10:50, Florian Weimer via Libc-alpha wrote: > >>> * Joe Simmons-Talbott via Libc-alpha: > >>> > >>>> ({ long _sys_result; \ > >>>> { \ > >>>> LOAD_ARGS_##nr (args) \ > >>>> register long _x8 asm ("x8") = (name); \ > >>>> + if (__builtin_constant_p(name)) \ > >>>> + asm volatile ("mov x8, " MSTR(name) ";" \ > >>>> + : /* no output */ : "i" (name) : "x8"); \ > >>>> asm volatile ("svc 0 // syscall " # name \ > >>>> : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \ > >>>> _sys_result = _x0; \ > >>> > >>> I think you should do this in a single assembler statement, load the > >>> constant only once. > >> > >> Is this required because compiler is free to reorganize the argument > >> list? I think it should me it clear on the commit message. > > > > Yes, that's the reason. It's a bit tricky to recover the system call > > number using static analysis otherwise. I suggested to Joe that we > > should put something into glibc, rather than improving that static > > analysis tool so that it's fully reliable. > > Direct syscalls are done by different projects, like sanitizer, libgomp, > etc; so imho improving the static analysis tool could potentially catch > a wide range of usages than trying to fix only on glibc. > I agree that improving the static analysis tool would be helpful. One thing to keep in mind is that this patchset will also aid people doing static analysis manually. It also seems likely that other static analysis tools would benefit from this change. Thanks, Joe