]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Do not use errno.h/inttypes.h
authorJan Janssen <medhefgo@web.de>
Sat, 7 Jan 2023 08:19:23 +0000 (09:19 +0100)
committerJan Janssen <medhefgo@web.de>
Tue, 21 Feb 2023 20:07:04 +0000 (21:07 +0100)
These are provided by libc instead of the compiler and are not supposed
to be used in freestanding environments.
When cross-compiling with clang and the corresponding gcc
cross-toolchain is not around, clang may pick up the wrong header from
the host system.

src/boot/efi/boot.c
src/boot/efi/efi-string.h
src/boot/efi/util.c
src/fundamental/efivars-fundamental.h

index 79cb36c717a195032de57f4a1596ca6c918686e3..e409168aa43b6b1733c6237c9bfbff3c248d70d6 100644 (file)
@@ -1,7 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <inttypes.h>
-
 #include "bcd.h"
 #include "bootspec-fundamental.h"
 #include "console.h"
index ea9493bcbb29bfc6ae5eac6aa0ea60748b97aff8..6b6b0d57b4601b5fde6851aae04ff2e49b84c5be 100644 (file)
@@ -121,6 +121,32 @@ _gnu_printf_(2, 0) _warn_unused_result_ char16_t *xvasprintf_status(EFI_STATUS s
 #  define printf(...) printf_status(EFI_SUCCESS, __VA_ARGS__)
 #  define xasprintf(...) xasprintf_status(EFI_SUCCESS, __VA_ARGS__)
 
+/* inttypes.h is provided by libc instead of the compiler and is not supposed to be used in freestanding
+ * environments. We could use clang __*_FMT*__ constants for this, bug gcc does not have them. :( */
+
+#  if defined(__ILP32__)
+#    define PRI64_PREFIX "ll"
+#  elif defined(__LP64__)
+#    define PRI64_PREFIX "l"
+#  elif defined(__LLP64__) || (__SIZEOF_LONG__ == 4 && __SIZEOF_POINTER__ == 8)
+#    define PRI64_PREFIX "ll"
+#  else
+#    error Unknown 64-bit data model
+#  endif
+
+#  define PRIi32 "i"
+#  define PRIu32 "u"
+#  define PRIx32 "x"
+#  define PRIX32 "X"
+#  define PRIiPTR "zi"
+#  define PRIuPTR "zu"
+#  define PRIxPTR "zx"
+#  define PRIXPTR "zX"
+#  define PRIi64 PRI64_PREFIX "i"
+#  define PRIu64 PRI64_PREFIX "u"
+#  define PRIx64 PRI64_PREFIX "x"
+#  define PRIX64 PRI64_PREFIX "X"
+
 /* The compiler normally has knowledge about standard functions such as memcmp, but this is not the case when
  * compiling with -ffreestanding. By referring to builtins, the compiler can check arguments and do
  * optimizations again. Note that we still need to provide implementations as the compiler is free to not
index 48b30a8f5a53584138db443001e4b76e26e5b51c..3166944b03f804f4f6b17fb5750ad22650a767af 100644 (file)
@@ -1,7 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <inttypes.h>
-
 #include "proto/device-path.h"
 #include "proto/simple-text-io.h"
 #include "ticks.h"
index cf785f8b7de20102f984265337e6c9989f0566bc..3bad79b0363ff3ec3c80e626cd46401da4415f72 100644 (file)
@@ -1,7 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <errno.h>
+#ifdef SD_BOOT
+#  define EINVAL 22
+#else
+#  include <errno.h>
+#endif
 #include "string-util-fundamental.h"
 
 /* Features of the loader, i.e. systemd-boot */