Hi, Alan added code to have GCC align the .toc section in GCC 7, aligning to four bytes for 32-bit mode, and 8 bytes for 64-bit mode. This is normally unnecessary since alignment of the .toc has historically been handled by the standard linker script. However, people using non-standard toolchains can still run into problems, so as a courtesy this is now done by the compiler as well.
We've recently seen this encountered using an out-of-service compiler, and would like to prevent any more occurrences by people finding interesting ways to avoid the standard toolchain. Thus I'd like to backport Alan's patch to GCC 5 and 6. Alan, please review as well to be sure I didn't miss any release-specific differences. Bootstrapped and tested on powerpc64le-linux-gnu with no regressions. Are these backports ok? Thanks, Bill 2017-07-23 Bill Schmidt <wschm...@linux.vnet.ibm.com> Backport from mainline r235874 2016-05-04 Alan Modra <amo...@gmail.com> * config/rs6000/rs6000.c (rs6000_elf_output_toc_section_asm_op): Align .toc. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 250426) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -32699,8 +32699,8 @@ rs6000_elf_output_toc_section_asm_op (const void * { if (!toc_initialized) { - toc_initialized = 1; fprintf (asm_out_file, "%s\n", TOC_SECTION_ASM_OP); + ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2); (*targetm.asm_out.internal_label) (asm_out_file, "LCTOC", 0); fprintf (asm_out_file, "\t.tc "); ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1[TC],"); @@ -32708,8 +32708,10 @@ rs6000_elf_output_toc_section_asm_op (const void * fprintf (asm_out_file, "\n"); fprintf (asm_out_file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); + ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2); ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1"); fprintf (asm_out_file, " = .+32768\n"); + toc_initialized = 1; } else fprintf (asm_out_file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); @@ -32716,12 +32718,20 @@ rs6000_elf_output_toc_section_asm_op (const void * } else if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && !TARGET_RELOCATABLE) - fprintf (asm_out_file, "%s\n", TOC_SECTION_ASM_OP); + { + fprintf (asm_out_file, "%s\n", TOC_SECTION_ASM_OP); + if (!toc_initialized) + { + ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2); + toc_initialized = 1; + } + } else { fprintf (asm_out_file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); if (!toc_initialized) { + ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2); ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1"); fprintf (asm_out_file, " = .+32768\n"); toc_initialized = 1;