From 5be87c8fa74c9ae6684bea571b4157ad1966d008 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 13 Nov 2017 12:26:12 +0100 Subject: PE: don't corrupt section flags when linking from ELF objects Linking EFI executables from ELF object files can result in corrupted COFF section flags if the section's alignment is too high. Issue a diagnostic in that case, erroring out if this is not a final link, and make sure only in-range values get written to the output image. While doing this also make tic80 use the generic alignment macros instead of custom #ifdef-ary. No testsuite regressions for the range of COFF/PE targets that actually cross-build in the first place on x86-64-linux. --- bfd/coffcode.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'bfd/coffcode.h') diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 6da0afa..604ba6d 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -1855,10 +1855,6 @@ coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED, if ((1 << i) >= hdr->s_align) break; #endif -#ifdef TIC80COFF - /* TI tools puts the alignment power in bits 8-11. */ - i = (hdr->s_flags >> 8) & 0xF ; -#endif #ifdef COFF_DECODE_ALIGNMENT i = COFF_DECODE_ALIGNMENT(hdr->s_flags); #endif @@ -3865,12 +3861,25 @@ coff_write_object_contents (bfd * abfd) ? 1 << current->alignment_power : 0); #endif -#ifdef TIC80COFF - /* TI COFF puts the alignment power in bits 8-11 of the flags. */ - section.s_flags |= (current->alignment_power & 0xF) << 8; -#endif #ifdef COFF_ENCODE_ALIGNMENT COFF_ENCODE_ALIGNMENT(section, current->alignment_power); + if ((unsigned int)COFF_DECODE_ALIGNMENT(section.s_flags) + != current->alignment_power) + { + bfd_boolean warn = coff_data (abfd)->link_info + && !bfd_link_relocatable (coff_data (abfd)->link_info); + + _bfd_error_handler + /* xgettext:c-format */ + (_("%B:%s section %s: alignment 2**%u not representable"), + abfd, warn ? " warning:" : "", current->name, + current->alignment_power); + if (!warn) + { + bfd_set_error (bfd_error_nonrepresentable_section); + return FALSE; + } + } #endif #ifdef COFF_IMAGE_WITH_PE -- cgit v1.1