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>
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 \
--- /dev/null
+/*
+ * 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 */
#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"
struct gc_string {
struct cds_list_head gc;
size_t alloclen;
- char s[];
+ char s[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
};
static
#define _LTTNG_KERNEL_H
#include <stdint.h>
+#include <common/compiler.hpp>
#include <common/macros.hpp>
#include <lttng/constant.h>
#include <lttng/event.h>
struct lttng_kernel_abi_syscall_mask {
uint32_t len; /* in bits */
- char mask[];
+ char mask[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
} LTTNG_PACKED;
/*
#include <stdint.h>
+#include <common/compiler.hpp>
#include <common/macros.hpp>
#include <lttng/lttng.h>
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 */
#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>
uint64_t tracefile_size;
uint64_t tracefile_count;
uint64_t trace_chunk_id;
- char names[];
+ char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
} LTTNG_PACKED;
/*
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;
/*
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 {
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 {
/* 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 */
#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>
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) \
#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>
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)