Skip to content

Commit

Permalink
efi: de-inline xmalloc to fix build failure with gcc 12.2 and -O2
Browse files Browse the repository at this point in the history
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 6036f62)
(cherry picked from commit 4cf3445)
(cherry picked from commit 4211a29)
  • Loading branch information
bluca committed Feb 28, 2024
1 parent 049c083 commit e31a074
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/boot/efi/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,9 @@ void *find_configuration_table(const EFI_GUID *guid) {
_used_ _noreturn_ int raise(int sig) {
assert_not_reached();
}

void *xmalloc(size_t size) {
void *p = NULL;
assert_se(BS->AllocatePool(EfiLoaderData, size, &p) == EFI_SUCCESS);
return p;
}
6 changes: 1 addition & 5 deletions src/boot/efi/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,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) {
Expand Down

0 comments on commit e31a074

Please sign in to comment.