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.
This commit is contained in:
Campbell Barton
2022-02-04 19:45:02 +11:00
parent e9fc25835f
commit 2d429bfdf8

View File

@@ -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);