From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nXXZL-0000N2-H2 for mharc-grub-devel@gnu.org; Thu, 24 Mar 2022 20:12:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXXZJ-0000Lx-RW for grub-devel@gnu.org; Thu, 24 Mar 2022 20:12:41 -0400 Received: from [2607:f8b0:4864:20::82d] (port=46627 helo=mail-qt1-x82d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nXXZH-00077Q-J4 for grub-devel@gnu.org; Thu, 24 Mar 2022 20:12:41 -0400 Received: by mail-qt1-x82d.google.com with SMTP id b18so5296244qtk.13 for ; Thu, 24 Mar 2022 17:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FG694Ykhy89Ij4IUhWa8S75MKdniFxCzGb/g7t+vxb4=; b=T0bPb5oC60LYRQfBH8UHyFcOLKFydNFKXGwVuPqMuKL0saj7XeAGVSZryLsj1vO+LR eMhbYEOOSzgMXKYgmW7IhS2YZuyx1O94eabsHtcLr6pmvre5X9Fbcz9jr7o69mt3YU99 dfFVVuDs5eD2/t+6rP7WSgACzoTzJn9TWPyFKfwrrBxVZ2JI2i19qQPvgXuyT1rT6Rn8 HMxJPhYbIg1FPZ1YyfVlHpalwOO+NNZtEBMhkDc2Gxh+0DhAFmXy3nS4BHQ9aCbS0LMq H/Ote8xuwU4NEidUjeFikTH5EF7vTNjdC/duciyF+cBQ3bJFp4zLehZNShXbw9BP8/U8 k5FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FG694Ykhy89Ij4IUhWa8S75MKdniFxCzGb/g7t+vxb4=; b=sB1+Da02uL448iP6JKLP2N04bS6j3/62h2VYjZzRS1l71yKAehxu1kg2QE6CocF/Bc PDWKPYKoaAFFsmMIxTNDdBe/PrqAEgZPxNb//rd+1s5mEe88sjmMF/es0qTwY2fKBSSD 4N8AsETTtVzD4mjoSqv0NoYewLk+pPy+BJ9s899TDZQcXx82CnDZ9hhMfsrz3/DCQsj6 8VMzSNX5IBNLd5Hj9lVKKZGWTXqk/z6LKlZ57oXe6xfDG4/X4rRNzEi66aHEEm6XmNnD im71kC2+R3zv7M0EReexcgUpQPBYIVlJ3CsztWEyoHB4PwFGQVG7zhfF08u1WXLz0JBU UB8Q== X-Gm-Message-State: AOAM5327Bpt/dmSADJoLNif6/+kWibnwPErCtTgReo2r8in+qWoqiLZI +MXqBCUUxHnmPwemuCqw/vu++OYfHQOhjg== X-Google-Smtp-Source: ABdhPJx3mh1RxZhjObCQH5N/Wxzsi87So8IuuIcZy+YtAizyGLNumsO8ZixrBtFj8T0BzK9R0Fn9xg== X-Received: by 2002:a05:622a:1015:b0:2e0:6cd5:7ee1 with SMTP id d21-20020a05622a101500b002e06cd57ee1mr6751412qte.485.1648167158097; Thu, 24 Mar 2022 17:12:38 -0700 (PDT) Received: from localhost.localdomain ([199.58.83.10]) by smtp.gmail.com with ESMTPSA id s131-20020a37a989000000b0067d2e3c51e8sm2346076qke.58.2022.03.24.17.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 17:12:37 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH] gnulib: Handle aborts in gnulib more gracefully Date: Thu, 24 Mar 2022 19:12:22 -0500 Message-Id: <20220325001222.3330852-1-development@efficientek.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::82d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::82d; envelope-from=development@efficientek.com; helo=mail-qt1-x82d.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Mar 2022 00:12:42 -0000 Gnulib does not define abort(), but expects it to be defined, usually by a libc implementation. However, GRUB has no libc and does not have an abort() function. Until recently GRUB had patched out abort() in gnulib, effectively making it a noop. This changed with a recent update of the version of gnulib GRUB uses to be a compiler defined trap. While this is fine for user space code where the kernel can be expected to cleanup after a process when this happens, the firmware may not be good at doing this. GRUB does have a grub_abort(), with the same function signature that can be used instead. So instead define gnulib's abort() implementation to be grub_abort(). This provides consistency of behavior regardless of whether the abort happens in gnulib code or in GRUB code. Because we want to avoid patching gnulib again and gnulib expects that abort(), now grub_abort(), is defined externally, we must provide a prototype in the config.h. This is complicated by the fact that config.h is included in many GRUB compilation units as well as grub/misc.h which already declares grub_abort(). A macro, GNULIB, is provided only to compilation units using gnulib code, so that the grub_abort() prototype is only included in those compilation units where it is lacking. Also, export grub_abort() so that it can now be used within modules. Signed-off-by: Glenn Washburn --- conf/Makefile.common | 2 +- config.h.in | 17 ++++++++++------- grub-core/kern/misc.c | 2 +- include/grub/misc.h | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/conf/Makefile.common b/conf/Makefile.common index b343a038ee..67996b710c 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -65,7 +65,7 @@ grubconfdir = $(sysconfdir)/grub.d platformdir = $(pkglibdir)/$(target_cpu)-$(platform) starfielddir = $(pkgdatadir)/themes/starfield -CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion +CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -DGNULIB=1 CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib CFLAGS_POSIX = -fno-builtin diff --git a/config.h.in b/config.h.in index 01dcbbfc82..5719b28ebe 100644 --- a/config.h.in +++ b/config.h.in @@ -139,14 +139,17 @@ typedef __UINT_FAST32_TYPE__ uint_fast32_t; # define _GL_INLINE_HEADER_END _Pragma ("GCC diagnostic pop") /* - * We don't have an abort() for gnulib to call in regexp. Because gnulib is - * built as a separate object that is then linked with, it doesn't have any - * of our headers or functions around to use - so we unfortunately can't - * print anything. Builds of emu include the system's stdlib, which includes - * a prototype for abort(), so leave this as a macro that doesn't take - * arguments. + * We don't have an abort() for gnulib's functions to call (eg. in regexp), but + * one needs to be provided and grub_abort() is the equivalent. Gnulib does not + * provide a prototype for abort either, so one must be provided. However, this + * duplicates the prototype in grub/misc.h for GRUB compilation units, which + * causes a failure to compile. So only include the prototype if this is in a + * gnulib compilation unit. */ -# define abort __builtin_trap +# ifdef GNULIB +# define abort grub_abort +void __attribute__ ((noreturn)) abort (void); +# endif # endif /* !_GL_INLINE_HEADER_BEGIN */ /* gnulib doesn't build cleanly with older compilers. */ diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 6c0221cc33..dfae4f9d78 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -1249,7 +1249,7 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected) /* Abort GRUB. This function does not return. */ -static void __attribute__ ((noreturn)) +void __attribute__ ((noreturn)) grub_abort (void) { grub_printf ("\nAborted."); diff --git a/include/grub/misc.h b/include/grub/misc.h index 7d2b551969..776dbf8af0 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -353,6 +353,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT; char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT; +void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint64_t d, -- 2.27.0