From patchwork Wed May 4 16:48:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 53470 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A3D6385734B for ; Wed, 4 May 2022 16:49:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A3D6385734B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651682956; bh=2TegBWK/gupEspWoxzNT/yMCi/sRRJx/opa3WNwoAX0=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pWUiCY/g3TwvW9PrDPOli1988JyqXXVs7ROUIZ7QXESaW6m49R1EYIbwwVRYetYti NkSpAuRYMxTx0udG7tBmfkX8F6Wpy+Mv0hpmykScEp0T4wS90zFaqzEcEvg+Tt5Wgu /oCrRVVIwayvn8lWQy7Xt0XEsksimHuoJbC2R3Cs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1EACD3858C53 for ; Wed, 4 May 2022 16:48:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EACD3858C53 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-WSiFA_SeM_OMJRra0y0KKQ-1; Wed, 04 May 2022 12:48:50 -0400 X-MC-Unique: WSiFA_SeM_OMJRra0y0KKQ-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 961D238149A3; Wed, 4 May 2022 16:48:50 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B1FD15674F3; Wed, 4 May 2022 16:48:49 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/3] Linux: Implement a useful version of _startup_fatal In-Reply-To: References: X-From-Line: 63235b8cfce808ff0c6fd07d5710faaf2e692f88 Mon Sep 17 00:00:00 2001 Message-Id: <63235b8cfce808ff0c6fd07d5710faaf2e692f88.1651682800.git.fweimer@redhat.com> Date: Wed, 04 May 2022 18:48:47 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" On i386 and ia64, the TCB is not available at this point. --- v2: Add ia64 override. On i386, use non-TCB version for non-PIE static, too. sysdeps/unix/sysv/linux/i386/startup.h | 21 ++------------ sysdeps/unix/sysv/linux/ia64/startup.h | 22 +++++++++++++++ sysdeps/unix/sysv/linux/startup.h | 38 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/ia64/startup.h create mode 100644 sysdeps/unix/sysv/linux/startup.h diff --git a/sysdeps/unix/sysv/linux/i386/startup.h b/sysdeps/unix/sysv/linux/i386/startup.h index 67c9310f3a..85534d09f1 100644 --- a/sysdeps/unix/sysv/linux/i386/startup.h +++ b/sysdeps/unix/sysv/linux/i386/startup.h @@ -16,22 +16,7 @@ License along with the GNU C Library; if not, see . */ -#if BUILD_PIE_DEFAULT -/* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE. */ -# define I386_USE_SYSENTER 0 +/* Can't use "call *%gs:SYSINFO_OFFSET" during statup. */ +#define I386_USE_SYSENTER 0 -# include -# include - -__attribute__ ((__noreturn__)) -static inline void -_startup_fatal (const char *message __attribute__ ((unused))) -{ - /* This is only called very early during startup in static PIE. - FIXME: How can it be improved? */ - ABORT_INSTRUCTION; - __builtin_unreachable (); -} -#else -# include_next -#endif +#include_next diff --git a/sysdeps/unix/sysv/linux/ia64/startup.h b/sysdeps/unix/sysv/linux/ia64/startup.h new file mode 100644 index 0000000000..68fcd9fea0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/ia64/startup.h @@ -0,0 +1,22 @@ +/* Linux/ia64 definitions of functions used by static libc main startup. + Copyright (C) 2017-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This code is used before the TCB is set up. */ +#define IA64_USE_NEW_STUB 0 + +#include_next diff --git a/sysdeps/unix/sysv/linux/startup.h b/sysdeps/unix/sysv/linux/startup.h new file mode 100644 index 0000000000..a5de941759 --- /dev/null +++ b/sysdeps/unix/sysv/linux/startup.h @@ -0,0 +1,38 @@ +/* Linux definitions of functions used by static libc main startup. + Copyright (C) 2017-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifdef SHARED +# include_next +#else +# include + +/* Avoid a run-time invocation of strlen. */ +#define _startup_fatal(message) \ + do \ + { \ + size_t message_length = __builtin_strlen (message); \ + if (! __builtin_constant_p (message_length)) \ + { \ + extern void _startup_fatal_not_constant (void); \ + _startup_fatal_not_constant (); \ + } \ + INTERNAL_SYSCALL_CALL (write, STDERR_FILENO, message, message_length); \ + INTERNAL_SYSCALL_CALL (exit_group, 127); \ + } \ + while (0) +#endif /* !SHARED */