From patchwork Thu May 5 15:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 53524 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 2EC4E3857404 for ; Thu, 5 May 2022 15:08:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EC4E3857404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651763285; bh=mRNW2DFkr34CVoPWTF/0AEe+ssG7RoIbAgkOHBJwW88=; 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=tzbW+4ookW1OpNJtLZI3gDi3Pb6XxNafk2b8vdSZu/P34lPdEWgMLIkuKCkT0hDBq YSUvLPszfnbXMjmFNaNIepzIGb3bxuX4kGR9nbQwXv9WnYB/jB0G+04Xlp1/Kd+gfe M6+plT9lnjpL+b/nxQD0t7IgSk+ks8oVAZZwUMMo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by sourceware.org (Postfix) with ESMTPS id 73C313857C4A for ; Thu, 5 May 2022 15:07:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73C313857C4A 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-258-CyU5OOJSOw-a7sRfp-kzlQ-1; Thu, 05 May 2022 11:07:32 -0400 X-MC-Unique: CyU5OOJSOw-a7sRfp-kzlQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEDE0811E78 for ; Thu, 5 May 2022 15:07:31 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 296FE55BA9A for ; Thu, 5 May 2022 15:07:30 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v4 2/3] Linux: Implement a useful version of _startup_fatal In-Reply-To: References: X-From-Line: 71808d9fc272aa3cfb78c905dd5aedd39bb903f6 Mon Sep 17 00:00:00 2001 Message-Id: <71808d9fc272aa3cfb78c905dd5aedd39bb903f6.1651762968.git.fweimer@redhat.com> Date: Thu, 05 May 2022 17:07:29 +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.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 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_NONE, 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. Reviewed-by: Adhemerval Zanella --- v4: Unchanged. v3: Use 2022 copyright year. Fix “statup” typo. Use __message_length local variable in _startup_fatal. sysdeps/unix/sysv/linux/i386/startup.h | 23 +++------------ sysdeps/unix/sysv/linux/ia64/startup.h | 22 +++++++++++++++ sysdeps/unix/sysv/linux/startup.h | 39 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 19 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..213805d7d2 100644 --- a/sysdeps/unix/sysv/linux/i386/startup.h +++ b/sysdeps/unix/sysv/linux/i386/startup.h @@ -1,5 +1,5 @@ /* Linux/i386 definitions of functions used by static libc main startup. - Copyright (C) 2017-2022 Free Software Foundation, Inc. + Copyright (C) 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 @@ -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 startup. */ +#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..77f29f15a2 --- /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) 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..39859b404a --- /dev/null +++ b/sysdeps/unix/sysv/linux/startup.h @@ -0,0 +1,39 @@ +/* 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 */