Hi. The patch fixes wrong assignment from a char * to lto_section_header that is seen on strict alignment targets.
I verified it fixes the problem with -fsanitize=undefined: gcc main.o -flto ../../gcc/lto/lto-common.c:2202:36: runtime error: reference binding to misaligned address 0x7f64dac090a7 for type 'const struct lto_section', which requires 4 byte alignment 0x7f64dac090a7: note: pointer points here 00 1b c0 02 09 00 00 00 03 00 00 00 28 b5 2f fd 60 77 00 d5 08 00 e6 d1 3d 37 20 01 09 00 bf 53 ^ ../../gcc/lto/lto-common.c:2202:33: runtime error: load of misaligned address 0x7f64dac090a7 for type 'const struct lto_section', which requires 4 byte alignment 0x7f64dac090a7: note: pointer points here 00 1b c0 02 09 00 00 00 03 00 00 00 28 b5 2f fd 60 77 00 d5 08 00 e6 d1 3d 37 20 01 09 00 bf 53 ^ Ready for trunk? Thanks, Martin gcc/lto/ChangeLog: 2019-07-04 Martin Liska <mli...@suse.cz> PR lto/91078 * lto-common.c (lto_file_finalize): Use memcpy to set file_data->lto_section_header. --- gcc/lto/lto-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c index bc8c2b40387..3c6d7b25ddb 100644 --- a/gcc/lto/lto-common.c +++ b/gcc/lto/lto-common.c @@ -2199,7 +2199,7 @@ lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file) return; } - file_data->lto_section_header = *(const lto_section *)data; + memcpy (&file_data->lto_section_header, data, sizeof (lto_section)); lto_check_version (file_data->lto_section_header.major_version, file_data->lto_section_header.minor_version, file_data->file_name);