From: Jérémie Galarneau Date: Wed, 2 Oct 2019 22:04:43 +0000 (-0400) Subject: Fix: liblttng-ctl: ABI-breaking size change of lttng_session struct X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=e9af56b3027eebc314384a797c01e6a7e35c8fd2 Fix: liblttng-ctl: ABI-breaking size change of lttng_session struct abidiff reports that the size of struct lttng_session has changed since 2.10: [C]'function int lttng_list_sessions(lttng_session**)' at lttng-ctl.c:2065:1 has some indirect sub-type changes: parameter 1 of type 'lttng_session**' has sub-type changes: in pointed to type 'lttng_session*': in pointed to type 'struct lttng_session' at session.h:38:1: type size changed from 35008 to 35072 (in bits) 1 data member deletion: 'char lttng_session::padding[12]', at offset 34912 (in bits) at session.h:50:1 1 data member insertion: 'union {char padding[12]; void* ptr;} lttng_session::extended', at offset 34944 (in bits) at session.h:57:1 The offset after the 'live_timer_interval' field is aligned on 4 bytes, but not on 8 bytes. This causes some compilers (such as gcc and clang) to align the following 'extended' union on 8 bytes, making the overall structure larger. To preserve the size of 'struct lttng_session', four bytes of padding are added after 'live_timer_interval', resulting in an aligned offset for both bitnesses. The 'extended' union's padding is reduced from 12 to 8 bytes, essentially ensuring that 'ptr' always occupies 8 bytes, even on 32-bit builds. Tested on clang and gcc for x64, x86, PPC32, PPC64, ARM, ARM64, AVR, MIPS, MIPS64, and MSVC (32-bit and 64-bit). Reviewed-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/session.h b/include/lttng/session.h index 395df3245..7e328b625 100644 --- a/include/lttng/session.h +++ b/include/lttng/session.h @@ -34,7 +34,7 @@ struct lttng_destruction_handle; * * The structures should be initialized to zero before use. */ -#define LTTNG_SESSION_PADDING1 12 +#define LTTNG_SESSION_PADDING1 8 struct lttng_session { char name[LTTNG_NAME_MAX]; /* @@ -51,7 +51,29 @@ struct lttng_session { uint32_t snapshot_mode; unsigned int live_timer_interval; /* usec */ + /* + * End of public attributes. + * The remaining fields are used to deal with ABI management concerns. + */ + + /* + * 32-bit architectures are already naturally aligned on 4 bytes after + * 'live_timer_interval'. However, the offset does not result in a + * natural alignment on 64-bit architectures. Adding 4 bytes of + * padding here results in an aligned offset after 'alignement_padding' + * for both bitnesses. + * + * This was added since not all compilers appear to align unions in the + * same way. Some (e.g. MSVC) do not seem to impose an alignement + * constraint while others (e.g. gcc, clang, icc) seem to align it to + * ensure 'ptr' is naturally aligned. + */ + char alignment_padding[4]; union { + /* + * Ensure the 'extended' union has the same size for both + * 32-bit and 64-bit builds. + */ char padding[LTTNG_SESSION_PADDING1]; void *ptr; } extended;