Skip to contentSkip to conversation

gnu-efi: fix stdint include location

PATCH New james.hilliard1 at gmail.com 2 participants 3 messages Jan 26, 2019 – Feb 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gnu-efi: fix stdint include location

From: James Hilliard <[email protected]>

Some applications such as systemd-boot include efilink.h without a libc. Move the stdint.h include to lib.h so that efilink.h can be used directly without requiring a libc.

---
 .../0001-efilink-fix-build-with-gcc-4.8.patch      | 35 ++++++++++------------
 1 file changed, 16 insertions(+), 19 deletions(-)
package/gnu-efi/0001-efilink-fix-build-with-gcc-4.8.patch +16 -19
index 57c78c9..7dc8d8d 100644
@@ -1,5 +1,5 @@
-From 6335e5c697c57d8b5854b8202de3733bcb151ca6 Mon Sep 17 00:00:00 2001
-From: Fabrice Fontaine <[email protected]>
+From 92d0653f09aa44b24b9306fa9384f13d2c9f1a24 Mon Sep 17 00:00:00 2001
+From: James Hilliard <[email protected]>
 Date: Fri, 18 Jan 2019 22:05:37 +0100
 Subject: [PATCH] efilink: fix build with gcc 4.8
 
@@ -8,28 +8,25 @@ intptr_t is undefined without an include on stdint.h
 Fixes:
  - http://autobuild.buildroot.org/results/a0ca37b5ed27af445344e3ac49dc87bb17512c50
 
