diff options
author | Jan Beulich <jbeulich@novell.com> | 2017-11-13 12:26:12 +0100 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2017-11-13 12:26:12 +0100 |
commit | 5be87c8fa74c9ae6684bea571b4157ad1966d008 (patch) | |
tree | 03ab623efa8dc04c95e82d4c6b05b9eb3ab346c4 /bfd/coffcode.h | |
parent | b76bc5d54e36f15efd954898d9aa075c2bea02dd (diff) | |
download | gdb-5be87c8fa74c9ae6684bea571b4157ad1966d008.zip gdb-5be87c8fa74c9ae6684bea571b4157ad1966d008.tar.gz gdb-5be87c8fa74c9ae6684bea571b4157ad1966d008.tar.bz2 |
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.
Diffstat (limited to 'bfd/coffcode.h')
-rw-r--r-- | bfd/coffcode.h | 25 |
1 files changed, 17 insertions, 8 deletions
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 |