From 4e5cdba646c574abc0f461669bf87ccf52289f4f Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 3 Feb 2013 12:48:11 +0000 Subject: [PATCH] Lose the 'packed' attribute for types declared in build.h. Most of them are already aligned to their natural boundaries, so lowering the alignment to 1 byte can only worsen things by making the C compiler generate poorer (unaligned access) code for some platforms. The layout of structures is not specified by the C Standard, but is rather given by a particular platform + toolchain's ABI (application binary interface). Most ABIs follow the expected pattern "alignment of scalars is their size, alignment of arrays is that of its element type, alignment of structs is the maximum alignment of its members". A couple of links to particular ABIs are given in build.h. Problems are expected with archs that care about unaligned access when a pointer to a non-packed struct is taken that resides in a packed aggregate, but these uses should be weeded out (I'm not sure if there are any in our codebase). The following types are affected, only hitdata_t changes its size: sectortype, walltype, spritetype, spriteext_t, spritesmooth_t, struct validmode_t, picanm_t, palette_t, vec2_t, vec3_t, hitdata_t. git-svn-id: https://svn.eduke32.com/eduke32@3455 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 17 +++++++++++++++-- polymer/eduke32/source/lunatic/defs_common.lua | 2 -- polymer/eduke32/source/player.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 3a96e3b3b..ae4fe6268 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -211,7 +211,20 @@ static inline void sprite_tracker_hook(uintptr_t address); #endif // __cplusplus -#pragma pack(push,1) +// Links to various ABIs specifying (or documenting non-normatively) the +// alignment requirements of aggregates: +// +// System V AMD64: http://www.x86-64.org/documentation/abi-0.99.pdf +// (x86-64.org down as of 2013-02-02?) +// "An array uses the same alignment as its elements, except that a local or global +// array variable of length at least 16 bytes or a C99 variable-length array variable +// always has alignment of at least 16 bytes." +// (Not reproducible with GCC or LuaJIT on Ubuntu) +// +// Win64: http://msdn.microsoft.com/en-us/library/9dbwhz68.aspx +// +// x86: http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86 + //ceilingstat/floorstat: // bit 0: 1 = parallaxing, 0 = not "P" @@ -319,6 +332,7 @@ typedef struct { uint8_t xpanning, ypanning; uint8_t filler; float alpha; + // NOTE: keep 'tspr' on an 8-byte boundary: spritetype *tspr; #if !defined UINTPTR_MAX # error Need UINTPTR_MAX define to select between 32- and 64-bit structs @@ -702,7 +716,6 @@ typedef struct { int16_t sprite, wall, sect; } hitdata_t; -#pragma pack(pop) int32_t preinitengine(void); // a partial setup of the engine used for launch windows int32_t initengine(void); diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index afdea070b..347c31242 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -101,7 +101,6 @@ end -- TODO: provide getters for unsigned {hi,lo}tag? ffi.cdef([[ -#pragma pack(push,1) typedef $ sectortype; typedef $ walltype; typedef $ spritetype; @@ -131,7 +130,6 @@ typedef struct { vec3_t pos; int16_t sprite, wall, sect; } hitdata_t; -#pragma pack(pop) ]], ffi.typeof(SECTOR_STRUCT), ffi.typeof(WALL_STRUCT), ffi.typeof(SPRITE_STRUCT), ffi.typeof(SPRITE_STRUCT)) diff --git a/polymer/eduke32/source/player.h b/polymer/eduke32/source/player.h index 3b409f0a4..564e195fa 100644 --- a/polymer/eduke32/source/player.h +++ b/polymer/eduke32/source/player.h @@ -220,6 +220,7 @@ typedef struct { uint8_t palette; palette_t pals; + // UNUSED char name[32]; #ifdef LUNATIC