u-boot/include/asm-generic
Rasmus Villemoes ee3a46a437 global-data.h: add build-time sanity check of sizeof(struct global_data)
The layout and contents of struct global_data depends on a lot of
CONFIG_* preprocessor macros, not all of which are entirely converted
to Kconfig - not to mention weird games played here and there. This
can result in one translation unit using one definition of struct
global_data while the actual layout is another.

That can be very hard to debug. But we already have a mechanism that
can help catch such bugs at build time, namely the asm-offsets
machinery which is necessary anyway to provide assembly code with the
necessary constants. So make sure that every C translation unit that
include global_data.h actually sees the same size of struct
global_data as that which was seen by the asm-offsets.c TU.

It is likely that this patch will break the build of some boards. For
example, without the patch from Matt Merhar
(https://lists.denx.de/pipermail/u-boot/2021-May/450135.html) or some
other fix, this breaks P2041RDB_defconfig:

  CC      arch/powerpc/lib/traps.o
  AS      arch/powerpc/cpu/mpc85xx/start.o
In file included from include/asm-generic/global_data.h:26,
                 from ./arch/powerpc/include/asm/global_data.h:109,
                 from include/init.h:21,
                 from arch/powerpc/lib/traps.c:7:
include/linux/build_bug.h:99:41: error: static assertion failed: "sizeof(struct global_data) == GD_SIZE"
   99 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
      |                                         ^~~~~~~~~~~~~~
include/linux/build_bug.h:98:34: note: in expansion of macro ‘__static_assert’
   98 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
      |                                  ^~~~~~~~~~~~~~~
include/asm-generic/global_data.h:470:1: note: in expansion of macro ‘static_assert’
  470 | static_assert(sizeof(struct global_data) == GD_SIZE);
      | ^~~~~~~~~~~~~
make[1]: *** [scripts/Makefile.build:266: arch/powerpc/lib/traps.o] Error 1
make: *** [Makefile:1753: arch/powerpc/lib] Error 2
make: *** Waiting for unfinished jobs....

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>
2021-07-01 16:34:32 -04:00
..
bitops include: Add generic bitops headers 2015-11-05 10:51:57 -05:00
atomic-long.h atomic-long: Fix warnings on arm64 2018-01-28 09:39:05 -05:00
atomic.h Add include/asm-generic/atomic.h 2018-09-25 21:49:18 -04:00
bitsperlong.h linux/bitops.h: GENMASK copy from linux 2015-10-21 09:14:07 -04:00
global_data.h global-data.h: add build-time sanity check of sizeof(struct global_data) 2021-07-01 16:34:32 -04:00
gpio.h gpio: Drop dm_gpio_set_dir() 2021-04-12 17:45:40 -04:00
int-ll64.h arch: types.h: factor out fixed width typedefs to int-ll64.h 2018-09-10 20:48:16 -04:00
io.h SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
ioctl.h x86: Fix support for booting bzImage 2010-05-06 00:17:01 +02:00
pe.h efi_loader: add Linux magic to aarch64 crt0 2021-01-29 20:22:40 +01:00
sections.h dm: core: Allow storing priv/plat data separately 2021-03-26 17:03:09 +13:00
signal.h asm-generic/signal.h: import from linux 2010-01-17 20:36:05 -05:00
types.h arch: types.h: factor out fixed width typedefs to int-ll64.h 2018-09-10 20:48:16 -04:00
u-boot.h asm-generic/u-boot.h: Remove bi_memstart & bi_memsize from bd_info 2020-08-26 09:20:05 +02:00
unaligned.h efi_loader: allow unaligned memory access 2018-06-03 15:27:21 +02:00