summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKees Cook <kees@outflux.net>2022-11-18 09:48:08 -0800
committerKees Cook <kees@outflux.net>2023-03-02 11:03:42 -0800
commite73b227e8e475c20cc394f237ea35d592fdf9ec3 (patch)
tree45e6b185f108bf0fe982df5ca45f49fb6a5dd3cb
parente66decc6fca36b59194b0947d87d6a9bec078bc3 (diff)
downloadacpica-e73b227e8e475c20cc394f237ea35d592fdf9ec3.tar.gz
Introduce ACPI_FLEX_ARRAY
In order to enable using -fstrict-flex-arrays with GCC and Clang in the Linux kernel, each trailing dynamically sized array must be defined as proper C99 "flexible array members" (FAM). Unfortunately, ACPICA has a bunch of technical debt, dating back to before even the GNU extension of 0-length arrays, meaning the code base has many 1-element and 0-length arrays defined at the end of structures that should actually be FAMs. One limitation of the C99 FAM specification is the accidental requirement that they cannot be in unions or alone in structs. There is no real-world reason for this, though, and, actually, the existing GNU extension permits this for 0-length arrays (which get treated as FAMs). Add the ACPI_FLEX_ARRAY() helper macro to work around this requirement so that FAMs can be defined in unions or alone in structs. Since this behavior still depends on GNU extensions, keep the macro specific to GCC (and Clang) builds. In this way, MSVC will continue to use 0-length arrays (since it does not support the union work-around). When MSVC grows support for this in the future, the macro can be updated.
-rw-r--r--source/include/actypes.h4
-rw-r--r--source/include/platform/acgcc.h11
2 files changed, 15 insertions, 0 deletions
diff --git a/source/include/actypes.h b/source/include/actypes.h
index 52d2d6dcf..c0f0a87f4 100644
--- a/source/include/actypes.h
+++ b/source/include/actypes.h
@@ -1574,4 +1574,8 @@ typedef enum
#define ACPI_FALLTHROUGH do {} while(0)
#endif
+#ifndef ACPI_FLEX_ARRAY
+#define ACPI_FLEX_ARRAY(TYPE, NAME) TYPE NAME[0]
+#endif
+
#endif /* __ACTYPES_H__ */
diff --git a/source/include/platform/acgcc.h b/source/include/platform/acgcc.h
index 81e29f90d..55a66c6da 100644
--- a/source/include/platform/acgcc.h
+++ b/source/include/platform/acgcc.h
@@ -211,4 +211,15 @@ typedef __builtin_va_list va_list;
#define ACPI_FALLTHROUGH __attribute__((__fallthrough__))
#endif
+/*
+ * Flexible array members are not allowed to be part of a union under
+ * C99, but this is not for any technical reason. Work around the
+ * limitation.
+ */
+#define ACPI_FLEX_ARRAY(TYPE, NAME) \
+ struct { \
+ struct { } __Empty_ ## NAME; \
+ TYPE NAME[]; \
+ }
+
#endif /* __ACGCC_H__ */