-Signed-off-by: Fabrice Fontaine <[email protected]>
+Signed-off-by: James Hilliard <[email protected]>
 [Upstream status:
-https://sourceforge.net/p/gnu-efi/code/merge-requests/3]
+https://sourceforge.net/p/gnu-efi/code/merge-requests/4]
 ---
- inc/efilink.h | 4 ++++
- 1 file changed, 4 insertions(+)
+ lib/lib.h | 1 +
+ 1 file changed, 1 insertion(+)
 
-diff --git a/inc/efilink.h b/inc/efilink.h
-index cc5aa2d..b69a6fd 100644
---- a/inc/efilink.h
-+++ b/inc/efilink.h
-@@ -1,6 +1,10 @@
- #ifndef _EFI_LINK_H
- #define _EFI_LINK_H
+diff --git a/lib/lib.h b/lib/lib.h
+index 37fbb95..7858cd0 100644
+--- a/lib/lib.h
++++ b/lib/lib.h
+@@ -18,6 +18,7 @@ Revision History
  
-+#if defined(__GNUC__)
+ #ifdef __GNUC__
+ #pragma GCC visibility push(hidden)
 +#include <stdint.h>
-+#endif
-+
- /*++
+ #endif
  
- Copyright (c) 1998  Intel Corporation
+ #include "efi.h"
 -- 
-2.14.1
+2.7.4
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 gnu-efi: fix stdint include location

Hello James,

Quoted 5 lines · On Sat, 26 Jan 2019 08:03:05 +0800 james.hilliard1 at gmail.com wrote:

From: James Hilliard <[email protected]>

Some applications such as systemd-boot include efilink.h without a libc. Move the stdint.h include to lib.h so that efilink.h can be used directly without requiring a libc.

This is a bit weird: gcc does provide <stdint.h>. It contains something like this:

#ifndef _GCC_WRAP_STDINT_H
#if __STDC_HOSTED__

# if defined __cplusplus && __cplusplus >= 201103L
#  undef __STDC_LIMIT_MACROS
#  define __STDC_LIMIT_MACROS
#  undef __STDC_CONSTANT_MACROS
#  define __STDC_CONSTANT_MACROS
# endif
# include_next <stdint.h>
#else
# include "stdint-gcc.h"
#endif
#define _GCC_WRAP_STDINT_H
#endif

So, when there's a C library, it does a "include_next <stdint.h>" to use the stdint.h from the C library, but otherwise it falls back to stdint-gcc.h, which does provide a type definition for intptr_t.

Since elflink.h itself uses intptr_t, it seems to make sense for it to include <stdint.h>. What exact error are you getting ?

It doesn't really help that this fix is sent standalone, without the rest of the systemd-boot series, as it doesn't allow us to try to reproduce the build issue.

package/gnu-efi/0001-efilink-fix-build-with-gcc-4.8.patch line 3

Quoted 13 lines
 .../0001-efilink-fix-build-with-gcc-4.8.patch      | 35 ++++++++++------------
 1 file changed, 16 insertions(+), 19 deletions(-)
package/gnu-efi/0001-efilink-fix-build-with-gcc-4.8.patch +2 -2
index 57c78c9..7dc8d8d 100644
@@ -1,5 +1,5 @@
-From 6335e5c697c57d8b5854b8202de3733bcb151ca6 Mon Sep 17 00:00:00 2001
-From: Fabrice Fontaine <[email protected]>
+From 92d0653f09aa44b24b9306fa9384f13d2c9f1a24 Mon Sep 17 00:00:00 2001
+From: James Hilliard <[email protected]>
 Date: Fri, 18 Jan 2019 22:05:37 +0100

It's not really nice to "hijack" the authorship of the patch here, even if admittedly it's just a one-liner.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 gnu-efi: fix stdint include location

Quoted 30 lines · Thomas Petazzoni

Hello James,

Quoted 5 lines · On Sat, 26 Jan 2019 08:03:05 +0800 james.hilliard1 at gmail.com wrote:

From: James Hilliard <[email protected]>

Some applications such as systemd-boot include efilink.h without a libc. Move the stdint.h include to lib.h so that efilink.h can be used directly without requiring a libc.

This is a bit weird: gcc does provide <stdint.h>. It contains something like this:

#ifndef _GCC_WRAP_STDINT_H
#if __STDC_HOSTED__

# if defined __cplusplus && __cplusplus >= 201103L
#  undef __STDC_LIMIT_MACROS
#  define __STDC_LIMIT_MACROS
#  undef __STDC_CONSTANT_MACROS
#  define __STDC_CONSTANT_MACROS
# endif
# include_next <stdint.h>
#else
# include "stdint-gcc.h"
#endif
#define _GCC_WRAP_STDINT_H
#endif
Quoted 7 lines

So, when there's a C library, it does a "include_next <stdint.h>" to use the stdint.h from the C library, but otherwise it falls back to stdint-gcc.h, which does provide a type definition for intptr_t.

Since elflink.h itself uses intptr_t, it seems to make sense for it to include <stdint.h>. What exact error are you getting ?

Quoted 1 line
Quoted 1 line

systemd 240 Building

PATH="/home/dragon/atmfirmware/bitaccess/output/host/bin:/home/dragon/atmfirmware/bitaccess/output/host/sbin:/home/dragon/bin:/home/dragon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" LC_ALL=en_US.UTF-8 PYTHONNOUSERSITE=y
/home/dragon/atmfirmware/bitaccess/output/host/bin/ninja -j5 -C
/home/dragon/atmfirmware/bitaccess/output/build/systemd-240//build
ninja: Entering directory
`/home/dragon/atmfirmware/bitaccess/output/build/systemd-240//build'
[519/832] Generating disk.c.o with a custom command.
FAILED: src/boot/efi/disk.c.o
/home/dragon/atmfirmware/bitaccess/output/host/bin/x86_64-buildroot-linux-gnu-gcc
-c ../src/boot/efi/disk.c -o src/boot/efi/disk.c.o -Wall -Wextra
-std=gnu90 -nostdinc -ggdb -O0 -fpic -fshort-wchar -ffreestanding
-fno-strict-aliasing -fno-stack-protector -Wsign-compare
-Wno-missing-field-initializers -isystem
/home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi
-isystem /home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi/x86_64
-include src/boot/efi/efi_config.h -mno-red-zone -mno-sse -mno-mmx
-DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
In file included from
/home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi/efilib.h:25:0,

                 from ../src/boot/efi/disk.c:4:
/home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi/efilink.h:5:10:
fatal error: stdint.h: No such file or directory
 #include <stdint.h>
          ^~~~~~~~~~

compilation terminated.
[521/832] Generating graphics.c.o with a custom command.
FAILED: src/boot/efi/graphics.c.o /home/dragon/atmfirmware/bitaccess/output/host/bin/x86_64-buildroot-linux-gnu-gcc
-c ../src/boot/efi/graphics.c -o src/boot/efi/graphics.c.o -Wall
-Wextra -std=gnu90 -nostdinc -ggdb -O0 -fpic -fshort-wchar
-ffreestanding -fno-strict-aliasing -fno-stack-protector
-Wsign-compare -Wno-missing-field-initializers -isystem /home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi -isystem /home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi/x86_64 -include src/boot/efi/efi_config.h -mno-red-zone -mno-sse -mno-mmx
-DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
In file included from /home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi/efilib.h:25:0,

                 from ../src/boot/efi/graphics.c:8:
/home/dragon/atmfirmware/bitaccess/output/host/x86_64-buildroot-linux-gnu/sysroot/usr/include/efi/efilink.h:5:10:
fatal error: stdint.h: No such file or directory
 #include <stdint.h>
          ^~~~~~~~~~

compilation terminated.

Quoted 4 lines

It doesn't really help that this fix is sent standalone, without the rest of the systemd-boot series, as it doesn't allow us to try to reproduce the build issue.

I'll send v2 with systemd-boot.

Quoted 4 lines
Quoted 4 lines
 .../0001-efilink-fix-build-with-gcc-4.8.patch      | 35 ++++++++++------------
 1 file changed, 16 insertions(+), 19 deletions(-)
Quoted 13 lines

package/gnu-efi/0001-efilink-fix-build-with-gcc-4.8.patch line 3

Quoted 10 lines
package/gnu-efi/0001-efilink-fix-build-with-gcc-4.8.patch +2 -2
index 57c78c9..7dc8d8d 100644
@@ -1,5 +1,5 @@
-From 6335e5c697c57d8b5854b8202de3733bcb151ca6 Mon Sep 17 00:00:00 2001
-From: Fabrice Fontaine <[email protected]>
+From 92d0653f09aa44b24b9306fa9384f13d2c9f1a24 Mon Sep 17 00:00:00 2001
+From: James Hilliard <[email protected]>
 Date: Fri, 18 Jan 2019 22:05:37 +0100

It's not really nice to "hijack" the authorship of the patch here, even if admittedly it's just a one-liner.

Ok, I wasn't sure what best practices there was, will change back in v2.

Quoted 8 lines

Thanks,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com