From bdff256c6ce6d8ccb873050b51480f9abf1435cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 31 Oct 2018 00:19:14 +0100 Subject: [PATCH] Fix: invalid alignment of enumeration fields MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issue --- According to the CTF specification, the alignment of an enumeration is that of its container integer field type. However, ctf-ir does not forward the alignment of an enumeration field type's alignment in bt_field_type_get_alignment(). This causes babeltrace to fail to read traces produced by lttng-ust following a fix that causes it to generate extended event headers. The problem is observed on ARM platforms since lttng-ust will produce a layout that does not result in unaligned memory accesses. Solution --- The alignment of the enumeration field type's container is sampled when the enumeration field type is frozen. Signed-off-by: Jérémie Galarneau --- lib/ctf-ir/field-types.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index c2a5383c..be3e2d0f 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -2997,6 +2997,15 @@ int bt_field_type_get_alignment(struct bt_field_type *type) ret = (int) type->alignment; break; } + case BT_FIELD_TYPE_ID_ENUM: + { + struct bt_field_type *container = + bt_field_type_enumeration_get_container_type(type); + + ret = bt_field_type_get_alignment(container); + bt_put(container); + break; + } case BT_FIELD_TYPE_ID_UNKNOWN: BT_LOGW("Invalid parameter: unknown field type ID: " "addr=%p, ft-id=%d", type, type_id); @@ -3725,6 +3734,7 @@ void bt_field_type_enumeration_freeze(struct bt_field_type *type) type, struct bt_field_type_enumeration, parent); BT_LOGD("Freezing enumeration field type object: addr=%p", type); + type->alignment = bt_field_type_get_alignment(type); set_enumeration_range_overlap(type); generic_field_type_freeze(type); BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p", -- 2.34.1