| From 0735ec2e76541d51678ec9da0cc3392ffbad71ce Mon Sep 17 00:00:00 2001 |
| From: Oleksandr Tymoshenko <ovt@google.com> |
| Date: Wed, 10 Feb 2021 22:59:41 +0000 |
| Subject: [PATCH 6/8] grub-lakitu: fix clang build |
| |
| - Hack _data value for a backtrace code, it's not used so no functional impact |
| - Remove gcc-specific -fno-trampolines |
| - Rewrite hack with a nested function |
| - Fix -isystem check, clang ships with some headers, but not all, so |
| test was false positive |
| - Remove duplicate clang-specific definition of abort() function |
| --- |
| conf/Makefile.common | 2 +- |
| configure.ac | 5 ++- |
| grub-core/kern/arm64/backtrace.c | 2 +- |
| grub-core/kern/compiler-rt.c | 9 ----- |
| grub-core/kern/i386/backtrace.c | 2 +- |
| grub-core/net/net.c | 64 ++++++++++++++++---------------- |
| 6 files changed, 38 insertions(+), 46 deletions(-) |
| |
| diff --git a/conf/Makefile.common b/conf/Makefile.common |
| index 6b85eb394..b484c5abe 100644 |
| --- a/conf/Makefile.common |
| +++ b/conf/Makefile.common |
| @@ -69,7 +69,7 @@ starfielddir = $(pkgdatadir)/themes/starfield |
| systemdunitdir = ${prefix}/lib/systemd/system |
| systemd_logind_service_ddir = $(systemdunitdir)/systemd-logind.service.d |
| |
| -CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines |
| +CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines |
| CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib |
| |
| CFLAGS_POSIX = -fno-builtin |
| diff --git a/configure.ac b/configure.ac |
| index d150a2e4a..dc6b75c9d 100644 |
| --- a/configure.ac |
| +++ b/configure.ac |
| @@ -1492,6 +1492,7 @@ AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [ |
| CPPFLAGS="$TARGET_CPPFLAGS -nostdlib -nostdinc -isystem `$TARGET_CC -print-file-name=include`" |
| AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h> |
| #include <stddef.h> |
| +#include <stdio.h> |
| int va_arg_func (int fixed, va_list args);]], [[]])], |
| [grub_cv_cc_isystem=yes], |
| [grub_cv_cc_isystem=no]) |
| @@ -2015,8 +2016,8 @@ if test x"$enable_wextra" != xno ; then |
| HOST_CFLAGS="$HOST_CFLAGS -Wextra" |
| fi |
| |
| -TARGET_CFLAGS="$TARGET_CFLAGS -Werror=trampolines -fno-trampolines" |
| -HOST_CFLAGS="$HOST_CFLAGS -Werror=trampolines -fno-trampolines" |
| +TARGET_CFLAGS="$TARGET_CFLAGS -Werror=trampolines" |
| +HOST_CFLAGS="$HOST_CFLAGS -Werror=trampolines" |
| |
| TARGET_CPP="$TARGET_CC -E" |
| TARGET_CCAS=$TARGET_CC |
| diff --git a/grub-core/kern/arm64/backtrace.c b/grub-core/kern/arm64/backtrace.c |
| index 019c6fdfe..9d3d8d50d 100644 |
| --- a/grub-core/kern/arm64/backtrace.c |
| +++ b/grub-core/kern/arm64/backtrace.c |
| @@ -78,7 +78,7 @@ asm ("\t.global \"_text\"\n" |
| "\t.quad .text\n" |
| "\t.global \"_data\"\n" |
| "_data:\n" |
| - "\t.quad .data\n" |
| + "\t.quad 0\n" |
| ); |
| |
| extern grub_uint64_t _text; |
| diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c |
| index a464200c6..762d1a251 100644 |
| --- a/grub-core/kern/compiler-rt.c |
| +++ b/grub-core/kern/compiler-rt.c |
| @@ -195,15 +195,6 @@ __ctzsi2 (grub_uint32_t x) |
| #endif |
| |
| |
| -#if defined (__clang__) && !defined(GRUB_EMBED_DECOMPRESSOR) |
| -/* clang emits references to abort(). */ |
| -void __attribute__ ((noreturn)) |
| -abort (void) |
| -{ |
| - grub_fatal ("compiler abort"); |
| -} |
| -#endif |
| - |
| #if (defined (__MINGW32__) || defined (__CYGWIN__)) |
| void __register_frame_info (void) |
| { |
| diff --git a/grub-core/kern/i386/backtrace.c b/grub-core/kern/i386/backtrace.c |
| index 2413f9a57..99ca5322a 100644 |
| --- a/grub-core/kern/i386/backtrace.c |
| +++ b/grub-core/kern/i386/backtrace.c |
| @@ -78,7 +78,7 @@ asm ("\t.global \"_text\"\n" |
| "\t.quad .text\n" |
| "\t.global \"_data\"\n" |
| "_data:\n" |
| - "\t.quad .data\n" |
| + "\t.quad 0\n" |
| ); |
| #elif defined(__i386__) |
| asm ("\t.global \"_text\"\n" |
| diff --git a/grub-core/net/net.c b/grub-core/net/net.c |
| index ad024c9ef..beb12de57 100644 |
| --- a/grub-core/net/net.c |
| +++ b/grub-core/net/net.c |
| @@ -1893,43 +1893,43 @@ grub_net_restore_hw (void) |
| return GRUB_ERR_NONE; |
| } |
| |
| -grub_err_t |
| -grub_net_search_configfile (char *config) |
| +static int |
| +search_through (char *config, char *suffix, grub_size_t num_tries, grub_size_t slice_size) |
| { |
| - grub_size_t config_len; |
| - char *suffix; |
| - |
| - auto int search_through (grub_size_t num_tries, grub_size_t slice_size); |
| - int search_through (grub_size_t num_tries, grub_size_t slice_size) |
| + while (num_tries-- > 0) |
| { |
| - while (num_tries-- > 0) |
| - { |
| grub_dprintf ("net", "probe %s\n", config); |
| |
| - grub_file_t file; |
| - file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); |
| + grub_file_t file; |
| + file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); |
| |
| - if (file) |
| - { |
| - grub_file_close (file); |
| - grub_dprintf ("net", "found!\n"); |
| - return 0; |
| - } |
| - else |
| - { |
| - if (grub_errno == GRUB_ERR_IO) |
| - grub_errno = GRUB_ERR_NONE; |
| - } |
| - |
| - if (grub_strlen (suffix) < slice_size) |
| - break; |
| - |
| - config[grub_strlen (config) - slice_size] = '\0'; |
| + if (file) |
| + { |
| + grub_file_close (file); |
| + grub_dprintf ("net", "found!\n"); |
| + return 0; |
| } |
| + else |
| + { |
| + if (grub_errno == GRUB_ERR_IO) |
| + grub_errno = GRUB_ERR_NONE; |
| + } |
| + |
| + if (grub_strlen (suffix) < slice_size) |
| + break; |
| |
| - return 1; |
| + config[grub_strlen (config) - slice_size] = '\0'; |
| } |
| |
| + return 1; |
| +} |
| + |
| +grub_err_t |
| +grub_net_search_configfile (char *config) |
| +{ |
| + grub_size_t config_len; |
| + char *suffix; |
| + |
| config_len = grub_strlen (config); |
| config[config_len] = '-'; |
| suffix = config + config_len + 1; |
| @@ -1959,7 +1959,7 @@ grub_net_search_configfile (char *config) |
| if (client_uuid) |
| { |
| grub_strcpy (suffix, client_uuid); |
| - if (search_through (1, 0) == 0) return GRUB_ERR_NONE; |
| + if (search_through (config, suffix, 1, 0) == 0) return GRUB_ERR_NONE; |
| } |
| |
| /* By the MAC address. */ |
| @@ -1974,7 +1974,7 @@ grub_net_search_configfile (char *config) |
| if (*ptr == ':') |
| *ptr = '-'; |
| |
| - if (search_through (1, 0) == 0) return GRUB_ERR_NONE; |
| + if (search_through (config, suffix, 1, 0) == 0) return GRUB_ERR_NONE; |
| |
| /* By IP address */ |
| |
| @@ -1987,7 +1987,7 @@ grub_net_search_configfile (char *config) |
| ((n >> 24) & 0xff), ((n >> 16) & 0xff), \ |
| ((n >> 8) & 0xff), ((n >> 0) & 0xff)); |
| |
| - if (search_through (8, 1) == 0) return GRUB_ERR_NONE; |
| + if (search_through (config, suffix, 8, 1) == 0) return GRUB_ERR_NONE; |
| break; |
| } |
| case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6: |
| @@ -2003,7 +2003,7 @@ grub_net_search_configfile (char *config) |
| *ptr = '-'; |
| |
| grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf); |
| - if (search_through (1, 0) == 0) return GRUB_ERR_NONE; |
| + if (search_through (config, suffix, 1, 0) == 0) return GRUB_ERR_NONE; |
| break; |
| } |
| case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: |
| -- |
| 2.30.1.766.gb4fecdf3b7-goog |
| |