[acpica] Fix build on host.
We want to build acpica for host tests, so fix up the build so that we
can run it on host machines.
Bug: 98871
Change-Id: I4df4c7bd596300e9b6ae607af33cc7eeb8769403
diff --git a/BUILD.gn b/BUILD.gn
index 4844635..6530016 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -37,6 +37,13 @@
]
}
+config("avoid_linux_init") {
+ # When building for Linux hosts, we use the aclinux.h header in ACPICA.
+ # This has the fun side effect of defining __init, which is used in the C++ standard
+ # library headers. To avoid the ACPICA definition, we define __init to __init here.
+ defines = [ "__init=__init" ]
+}
+
static_library("acpica") {
public_deps = [ ":headers" ]
@@ -54,6 +61,9 @@
"//build/config:Wno-conversion",
]
+ # This is a public config, since it impacts our header files.
+ public_configs = [ ":avoid_linux_init" ]
+
# We need to specify -fno-strict-aliasing, since ACPICA has a habit of
# violating strict aliasing rules in some of its macros. Rewriting this
# code would increase the maintenance cost of bringing in the latest
@@ -236,9 +246,7 @@
"source/components/utilities/utxfinit.c",
"source/components/utilities/utxfmutex.c",
]
- deps = [
- "//zircon/system/ulib/acpica:acpica-fuchsia",
- ]
+ deps = [ "//zircon/system/ulib/acpica:acpica-fuchsia" ]
defines = [ "_ALL_SOURCE" ]
if (acpica_debug_output) {
defines += [ "ACPI_DEBUG_OUTPUT" ]
diff --git a/source/components/hardware/hwsleep.c b/source/components/hardware/hwsleep.c
index f6fd05a..e6dcc83 100644
--- a/source/components/hardware/hwsleep.c
+++ b/source/components/hardware/hwsleep.c
@@ -41,7 +41,9 @@
#include "acpi.h"
#include "accommon.h"
+#ifdef __Fuchsia__
#include <zircon/syscalls/system.h>
+#endif
#define _COMPONENT ACPI_HARDWARE
ACPI_MODULE_NAME ("hwsleep")
diff --git a/source/include/acpi.h b/source/include/acpi.h
index dc025b8..2b86d91 100644
--- a/source/include/acpi.h
+++ b/source/include/acpi.h
@@ -50,7 +50,10 @@
* Note: The order of these include files is important.
*/
#include "platform/acenv.h" /* Environment-specific items */
-__BEGIN_CDECLS
+
+#ifdef __cplusplus
+extern "C" {
+#endif
#include "actypes.h" /* ACPICA data types and structures */
#include "platform/acenvex.h" /* Extra environment-specific items */
@@ -61,6 +64,9 @@
#include "acrestyp.h" /* Resource Descriptor structs */
#include "acpiosxf.h" /* OSL interfaces (ACPICA-to-OS) */
#include "acpixf.h" /* ACPI core subsystem external interfaces */
-__END_CDECLS
+
+#ifdef __cplusplus
+}
+#endif
#endif /* __ACPI_H__ */
diff --git a/source/include/actypes.h b/source/include/actypes.h
index a8f5c6b..11b361e 100644
--- a/source/include/actypes.h
+++ b/source/include/actypes.h
@@ -547,9 +547,13 @@
#define ACPI_TO_POINTER(i) ACPI_CAST_PTR (void, (ACPI_SIZE) (i))
#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0)
+#ifdef __Fuchsia__
// Use offsetof() to avoid taking the offset of a nullptr, which is undefined
// behavior.
#define ACPI_OFFSET(d, f) offsetof(d, f)
+#else
+#define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
+#endif
#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i)
#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)