Build fix: POD static_assert check fails on lttng_event_exclusions
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 Mar 2023 15:15:19 +0000 (11:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 Mar 2023 21:50:22 +0000 (17:50 -0400)
A build error occurs when building using g++ 6.4.0 on PPC32:

  In file included from ../../src/common/buffer-view.hpp:11:0,
                   from event.cpp:9:
  ../../src/common/macros.hpp: In instantiation of 'AllocatedType* zmalloc(size_t) [with AllocatedType = lttng_event_exclusion; size_t = unsigned int]':
  event.cpp:270:77:   required from here
  ../../src/common/macros.hpp:102:2: error: static assertion failed: type can be malloc'ed
    static_assert(can_malloc<AllocatedType>::value, "type can be malloc'ed");
    ^~~~~~~~~~~~~

A bug affecting gcc [6.1, 7.4] causes flexible array members to generate
a destructor for compound types. In turn, this makes any type that
contains a flexible array a non-POD object which is a problem under some
use-case (e.g., being allocated using C-style memory management
facilities).

Explicitly specifying a length of zero works around this bug, see:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70932
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71147

The same bug affects re2 and they have fixed it in a similar way:
https://github.com/google/re2/blob/9049cd28d7496e05e7b7beaec89291d8bc6a31ee/re2/dfa.cc#L123

Change-Id: I730cdeb86bb39cdbfdc5165f854ab5906aeb2192
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
src/common/Makefile.am
src/common/compiler.hpp [new file with mode: 0644]
src/common/filter/filter-parser.ypp
src/common/lttng-kernel.hpp
src/common/sessiond-comm/agent.hpp
src/common/sessiond-comm/relayd.hpp
src/common/sessiond-comm/sessiond-comm.hpp
src/lib/lttng-ctl/lttng-ctl-health.cpp

index 39c531cbafd0ef4a83e270794e506b542a7f04fe..6aad72cf4dd65291398ea22932973c46e968eece 100644 (file)
@@ -57,6 +57,7 @@ libcommon_lgpl_la_SOURCES = \
        actions/rate-policy.cpp \
        buffer-view.hpp buffer-view.cpp \
        channel.cpp \
+       compiler.hpp \
        conditions/buffer-usage.cpp \
        conditions/condition.cpp \
        conditions/event-rule-matches.cpp \
diff --git a/src/common/compiler.hpp b/src/common/compiler.hpp
new file mode 100644 (file)
index 0000000..bb080ad
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2023 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_COMPILER_HPP
+#define LTTNG_COMPILER_HPP
+
+/*
+ * A bug in gcc [6.1, 7.4] causes flexible array members to generate a destructor
+ * for compound types. In turn, this makes any type that contains a flexible array
+ * a non-POD object which is a problem under some use-case (e.g., being allocated
+ * using C-style memory management facilities).
+ *
+ * Explicitly specifying a length of zero works around this bug, see:
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70932
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71147
+ */
+#if !defined(__clang__) && defined(__GNUC__) && \
+       ((__GNUC__ == 6 && __GNUC_MINOR__ >= 1) || ((__GNUC__ == 7 && __GNUC_MINOR__ <= 4)))
+#define LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH 0
+#else
+#define LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH
+#endif /* gcc version [6.1, 7.4]. */
+
+#endif /* LTTNG_COMPILER_HPP */
index fedf0e830b433685830acbe6ea1694432874c71d..e3fae6394fcaa0cb6a76eaec0191829714d14045 100644 (file)
@@ -22,6 +22,7 @@
 #include "memstream.hpp"
 
 #include <common/compat/errno.hpp>
+#include <common/compiler.hpp>
 #include <common/macros.hpp>
 
 #define WIDTH_u64_SCANF_IS_A_BROKEN_API        "20"
@@ -62,7 +63,7 @@ void yyrestart(FILE * in_str, yyscan_t parser_ctx);
 struct gc_string {
        struct cds_list_head gc;
        size_t alloclen;
-       char s[];
+       char s[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 };
 
 static
index 1363ba584c21049bf4a95c205426c18fc84554a4..2de7ef81067cdbbb3a3e61820a815b56ed1cf15f 100644 (file)
@@ -10,6 +10,7 @@
 #define _LTTNG_KERNEL_H
 
 #include <stdint.h>
+#include <common/compiler.hpp>
 #include <common/macros.hpp>
 #include <lttng/constant.h>
 #include <lttng/event.h>
@@ -275,7 +276,7 @@ struct lttng_kernel_abi_tracer_abi_version {
 
 struct lttng_kernel_abi_syscall_mask {
        uint32_t len;   /* in bits */
-       char mask[];
+       char mask[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 /*
index 9fcb1f34956be67f4a5329e4a8c5cd9d2158a10f..65d379ec06cde75c6d39545e743572c0a7a0c375 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <stdint.h>
 
+#include <common/compiler.hpp>
 #include <common/macros.hpp>
 #include <lttng/lttng.h>
 
@@ -87,7 +88,7 @@ struct lttcomm_agent_list_reply_hdr {
 struct lttcomm_agent_list_reply {
        uint32_t nb_event;
        /* List of event name each of them ending by a NULL byte. */
-       char payload[];
+       char payload[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 #endif /* AGENT_COMM */
index 0f5adaa94bba32443286bcefe1d99c9f445e96a8..0865254fa7dd14cd190499cabd7d4e26fc8eb619 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdint.h>
 
 #include <lttng/lttng.h>
+#include <common/compiler.hpp>
 #include <common/defaults.hpp>
 #include <common/index/ctf-index.hpp>
 #include <common/macros.hpp>
@@ -83,7 +84,7 @@ struct lttcomm_relayd_add_stream_2_11 {
        uint64_t tracefile_size;
        uint64_t tracefile_count;
        uint64_t trace_chunk_id;
-       char names[];
+       char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 /*
@@ -209,14 +210,14 @@ struct lttcomm_relayd_create_session_2_11 {
        uint64_t creation_time;
        LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED current_chunk_id;
        /* Contains the session_name, hostname, base_path. */
-       char names[];
+       char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 struct lttcomm_relayd_create_session_reply_2_11 {
        struct lttcomm_relayd_status_session generic;
        /* Includes the '\0' terminator. */
        uint32_t output_path_length;
-       char output_path[];
+       char output_path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 /*
@@ -309,7 +310,7 @@ struct lttcomm_relayd_create_trace_chunk {
        uint64_t creation_timestamp;
        /* Includes trailing NULL. */
        uint32_t override_name_length;
-       char override_name[];
+       char override_name[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 struct lttcomm_relayd_close_trace_chunk {
@@ -324,7 +325,7 @@ struct lttcomm_relayd_close_trace_chunk_reply {
        struct lttcomm_relayd_generic_reply generic;
        /* Includes trailing NULL. */
        uint32_t path_length;
-       char path[];
+       char path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 struct lttcomm_relayd_trace_chunk_exists {
@@ -354,7 +355,7 @@ struct lttcomm_relayd_get_configuration_reply {
        /* Set of lttcomm_relayd_configuration_flag. */
        uint64_t relayd_configuration_flags;
        /* Optional variable-length payload. */
-       char payload[];
+       char payload[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 } LTTNG_PACKED;
 
 #endif /* _RELAYD_COMM */
index 3d4eb6b8a070a324f213003be96f36a31209d2df..e9cb85a05f6a30715b9928daee2aec537069bea4 100644 (file)
@@ -22,6 +22,7 @@
 #include <lttng/trigger/trigger-internal.hpp>
 #include <lttng/rotate-internal.hpp>
 #include <common/compat/socket.hpp>
+#include <common/compiler.hpp>
 #include <common/uri.hpp>
 #include <common/defaults.hpp>
 #include <common/uuid.hpp>
@@ -563,7 +564,7 @@ struct lttng_bytecode {
 struct lttng_event_exclusion {
        uint32_t count;
        char padding[LTTNG_EVENT_EXCLUSION_PADDING];
-       char names[][LTTNG_SYMBOL_NAME_LEN];
+       char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH][LTTNG_SYMBOL_NAME_LEN];
 } LTTNG_PACKED;
 
 #define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) \
index fd6279ade1aaa49110924a7818987305e75e793b..8ec35907459eb7bad89ae27c413e1f9165049016 100644 (file)
@@ -13,6 +13,7 @@
 #define _LGPL_SOURCE
 #include "lttng-ctl-helper.hpp"
 
+#include <common/compiler.hpp>
 #include <common/compat/errno.hpp>
 #include <common/defaults.hpp>
 #include <common/utils.hpp>
@@ -48,7 +49,7 @@ struct lttng_health {
        char health_sock_path[PATH_MAX];
        /* For consumer health only */
        enum lttng_health_consumerd consumerd_type;
-       struct lttng_health_thread thread[];
+       struct lttng_health_thread thread[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
 };
 
 static const char *get_sessiond_thread_name(health_type_sessiond type)
This page took 0.03232 seconds and 4 git commands to generate.