From 4211a29e4191653db1e323fd020c6dea9f8872b2 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 22 Feb 2024 14:23:06 +0000 Subject: [PATCH] efi: de-inline xmalloc to fix build failure with gcc 12.2 and -O2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With meson build --werror --buildtype=plain -Dc_args=" -O2" the build fails: ../src/boot/efi/stub.c: In function ‘load_addons.constprop’:03:06 ../src/boot/efi/stub.c:475:40: error: using a dangling pointer to ‘p’ [-Werror=dangling-pointer=]03:06 475 | dt_bases[n_dt] = xmemdup((uint8_t*)loaded_addon->ImageBase + addrs[UNIFIED_SECTION_DTB],03:06 | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~03:06 476 | dt_sizes[n_dt]);03:06 | ~~~~~~~~~~~~~~~03:06 In file included from ../src/boot/efi/stub.c:20:03:06 ../src/boot/efi/util.h:33:15: note: ‘p’ declared here03:06 33 | void *p;03:06 | ^ De-inline the function and initialize p to make gcc happy. (cherry picked from commit 6036f62c51aea80e199b8c81f8ceb16b5a1a341a) (cherry picked from commit 4cf3445955e9b539fd4dcbd14810913a3054c8a5) --- src/boot/efi/util.c | 6 ++++++ src/boot/efi/util.h | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 3778a26f530..33a04fc2c13 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -707,3 +707,9 @@ char16_t *get_extra_dir(const EFI_DEVICE_PATH *file_path) { remove_boot_count(file_path_str); return xasprintf("%ls.extra.d", file_path_str); } + +void *xmalloc(size_t size) { + void *p = NULL; + assert_se(BS->AllocatePool(EfiLoaderData, size, &p) == EFI_SUCCESS); + return p; +} diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index bc5538cc993..719e5fd5549 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -29,11 +29,7 @@ static inline void freep(void *p) { #define _cleanup_free_ _cleanup_(freep) _malloc_ _alloc_(1) _returns_nonnull_ _warn_unused_result_ -static inline void *xmalloc(size_t size) { - void *p; - assert_se(BS->AllocatePool(EfiLoaderData, size, &p) == EFI_SUCCESS); - return p; -} +void *xmalloc(size_t size); _malloc_ _alloc_(1, 2) _returns_nonnull_ _warn_unused_result_ static inline void *xmalloc_multiply(size_t n, size_t size) {