From: Jérémie Galarneau Date: Tue, 21 Mar 2023 15:15:19 +0000 (-0400) Subject: Build fix: POD static_assert check fails on lttng_event_exclusions X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=40ebe2193c00a3b67294ad38b47537cdd68b0e82;p=lttng-tools.git Build fix: POD static_assert check fails on lttng_event_exclusions 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::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 Signed-off-by: Michael Jeanson --- diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 39c531cba..6aad72cf4 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 index 000000000..bb080ad50 --- /dev/null +++ b/src/common/compiler.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2023 Jérémie Galarneau + * + * 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 */ diff --git a/src/common/filter/filter-parser.ypp b/src/common/filter/filter-parser.ypp index fedf0e830..e3fae6394 100644 --- a/src/common/filter/filter-parser.ypp +++ b/src/common/filter/filter-parser.ypp @@ -22,6 +22,7 @@ #include "memstream.hpp" #include +#include #include #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 diff --git a/src/common/lttng-kernel.hpp b/src/common/lttng-kernel.hpp index 1363ba584..2de7ef810 100644 --- a/src/common/lttng-kernel.hpp +++ b/src/common/lttng-kernel.hpp @@ -10,6 +10,7 @@ #define _LTTNG_KERNEL_H #include +#include #include #include #include @@ -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; /* diff --git a/src/common/sessiond-comm/agent.hpp b/src/common/sessiond-comm/agent.hpp index 9fcb1f349..65d379ec0 100644 --- a/src/common/sessiond-comm/agent.hpp +++ b/src/common/sessiond-comm/agent.hpp @@ -11,6 +11,7 @@ #include +#include #include #include @@ -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 */ diff --git a/src/common/sessiond-comm/relayd.hpp b/src/common/sessiond-comm/relayd.hpp index 0f5adaa94..0865254fa 100644 --- a/src/common/sessiond-comm/relayd.hpp +++ b/src/common/sessiond-comm/relayd.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -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 */ diff --git a/src/common/sessiond-comm/sessiond-comm.hpp b/src/common/sessiond-comm/sessiond-comm.hpp index 3d4eb6b8a..e9cb85a05 100644 --- a/src/common/sessiond-comm/sessiond-comm.hpp +++ b/src/common/sessiond-comm/sessiond-comm.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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) \ diff --git a/src/lib/lttng-ctl/lttng-ctl-health.cpp b/src/lib/lttng-ctl/lttng-ctl-health.cpp index fd6279ade..8ec359074 100644 --- a/src/lib/lttng-ctl/lttng-ctl-health.cpp +++ b/src/lib/lttng-ctl/lttng-ctl-health.cpp @@ -13,6 +13,7 @@ #define _LGPL_SOURCE #include "lttng-ctl-helper.hpp" +#include #include #include #include @@ -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)