From 6f8f6017a0c4e22c6417c597c31b0a937d148a39 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 16 Apr 2021 22:29:05 +0930 Subject: PR27567, Linking PE files adds alignment section flags to executables So don't set those flags for an executable. In the patch I also test DYNAMIC even though the PE bfd code doesn't appear to set it for dlls. I figure it doesn't hurt to include that flag too. PR 27567 bfd/ * coffcode.h (styp_to_sec_flags): Use an unsigned long styp_flags. (coff_write_object_contents): Pass bfd to COFF_ENCODE_ALIGNMENT, ignore alignment checks when return is false. Formatting. include/ * coff/internal.h (struct internal_scnhdr): Make s_flags unsigned long. * coff/pe.h (COFF_ENCODE_ALIGNMENT): Don't set align flags for an executable and return false. Do so for a relocatable object and evaluate to true. * coff/ti.h (COFF_ENCODE_ALIGNMENT): Add bfd arg and evaluate to true. (COFF_DECODE_ALIGNMENT): Formatting. * coff/z80.h (COFF_ENCODE_ALIGNMENT): Similarly. (COFF_DECODE_ALIGNMENT): Similarly. --- bfd/ChangeLog | 7 +++++++ bfd/coffcode.h | 16 ++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 702d402..513d6e9 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2021-04-16 Alan Modra + + PR 27567 + * coffcode.h (styp_to_sec_flags): Use an unsigned long styp_flags. + (coff_write_object_contents): Pass bfd to COFF_ENCODE_ALIGNMENT, + ignore alignment checks when return is false. Formatting. + 2021-04-15 Nelson Chu PR27584 diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 8006baa..f65f335 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -737,7 +737,7 @@ styp_to_sec_flags (bfd *abfd, flagword *flags_ptr) { struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr; - long styp_flags = internal_s->s_flags; + unsigned long styp_flags = internal_s->s_flags; flagword sec_flags = 0; #ifdef STYP_BLOCK @@ -3643,18 +3643,18 @@ coff_write_object_contents (bfd * abfd) #ifdef COFF_ENCODE_ALIGNMENT - COFF_ENCODE_ALIGNMENT(section, current->alignment_power); - if ((unsigned int)COFF_DECODE_ALIGNMENT(section.s_flags) - != current->alignment_power) + if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power) + && (COFF_DECODE_ALIGNMENT (section.s_flags) + != current->alignment_power)) { - bool warn = coff_data (abfd)->link_info - && !bfd_link_relocatable (coff_data (abfd)->link_info); + bool warn = (coff_data (abfd)->link_info + && !bfd_link_relocatable (coff_data (abfd)->link_info)); _bfd_error_handler /* xgettext:c-format */ (_("%pB:%s section %s: alignment 2**%u not representable"), - abfd, warn ? " warning:" : "", current->name, - current->alignment_power); + abfd, warn ? " warning:" : "", current->name, + current->alignment_power); if (!warn) { bfd_set_error (bfd_error_nonrepresentable_section); -- cgit v1.1