From 2d429bfdf8a4fd25891ba682618d6ba25435410b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 4 Feb 2022 19:45:02 +1100 Subject: Fix T93425: makesdna crashes during build with LTO on s390x Linux DNAstr was assumed to be 4-byte aligned which is not necessarily the case for byte-arrays. Use a compiler attribute to ensure this is the case. Thanks to @mtasaka for investigating and providing a patch. --- source/blender/makesdna/intern/makesdna.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source/blender/makesdna/intern/makesdna.c') diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index 114c0b40407..d94b95fc6f4 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -1555,8 +1555,18 @@ int main(int argc, char **argv) base_directory = BASE_HEADER; } + /* NOTE: #init_structDNA() in dna_genfile.c expects `sdna->data` is 4-bytes aligned. + * `DNAstr[]` buffer written by `makesdna` is used for this data, so make `DNAstr` forcefully + * 4-bytes aligned. */ +#ifdef __GNUC__ +# define FORCE_ALIGN_4 " __attribute__((aligned(4))) " +#else +# define FORCE_ALIGN_4 " " +#endif fprintf(file_dna, "extern const unsigned char DNAstr[];\n"); - fprintf(file_dna, "const unsigned char DNAstr[] = {\n"); + fprintf(file_dna, "const unsigned char" FORCE_ALIGN_4 "DNAstr[] = {\n"); +#undef FORCE_ALIGN_4 + if (make_structDNA(base_directory, file_dna, file_dna_offsets, file_dna_verify)) { /* error */ fclose(file_dna); -- cgit v1.2.3