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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id CEE353857C7A for ; Thu, 28 Jan 2021 22:18:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CEE353857C7A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-harQW2XlPqKWp0Stm0vu-g-1; Thu, 28 Jan 2021 17:17:58 -0500 X-MC-Unique: harQW2XlPqKWp0Stm0vu-g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF02E801817; Thu, 28 Jan 2021 22:17:57 +0000 (UTC) Received: from greed.delorie.com (ovpn-114-77.rdu2.redhat.com [10.10.114.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 992955C1B4; Thu, 28 Jan 2021 22:17:57 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 10SMHt0J004940; Thu, 28 Jan 2021 17:17:55 -0500 From: DJ Delorie To: "Madhavan T. Venkataraman" Cc: libffi-discuss@sourceware.org Subject: Re: [RFC PATCH v3 2/5] x86: Support for Static Trampolines In-Reply-To: (madvenka@linux.microsoft.com) Date: Thu, 28 Jan 2021 17:17:55 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libffi-discuss@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libffi-discuss mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jan 2021 22:18:02 -0000 "Madhavan T. Venkataraman" writes: >> Extern, but local to this port, yes? > > Yes. So, is this declaration acceptable? Yup! >>> + /* Initialize the dynamic trampoline. */ >> >> Should these new APIs be inside #if FFI_EXEC_STATIC_TRAMP ? >> > > Strictly speaking, these should be inside that ifdef. I did it this > way to avoid too many ifdefs in the code. If you prefer I put them > inside the ifdefs, I will do it. I will try to minimize the number of > ifdefs somehow. No, it's ok, I was just worried that if ffi_tramp_is_present was in an #ifdef any callers would be too - but as you noted in another email, there's always a ffi_tramp_is_present even if it always returns false. >> This hack to detect CET should be replaced by the logic in ffitarget.h, >> or add a #define CET_ENABLED to ffitarget.h >> > > So, _CET_ENDBR for x64 is either defined as: > > If CET is present: > #define _CET_ENDBR endbr64 > Otherwise: > #define _CET_ENDBR > > So, it is always defined. So, I cannot do something like: I was thinking of the conditionals in src/x86/ffitarget.h: #if !defined(GENERATE_LIBFFI_MAP) && defined(__ASSEMBLER__) \ && defined(__CET__) Obviously you'd omit the __ASSEMBLER__ one ;-) If you duplicate the ffitarget.h logic you get the same results. >> Copies first argument to %r10, discards return address and arg - closure >> will return to whoever called it's caller. I'm not sure how this works, >> which means *at least* a comment needs to be here ;-) >> > The target code in this case is the alt entry point. > > This is what the alt code is doing: > - load the data (closure) address in r10 > - discard the original value of r10 saved on the stack > since we are using r10 we don't need its original value > - restore the stack back to what it was when the static trampoline was > invoked. These kinds of short notes should be useful inline comments in the assembler: movq 8(%rsp), %r10 /* load closure */ > I could add a small comment saying "see comment above trampoline_code_table". > Is that acceptable? That would be good too :-)