diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index c09779a..a51b384 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -4097,6 +4097,8 @@ rsrc_process_section (bfd * abfd, unsigned int num_input_rsrc = 0; unsigned int max_num_input_rsrc = 4; ptrdiff_t * rsrc_sizes = NULL; + unsigned long page_size; + new_table.names.num_entries = 0; new_table.ids.num_entries = 0; @@ -4139,7 +4141,8 @@ rsrc_process_section (bfd * abfd, { asection * rsrc_sec = bfd_get_section_by_name (input, ".rsrc"); - if (rsrc_sec != NULL) + /* PR 18372 - skip discarded .rsrc sections. */ + if (rsrc_sec != NULL && !discarded_section (rsrc_sec)) { if (num_input_rsrc == max_num_input_rsrc) { @@ -4274,22 +4277,25 @@ rsrc_process_section (bfd * abfd, We recompute the size as we may have lost entries due to mergeing. */ size = ((write_data.next_data - new_data) + 3) & ~ 3; - { - int page_size; - - if (coff_data (abfd)->link_info) - { - page_size = pe_data (abfd)->pe_opthdr.FileAlignment; + if (coff_data (abfd)->link_info) + { + page_size = pe_data (abfd)->pe_opthdr.FileAlignment; - /* If no file alignment has been set, default to one. - This repairs 'ld -r' for arm-wince-pe target. */ - if (page_size == 0) - page_size = 1; - } - else - page_size = PE_DEF_FILE_ALIGNMENT; - size = (size + page_size - 1) & - page_size; - } + /* If no file alignment has been set, default to one. + This repairs 'ld -r' for arm-wince-pe target. */ + if (page_size == 0) + page_size = 1; + } + else + page_size = PE_DEF_FILE_ALIGNMENT; + + size = (size + page_size - 1) & - page_size; + /* PR gcc/69880: We must ensure that there are no gaps between the end + of the .rsrc section and whichever section comes next in the file. + This does mean that we can end up with a lot of unused space at + the end of the .rsrc section, but at least this way works. */ + if (sec->next && sec->next->filepos > (file_ptr)(sec->filepos + size)) + size = sec->next->filepos - sec->filepos; bfd_set_section_contents (pfinfo->output_bfd, sec, new_data, 0, size); sec->size = sec->rawsize = size;