diff --git a/binutils-CVE-2019-17450.patch b/binutils-CVE-2019-17450.patch new file mode 100644 index 0000000..c664ee8 --- /dev/null +++ b/binutils-CVE-2019-17450.patch @@ -0,0 +1,62 @@ +--- binutils.orig/bfd/dwarf2.c 2019-11-13 11:49:52.211121564 +0000 ++++ binutils-2.33.1/bfd/dwarf2.c 2019-11-13 11:53:26.991423055 +0000 +@@ -2813,8 +2813,8 @@ static bfd_boolean comp_unit_maybe_decod + + static bfd_boolean + find_abstract_instance (struct comp_unit * unit, +- bfd_byte * orig_info_ptr, + struct attribute * attr_ptr, ++ unsigned int recur_count, + const char ** pname, + bfd_boolean * is_linkage, + char ** filename_ptr, +@@ -2829,6 +2829,14 @@ find_abstract_instance (struct comp_unit + struct attribute attr; + const char *name = NULL; + ++ if (recur_count == 100) ++ { ++ _bfd_error_handler ++ (_("DWARF error: abstract instance recursion detected")); ++ bfd_set_error (bfd_error_bad_value); ++ return FALSE; ++ } ++ + /* DW_FORM_ref_addr can reference an entry in a different CU. It + is an offset from the .debug_info section, not the current CU. */ + if (attr_ptr->form == DW_FORM_ref_addr) +@@ -2962,15 +2970,7 @@ find_abstract_instance (struct comp_unit + info_ptr, info_ptr_end); + if (info_ptr == NULL) + break; +- /* It doesn't ever make sense for DW_AT_specification to +- refer to the same DIE. Stop simple recursion. */ +- if (info_ptr == orig_info_ptr) +- { +- _bfd_error_handler +- (_("DWARF error: abstract instance recursion detected")); +- bfd_set_error (bfd_error_bad_value); +- return FALSE; +- } ++ + switch (attr.name) + { + case DW_AT_name: +@@ -2984,7 +2984,7 @@ find_abstract_instance (struct comp_unit + } + break; + case DW_AT_specification: +- if (!find_abstract_instance (unit, info_ptr, &attr, ++ if (!find_abstract_instance (unit, &attr, recur_count + 1, + &name, is_linkage, + filename_ptr, linenumber_ptr)) + return FALSE; +@@ -3200,7 +3200,7 @@ scan_unit_for_symbols (struct comp_unit + + case DW_AT_abstract_origin: + case DW_AT_specification: +- if (!find_abstract_instance (unit, info_ptr, &attr, ++ if (!find_abstract_instance (unit, &attr, 0, + &func->name, + &func->is_linkage, + &func->file, diff --git a/binutils-CVE-2019-17451.patch b/binutils-CVE-2019-17451.patch new file mode 100644 index 0000000..0f503a3 --- /dev/null +++ b/binutils-CVE-2019-17451.patch @@ -0,0 +1,20 @@ +--- binutils.orig/bfd/dwarf2.c 2019-11-13 11:32:09.395430104 +0000 ++++ binutils-2.33.1/bfd/dwarf2.c 2019-11-13 11:33:17.272899503 +0000 +@@ -4440,7 +4440,16 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + for (total_size = 0; + msec; + msec = find_debug_info (debug_bfd, debug_sections, msec)) +- total_size += msec->size; ++ { ++ /* Catch PR25070 testcase overflowing size calculation here. */ ++ if (total_size + msec->size < total_size ++ || total_size + msec->size < msec->size) ++ { ++ bfd_set_error (bfd_error_no_memory); ++ return FALSE; ++ } ++ total_size += msec->size; ++ } + + stash->info_ptr_memory = (bfd_byte *) bfd_malloc (total_size); + if (stash->info_ptr_memory == NULL) diff --git a/binutils-addr2line-fixes.patch b/binutils-addr2line-fixes.patch new file mode 100644 index 0000000..869fe23 --- /dev/null +++ b/binutils-addr2line-fixes.patch @@ -0,0 +1,1588 @@ +diff -rup binutils.orig/bfd/dwarf2.c binutils-2.33.1/bfd/dwarf2.c +--- binutils.orig/bfd/dwarf2.c 2020-01-02 17:07:57.530373027 +0000 ++++ binutils-2.33.1/bfd/dwarf2.c 2020-01-02 17:11:21.510870042 +0000 +@@ -1,5 +1,5 @@ + /* DWARF 2 support. +- Copyright (C) 1994-2019 Free Software Foundation, Inc. ++ Copyright (C) 1994-2020 Free Software Foundation, Inc. + + Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions + (gavin@cygnus.com). +@@ -82,55 +82,23 @@ struct adjusted_section + bfd_vma adj_vma; + }; + +-struct dwarf2_debug ++struct dwarf2_debug_file + { +- /* A list of all previously read comp_units. */ +- struct comp_unit *all_comp_units; +- +- /* Last comp unit in list above. */ +- struct comp_unit *last_comp_unit; ++ /* The actual bfd from which debug info was loaded. Might be ++ different to orig_bfd because of gnu_debuglink sections. */ ++ bfd *bfd_ptr; + +- /* Names of the debug sections. */ +- const struct dwarf_debug_section *debug_sections; ++ /* Pointer to the symbol table. */ ++ asymbol **syms; + +- /* The next unread compilation unit within the .debug_info section. +- Zero indicates that the .debug_info section has not been loaded +- into a buffer yet. */ ++ /* The current info pointer for the .debug_info section being parsed. */ + bfd_byte *info_ptr; + +- /* Pointer to the end of the .debug_info section memory buffer. */ +- bfd_byte *info_ptr_end; ++ /* A pointer to the memory block allocated for .debug_info sections. */ ++ bfd_byte *dwarf_info_buffer; + +- /* Pointer to the original bfd for which debug was loaded. This is what +- we use to compare and so check that the cached debug data is still +- valid - it saves having to possibly dereference the gnu_debuglink each +- time. */ +- bfd *orig_bfd; +- +- /* Pointer to the bfd, section and address of the beginning of the +- section. The bfd might be different than expected because of +- gnu_debuglink sections. */ +- bfd *bfd_ptr; +- asection *sec; +- bfd_byte *sec_info_ptr; +- +- /* Support for alternate debug info sections created by the DWZ utility: +- This includes a pointer to an alternate bfd which contains *extra*, +- possibly duplicate debug sections, and pointers to the loaded +- .debug_str and .debug_info sections from this bfd. */ +- bfd * alt_bfd_ptr; +- bfd_byte * alt_dwarf_str_buffer; +- bfd_size_type alt_dwarf_str_size; +- bfd_byte * alt_dwarf_info_buffer; +- bfd_size_type alt_dwarf_info_size; +- +- /* A pointer to the memory block allocated for info_ptr. Neither +- info_ptr nor sec_info_ptr are guaranteed to stay pointing to the +- beginning of the malloc block. */ +- bfd_byte *info_ptr_memory; +- +- /* Pointer to the symbol table. */ +- asymbol **syms; ++ /* Length of the loaded .debug_info sections. */ ++ bfd_size_type dwarf_info_size; + + /* Pointer to the .debug_abbrev section loaded into memory. */ + bfd_byte *dwarf_abbrev_buffer; +@@ -162,6 +130,33 @@ struct dwarf2_debug + /* Length of the loaded .debug_ranges section. */ + bfd_size_type dwarf_ranges_size; + ++ /* A list of all previously read comp_units. */ ++ struct comp_unit *all_comp_units; ++ ++ /* Last comp unit in list above. */ ++ struct comp_unit *last_comp_unit; ++ ++ /* Line table at line_offset zero. */ ++ struct line_info_table *line_table; ++ ++ /* Hash table to map offsets to decoded abbrevs. */ ++ htab_t abbrev_offsets; ++}; ++ ++struct dwarf2_debug ++{ ++ /* Names of the debug sections. */ ++ const struct dwarf_debug_section *debug_sections; ++ ++ /* Per-file stuff. */ ++ struct dwarf2_debug_file f, alt; ++ ++ /* Pointer to the original bfd for which debug was loaded. This is what ++ we use to compare and so check that the cached debug data is still ++ valid - it saves having to possibly dereference the gnu_debuglink each ++ time. */ ++ bfd *orig_bfd; ++ + /* If the most recent call to bfd_find_nearest_line was given an + address in an inlined function, preserve a pointer into the + calling chain for subsequent calls to bfd_find_inliner_info to +@@ -276,8 +271,9 @@ struct comp_unit + /* A list of the variables found in this comp. unit. */ + struct varinfo *variable_table; + +- /* Pointer to dwarf2_debug structure. */ ++ /* Pointers to dwarf2_debug structures. */ + struct dwarf2_debug *stash; ++ struct dwarf2_debug_file *file; + + /* DWARF format version for this unit - from unit header. */ + int version; +@@ -706,6 +702,7 @@ read_indirect_string (struct comp_unit * + { + bfd_uint64_t offset; + struct dwarf2_debug *stash = unit->stash; ++ struct dwarf2_debug_file *file = unit->file; + char *str; + + if (buf + unit->offset_size > buf_end) +@@ -722,13 +719,11 @@ read_indirect_string (struct comp_unit * + *bytes_read_ptr = unit->offset_size; + + if (! read_section (unit->abfd, &stash->debug_sections[debug_str], +- stash->syms, offset, +- &stash->dwarf_str_buffer, &stash->dwarf_str_size)) ++ file->syms, offset, ++ &file->dwarf_str_buffer, &file->dwarf_str_size)) + return NULL; + +- if (offset >= stash->dwarf_str_size) +- return NULL; +- str = (char *) stash->dwarf_str_buffer + offset; ++ str = (char *) file->dwarf_str_buffer + offset; + if (*str == '\0') + return NULL; + return str; +@@ -744,6 +739,7 @@ read_indirect_line_string (struct comp_u + { + bfd_uint64_t offset; + struct dwarf2_debug *stash = unit->stash; ++ struct dwarf2_debug_file *file = unit->file; + char *str; + + if (buf + unit->offset_size > buf_end) +@@ -760,14 +756,12 @@ read_indirect_line_string (struct comp_u + *bytes_read_ptr = unit->offset_size; + + if (! read_section (unit->abfd, &stash->debug_sections[debug_line_str], +- stash->syms, offset, +- &stash->dwarf_line_str_buffer, +- &stash->dwarf_line_str_size)) ++ file->syms, offset, ++ &file->dwarf_line_str_buffer, ++ &file->dwarf_line_str_size)) + return NULL; + +- if (offset >= stash->dwarf_line_str_size) +- return NULL; +- str = (char *) stash->dwarf_line_str_buffer + offset; ++ str = (char *) file->dwarf_line_str_buffer + offset; + if (*str == '\0') + return NULL; + return str; +@@ -800,7 +794,7 @@ read_alt_indirect_string (struct comp_un + + *bytes_read_ptr = unit->offset_size; + +- if (stash->alt_bfd_ptr == NULL) ++ if (stash->alt.bfd_ptr == NULL) + { + bfd *debug_bfd; + char *debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR); +@@ -819,20 +813,17 @@ read_alt_indirect_string (struct comp_un + bfd_close (debug_bfd); + return NULL; + } +- stash->alt_bfd_ptr = debug_bfd; ++ stash->alt.bfd_ptr = debug_bfd; + } + +- if (! read_section (unit->stash->alt_bfd_ptr, ++ if (! read_section (unit->stash->alt.bfd_ptr, + stash->debug_sections + debug_str_alt, +- NULL, /* FIXME: Do we need to load alternate symbols ? */ +- offset, +- &stash->alt_dwarf_str_buffer, +- &stash->alt_dwarf_str_size)) ++ stash->alt.syms, offset, ++ &stash->alt.dwarf_str_buffer, ++ &stash->alt.dwarf_str_size)) + return NULL; + +- if (offset >= stash->alt_dwarf_str_size) +- return NULL; +- str = (char *) stash->alt_dwarf_str_buffer + offset; ++ str = (char *) stash->alt.dwarf_str_buffer + offset; + if (*str == '\0') + return NULL; + +@@ -849,13 +840,13 @@ read_alt_indirect_ref (struct comp_unit + { + struct dwarf2_debug *stash = unit->stash; + +- if (stash->alt_bfd_ptr == NULL) ++ if (stash->alt.bfd_ptr == NULL) + { + bfd *debug_bfd; + char *debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR); + + if (debug_filename == NULL) +- return FALSE; ++ return NULL; + + debug_bfd = bfd_openr (debug_filename, NULL); + free (debug_filename); +@@ -868,20 +859,17 @@ read_alt_indirect_ref (struct comp_unit + bfd_close (debug_bfd); + return NULL; + } +- stash->alt_bfd_ptr = debug_bfd; ++ stash->alt.bfd_ptr = debug_bfd; + } + +- if (! read_section (unit->stash->alt_bfd_ptr, ++ if (! read_section (unit->stash->alt.bfd_ptr, + stash->debug_sections + debug_info_alt, +- NULL, /* FIXME: Do we need to load alternate symbols ? */ +- offset, +- &stash->alt_dwarf_info_buffer, +- &stash->alt_dwarf_info_size)) ++ stash->alt.syms, offset, ++ &stash->alt.dwarf_info_buffer, ++ &stash->alt.dwarf_info_size)) + return NULL; + +- if (offset >= stash->alt_dwarf_info_size) +- return NULL; +- return stash->alt_dwarf_info_buffer + offset; ++ return stash->alt.dwarf_info_buffer + offset; + } + + static bfd_uint64_t +@@ -947,13 +935,59 @@ lookup_abbrev (unsigned int number, stru + return NULL; + } + ++/* We keep a hash table to map .debug_abbrev section offsets to the ++ array of abbrevs, so that compilation units using the same set of ++ abbrevs do not waste memory. */ ++ ++struct abbrev_offset_entry ++{ ++ size_t offset; ++ struct abbrev_info **abbrevs; ++}; ++ ++static hashval_t ++hash_abbrev (const void *p) ++{ ++ const struct abbrev_offset_entry *ent = p; ++ return htab_hash_pointer ((void *) ent->offset); ++} ++ ++static int ++eq_abbrev (const void *pa, const void *pb) ++{ ++ const struct abbrev_offset_entry *a = pa; ++ const struct abbrev_offset_entry *b = pb; ++ return a->offset == b->offset; ++} ++ ++static void ++del_abbrev (void *p) ++{ ++ struct abbrev_offset_entry *ent = p; ++ struct abbrev_info **abbrevs = ent->abbrevs; ++ size_t i; ++ ++ for (i = 0; i < ABBREV_HASH_SIZE; i++) ++ { ++ struct abbrev_info *abbrev = abbrevs[i]; ++ ++ while (abbrev) ++ { ++ free (abbrev->attrs); ++ abbrev = abbrev->next; ++ } ++ } ++ free (ent); ++} ++ + /* In DWARF version 2, the description of the debugging information is + stored in a separate .debug_abbrev section. Before we read any + dies from a section we read in all abbreviations and install them + in a hash table. */ + + static struct abbrev_info** +-read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash) ++read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash, ++ struct dwarf2_debug_file *file) + { + struct abbrev_info **abbrevs; + bfd_byte *abbrev_ptr; +@@ -962,13 +996,22 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of + unsigned int abbrev_number, bytes_read, abbrev_name; + unsigned int abbrev_form, hash_number; + bfd_size_type amt; ++ void **slot; ++ struct abbrev_offset_entry ent = { offset, NULL }; + +- if (! read_section (abfd, &stash->debug_sections[debug_abbrev], +- stash->syms, offset, +- &stash->dwarf_abbrev_buffer, &stash->dwarf_abbrev_size)) ++ if (ent.offset != offset) + return NULL; + +- if (offset >= stash->dwarf_abbrev_size) ++ slot = htab_find_slot (file->abbrev_offsets, &ent, INSERT); ++ if (slot == NULL) ++ return NULL; ++ if (*slot != NULL) ++ return ((struct abbrev_offset_entry *) (*slot))->abbrevs; ++ ++ if (! read_section (abfd, &stash->debug_sections[debug_abbrev], ++ file->syms, offset, ++ &file->dwarf_abbrev_buffer, ++ &file->dwarf_abbrev_size)) + return NULL; + + amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE; +@@ -976,8 +1019,8 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of + if (abbrevs == NULL) + return NULL; + +- abbrev_ptr = stash->dwarf_abbrev_buffer + offset; +- abbrev_end = stash->dwarf_abbrev_buffer + stash->dwarf_abbrev_size; ++ abbrev_ptr = file->dwarf_abbrev_buffer + offset; ++ abbrev_end = file->dwarf_abbrev_buffer + file->dwarf_abbrev_size; + abbrev_number = _bfd_safe_read_leb128 (abfd, abbrev_ptr, &bytes_read, + FALSE, abbrev_end); + abbrev_ptr += bytes_read; +@@ -988,7 +1031,7 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of + amt = sizeof (struct abbrev_info); + cur_abbrev = (struct abbrev_info *) bfd_zalloc (abfd, amt); + if (cur_abbrev == NULL) +- return NULL; ++ goto fail; + + /* Read in abbrev header. */ + cur_abbrev->number = abbrev_number; +@@ -1030,21 +1073,7 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of + amt *= sizeof (struct attr_abbrev); + tmp = (struct attr_abbrev *) bfd_realloc (cur_abbrev->attrs, amt); + if (tmp == NULL) +- { +- size_t i; +- +- for (i = 0; i < ABBREV_HASH_SIZE; i++) +- { +- struct abbrev_info *abbrev = abbrevs[i]; +- +- while (abbrev) +- { +- free (abbrev->attrs); +- abbrev = abbrev->next; +- } +- } +- return NULL; +- } ++ goto fail; + cur_abbrev->attrs = tmp; + } + +@@ -1068,8 +1097,8 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of + already read (which means we are about to read the abbreviations + for the next compile unit) or if the end of the abbreviation + table is reached. */ +- if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer) +- >= stash->dwarf_abbrev_size) ++ if ((size_t) (abbrev_ptr - file->dwarf_abbrev_buffer) ++ >= file->dwarf_abbrev_size) + break; + abbrev_number = _bfd_safe_read_leb128 (abfd, abbrev_ptr, + &bytes_read, FALSE, abbrev_end); +@@ -1078,7 +1107,31 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of + break; + } + ++ *slot = bfd_malloc (sizeof ent); ++ if (!*slot) ++ goto fail; ++ ent.abbrevs = abbrevs; ++ memcpy (*slot, &ent, sizeof ent); + return abbrevs; ++ ++ fail: ++ if (abbrevs != NULL) ++ { ++ size_t i; ++ ++ for (i = 0; i < ABBREV_HASH_SIZE; i++) ++ { ++ struct abbrev_info *abbrev = abbrevs[i]; ++ ++ while (abbrev) ++ { ++ free (abbrev->attrs); ++ abbrev = abbrev->next; ++ } ++ } ++ free (abbrevs); ++ } ++ return NULL; + } + + /* Returns true if the form is one which has a string value. */ +@@ -1413,6 +1466,8 @@ struct lookup_funcinfo + The highest address of all prior functions after the lookup table is + sorted, which is used for binary search. */ + bfd_vma high_addr; ++ /* Index of this function, used to ensure qsort is stable. */ ++ unsigned int idx; + }; + + struct varinfo +@@ -1713,6 +1768,11 @@ compare_sequences (const void* a, const + if (seq1->last_line->op_index > seq2->last_line->op_index) + return -1; + ++ /* num_lines is initially an index, to make the sort stable. */ ++ if (seq1->num_lines < seq2->num_lines) ++ return -1; ++ if (seq1->num_lines > seq2->num_lines) ++ return 1; + return 0; + } + +@@ -1739,12 +1799,14 @@ build_line_info_table (struct line_info_ + for (each_line = seq->last_line; each_line; each_line = each_line->prev_line) + num_lines++; + ++ seq->num_lines = num_lines; + if (num_lines == 0) + return TRUE; + + /* Allocate space for the line information lookup table. */ + amt = sizeof (struct line_info*) * num_lines; + line_info_lookup = (struct line_info**) bfd_alloc (table->abfd, amt); ++ seq->line_info_lookup = line_info_lookup; + if (line_info_lookup == NULL) + return FALSE; + +@@ -1754,10 +1816,6 @@ build_line_info_table (struct line_info_ + line_info_lookup[--line_index] = each_line; + + BFD_ASSERT (line_index == 0); +- +- seq->num_lines = num_lines; +- seq->line_info_lookup = line_info_lookup; +- + return TRUE; + } + +@@ -1793,7 +1851,7 @@ sort_line_sequences (struct line_info_ta + sequences[n].prev_sequence = NULL; + sequences[n].last_line = seq->last_line; + sequences[n].line_info_lookup = NULL; +- sequences[n].num_lines = 0; ++ sequences[n].num_lines = n; + seq = seq->prev_sequence; + free (last_seq); + } +@@ -2020,9 +2078,11 @@ read_formatted_entries (struct comp_unit + /* Decode the line number information for UNIT. */ + + static struct line_info_table* +-decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash) ++decode_line_info (struct comp_unit *unit) + { + bfd *abfd = unit->abfd; ++ struct dwarf2_debug *stash = unit->stash; ++ struct dwarf2_debug_file *file = unit->file; + struct line_info_table* table; + bfd_byte *line_ptr; + bfd_byte *line_end; +@@ -2033,39 +2093,24 @@ decode_line_info (struct comp_unit *unit + unsigned int exop_len; + bfd_size_type amt; + +- if (! read_section (abfd, &stash->debug_sections[debug_line], +- stash->syms, unit->line_offset, +- &stash->dwarf_line_buffer, &stash->dwarf_line_size)) +- return NULL; ++ if (unit->line_offset == 0 && file->line_table) ++ return file->line_table; + +- amt = sizeof (struct line_info_table); +- table = (struct line_info_table *) bfd_alloc (abfd, amt); +- if (table == NULL) ++ if (! read_section (abfd, &stash->debug_sections[debug_line], ++ file->syms, unit->line_offset, ++ &file->dwarf_line_buffer, &file->dwarf_line_size)) + return NULL; +- table->abfd = abfd; +- table->comp_dir = unit->comp_dir; + +- table->num_files = 0; +- table->files = NULL; +- +- table->num_dirs = 0; +- table->dirs = NULL; +- +- table->num_sequences = 0; +- table->sequences = NULL; +- +- table->lcl_head = NULL; +- +- if (stash->dwarf_line_size < 16) ++ if (file->dwarf_line_size < 16) + { + _bfd_error_handler + (_("DWARF error: line info section is too small (%" PRId64 ")"), +- (int64_t) stash->dwarf_line_size); ++ (int64_t) file->dwarf_line_size); + bfd_set_error (bfd_error_bad_value); + return NULL; + } +- line_ptr = stash->dwarf_line_buffer + unit->line_offset; +- line_end = stash->dwarf_line_buffer + stash->dwarf_line_size; ++ line_ptr = file->dwarf_line_buffer + unit->line_offset; ++ line_end = file->dwarf_line_buffer + file->dwarf_line_size; + + /* Read in the prologue. */ + lh.total_length = read_4_bytes (abfd, line_ptr, line_end); +@@ -2192,6 +2237,24 @@ decode_line_info (struct comp_unit *unit + line_ptr += 1; + } + ++ amt = sizeof (struct line_info_table); ++ table = (struct line_info_table *) bfd_alloc (abfd, amt); ++ if (table == NULL) ++ return NULL; ++ table->abfd = abfd; ++ table->comp_dir = unit->comp_dir; ++ ++ table->num_files = 0; ++ table->files = NULL; ++ ++ table->num_dirs = 0; ++ table->dirs = NULL; ++ ++ table->num_sequences = 0; ++ table->sequences = NULL; ++ ++ table->lcl_head = NULL; ++ + if (lh.version >= 5) + { + /* Read directory table. */ +@@ -2391,16 +2454,16 @@ decode_line_info (struct comp_unit *unit + break; + case DW_LNS_set_file: + { +- unsigned int file; ++ unsigned int filenum; + + /* The file and directory tables are 0 + based, the references are 1 based. */ +- file = _bfd_safe_read_leb128 (abfd, line_ptr, &bytes_read, +- FALSE, line_end); ++ filenum = _bfd_safe_read_leb128 (abfd, line_ptr, &bytes_read, ++ FALSE, line_end); + line_ptr += bytes_read; + if (filename) + free (filename); +- filename = concat_filename (table, file); ++ filename = concat_filename (table, filenum); + break; + } + case DW_LNS_set_column: +@@ -2449,6 +2512,8 @@ decode_line_info (struct comp_unit *unit + free (filename); + } + ++ if (unit->line_offset == 0) ++ file->line_table = table; + if (sort_line_sequences (table)) + return table; + +@@ -2544,12 +2609,12 @@ fail: + static bfd_boolean + read_debug_ranges (struct comp_unit * unit) + { +- struct dwarf2_debug * stash = unit->stash; ++ struct dwarf2_debug *stash = unit->stash; ++ struct dwarf2_debug_file *file = unit->file; + + return read_section (unit->abfd, &stash->debug_sections[debug_ranges], +- stash->syms, 0, +- &stash->dwarf_ranges_buffer, +- &stash->dwarf_ranges_size); ++ file->syms, 0, ++ &file->dwarf_ranges_buffer, &file->dwarf_ranges_size); + } + + /* Function table functions. */ +@@ -2569,6 +2634,10 @@ compare_lookup_funcinfos (const void * a + if (lookup1->high_addr > lookup2->high_addr) + return 1; + ++ if (lookup1->idx < lookup2->idx) ++ return -1; ++ if (lookup1->idx > lookup2->idx) ++ return 1; + return 0; + } + +@@ -2598,6 +2667,7 @@ build_lookup_funcinfo_table (struct comp + { + entry = &lookup_funcinfo_table[--func_index]; + entry->funcinfo = each; ++ entry->idx = func_index; + + /* Calculate the lowest and highest address for this function entry. */ + low_addr = entry->funcinfo->arange.low; +@@ -2807,21 +2877,21 @@ lookup_symbol_in_variable_table (struct + return FALSE; + } + +-static struct comp_unit *stash_comp_unit (struct dwarf2_debug *); +-static bfd_boolean comp_unit_maybe_decode_line_info (struct comp_unit *, +- struct dwarf2_debug *); ++static struct comp_unit *stash_comp_unit (struct dwarf2_debug *, ++ struct dwarf2_debug_file *); ++static bfd_boolean comp_unit_maybe_decode_line_info (struct comp_unit *); + + static bfd_boolean +-find_abstract_instance (struct comp_unit * unit, +- struct attribute * attr_ptr, +- unsigned int recur_count, +- const char ** pname, +- bfd_boolean * is_linkage, +- char ** filename_ptr, +- int * linenumber_ptr) ++find_abstract_instance (struct comp_unit *unit, ++ struct attribute *attr_ptr, ++ unsigned int recur_count, ++ const char **pname, ++ bfd_boolean *is_linkage, ++ char **filename_ptr, ++ int *linenumber_ptr) + { + bfd *abfd = unit->abfd; +- bfd_byte *info_ptr; ++ bfd_byte *info_ptr = NULL; + bfd_byte *info_ptr_end; + unsigned int abbrev_number, bytes_read, i; + struct abbrev_info *abbrev; +@@ -2832,7 +2902,7 @@ find_abstract_instance (struct comp_unit + if (recur_count == 100) + { + _bfd_error_handler +- (_("DWARF error: abstract instance recursion detected")); ++ (_("DWARF error: abstract instance recursion detected")); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } +@@ -2854,12 +2924,12 @@ find_abstract_instance (struct comp_unit + a symbolic reference to a label in any .debug_info section + might be used. Since we lay out multiple .debug_info + sections at non-zero VMAs (see place_sections), and read +- them contiguously into stash->info_ptr_memory, that means +- the reference is relative to stash->info_ptr_memory. */ ++ them contiguously into dwarf_info_buffer, that means the ++ reference is relative to dwarf_info_buffer. */ + size_t total; + +- info_ptr = unit->stash->info_ptr_memory; +- info_ptr_end = unit->stash->info_ptr_end; ++ info_ptr = unit->file->dwarf_info_buffer; ++ info_ptr_end = info_ptr + unit->file->dwarf_info_size; + total = info_ptr_end - info_ptr; + if (!die_ref) + return TRUE; +@@ -2871,14 +2941,38 @@ find_abstract_instance (struct comp_unit + return FALSE; + } + info_ptr += die_ref; ++ } ++ else if (attr_ptr->form == DW_FORM_GNU_ref_alt) ++ { ++ bfd_boolean first_time = unit->stash->alt.dwarf_info_buffer == NULL; ++ ++ info_ptr = read_alt_indirect_ref (unit, die_ref); ++ if (first_time) ++ unit->stash->alt.info_ptr = unit->stash->alt.dwarf_info_buffer; ++ if (info_ptr == NULL) ++ { ++ _bfd_error_handler ++ (_("DWARF error: unable to read alt ref %" PRIu64), ++ (uint64_t) die_ref); ++ bfd_set_error (bfd_error_bad_value); ++ return FALSE; ++ } ++ info_ptr_end = (unit->stash->alt.dwarf_info_buffer ++ + unit->stash->alt.dwarf_info_size); ++ if (unit->stash->alt.all_comp_units) ++ unit = unit->stash->alt.all_comp_units; ++ } + ++ if (attr_ptr->form == DW_FORM_ref_addr ++ || attr_ptr->form == DW_FORM_GNU_ref_alt) ++ { + /* Now find the CU containing this pointer. */ + if (info_ptr >= unit->info_ptr_unit && info_ptr < unit->end_ptr) + info_ptr_end = unit->end_ptr; + else + { + /* Check other CUs to see if they contain the abbrev. */ +- struct comp_unit * u; ++ struct comp_unit *u; + + for (u = unit->prev_unit; u != NULL; u = u->prev_unit) + if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr) +@@ -2889,15 +2983,27 @@ find_abstract_instance (struct comp_unit + if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr) + break; + +- while (u == NULL) +- { +- u = stash_comp_unit (unit->stash); +- if (u == NULL) +- break; +- if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr) +- break; +- u = NULL; +- } ++ if (attr_ptr->form == DW_FORM_ref_addr) ++ while (u == NULL) ++ { ++ u = stash_comp_unit (unit->stash, &unit->stash->f); ++ if (u == NULL) ++ break; ++ if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr) ++ break; ++ u = NULL; ++ } ++ ++ if (attr_ptr->form == DW_FORM_GNU_ref_alt) ++ while (u == NULL) ++ { ++ u = stash_comp_unit (unit->stash, &unit->stash->alt); ++ if (u == NULL) ++ break; ++ if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr) ++ break; ++ u = NULL; ++ } + + if (u == NULL) + { +@@ -2911,23 +3017,6 @@ find_abstract_instance (struct comp_unit + info_ptr_end = unit->end_ptr; + } + } +- else if (attr_ptr->form == DW_FORM_GNU_ref_alt) +- { +- info_ptr = read_alt_indirect_ref (unit, die_ref); +- if (info_ptr == NULL) +- { +- _bfd_error_handler +- (_("DWARF error: unable to read alt ref %" PRIu64), +- (uint64_t) die_ref); +- bfd_set_error (bfd_error_bad_value); +- return FALSE; +- } +- info_ptr_end = (unit->stash->alt_dwarf_info_buffer +- + unit->stash->alt_dwarf_info_size); +- +- /* FIXME: Do we need to locate the correct CU, in a similar +- fashion to the code in the DW_FORM_ref_addr case above ? */ +- } + else + { + /* DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, DW_FORM_ref8 or +@@ -2970,7 +3059,6 @@ find_abstract_instance (struct comp_unit + info_ptr, info_ptr_end); + if (info_ptr == NULL) + break; +- + switch (attr.name) + { + case DW_AT_name: +@@ -3000,7 +3088,7 @@ find_abstract_instance (struct comp_unit + } + break; + case DW_AT_decl_file: +- if (!comp_unit_maybe_decode_line_info (unit, unit->stash)) ++ if (!comp_unit_maybe_decode_line_info (unit)) + return FALSE; + *filename_ptr = concat_filename (unit->line_table, + attr.u.val); +@@ -3026,16 +3114,16 @@ read_rangelist (struct comp_unit *unit, + bfd_byte *ranges_end; + bfd_vma base_address = unit->base_address; + +- if (! unit->stash->dwarf_ranges_buffer) ++ if (! unit->file->dwarf_ranges_buffer) + { + if (! read_debug_ranges (unit)) + return FALSE; + } + +- ranges_ptr = unit->stash->dwarf_ranges_buffer + offset; +- if (ranges_ptr < unit->stash->dwarf_ranges_buffer) ++ ranges_ptr = unit->file->dwarf_ranges_buffer + offset; ++ if (ranges_ptr < unit->file->dwarf_ranges_buffer) + return FALSE; +- ranges_end = unit->stash->dwarf_ranges_buffer + unit->stash->dwarf_ranges_size; ++ ranges_end = unit->file->dwarf_ranges_buffer + unit->file->dwarf_ranges_size; + + for (;;) + { +@@ -3365,6 +3453,8 @@ scan_unit_for_symbols (struct comp_unit + + static struct comp_unit * + parse_comp_unit (struct dwarf2_debug *stash, ++ struct dwarf2_debug_file *file, ++ bfd_byte *info_ptr, + bfd_vma unit_length, + bfd_byte *info_ptr_unit, + unsigned int offset_size) +@@ -3378,12 +3468,11 @@ parse_comp_unit (struct dwarf2_debug *st + unsigned int abbrev_number, bytes_read, i; + struct abbrev_info *abbrev; + struct attribute attr; +- bfd_byte *info_ptr = stash->info_ptr; + bfd_byte *end_ptr = info_ptr + unit_length; + bfd_size_type amt; + bfd_vma low_pc = 0; + bfd_vma high_pc = 0; +- bfd *abfd = stash->bfd_ptr; ++ bfd *abfd = file->bfd_ptr; + bfd_boolean high_pc_relative = FALSE; + enum dwarf_unit_type unit_type; + +@@ -3460,7 +3549,7 @@ parse_comp_unit (struct dwarf2_debug *st + } + + /* Read the abbrevs for this compilation unit into a table. */ +- abbrevs = read_abbrevs (abfd, abbrev_offset, stash); ++ abbrevs = read_abbrevs (abfd, abbrev_offset, stash, file); + if (! abbrevs) + return NULL; + +@@ -3496,6 +3585,7 @@ parse_comp_unit (struct dwarf2_debug *st + unit->abbrevs = abbrevs; + unit->end_ptr = end_ptr; + unit->stash = stash; ++ unit->file = file; + unit->info_ptr_unit = info_ptr_unit; + + for (i = 0; i < abbrev->num_attrs; ++i) +@@ -3622,18 +3712,17 @@ comp_unit_find_nearest_line (struct comp + const char **filename_ptr, + struct funcinfo **function_ptr, + unsigned int *linenumber_ptr, +- unsigned int *discriminator_ptr, +- struct dwarf2_debug *stash) ++ unsigned int *discriminator_ptr) + { + bfd_boolean func_p; + +- if (!comp_unit_maybe_decode_line_info (unit, stash)) ++ if (!comp_unit_maybe_decode_line_info (unit)) + return FALSE; + + *function_ptr = NULL; + func_p = lookup_address_in_function_table (unit, addr, function_ptr); + if (func_p && (*function_ptr)->tag == DW_TAG_inlined_subroutine) +- stash->inliner_chain = *function_ptr; ++ unit->stash->inliner_chain = *function_ptr; + + return lookup_address_in_line_info_table (unit->line_table, addr, + filename_ptr, +@@ -3646,8 +3735,7 @@ comp_unit_find_nearest_line (struct comp + FALSE otherwise. */ + + static bfd_boolean +-comp_unit_maybe_decode_line_info (struct comp_unit *unit, +- struct dwarf2_debug *stash) ++comp_unit_maybe_decode_line_info (struct comp_unit *unit) + { + if (unit->error) + return FALSE; +@@ -3660,7 +3748,7 @@ comp_unit_maybe_decode_line_info (struct + return FALSE; + } + +- unit->line_table = decode_line_info (unit, stash); ++ unit->line_table = decode_line_info (unit); + + if (! unit->line_table) + { +@@ -3692,10 +3780,9 @@ comp_unit_find_line (struct comp_unit *u + asymbol *sym, + bfd_vma addr, + const char **filename_ptr, +- unsigned int *linenumber_ptr, +- struct dwarf2_debug *stash) ++ unsigned int *linenumber_ptr) + { +- if (!comp_unit_maybe_decode_line_info (unit, stash)) ++ if (!comp_unit_maybe_decode_line_info (unit)) + return FALSE; + + if (sym->flags & BSF_FUNCTION) +@@ -3754,7 +3841,7 @@ comp_unit_hash_info (struct dwarf2_debug + + BFD_ASSERT (stash->info_hash_status != STASH_INFO_HASH_DISABLED); + +- if (!comp_unit_maybe_decode_line_info (unit, stash)) ++ if (!comp_unit_maybe_decode_line_info (unit)) + return FALSE; + + BFD_ASSERT (!unit->cached); +@@ -3885,6 +3972,41 @@ set_debug_vma (bfd *orig_bfd, bfd *debug + } + } + ++/* If the dwarf2 info was found in a separate debug file, return the ++ debug file section corresponding to the section in the original file ++ and the debug file symbols. */ ++ ++static void ++_bfd_dwarf2_stash_syms (struct dwarf2_debug *stash, bfd *abfd, ++ asection **sec, asymbol ***syms) ++{ ++ if (stash->f.bfd_ptr != abfd) ++ { ++ asection *s, *d; ++ ++ if (*sec == NULL) ++ { ++ *syms = stash->f.syms; ++ return; ++ } ++ ++ for (s = abfd->sections, d = stash->f.bfd_ptr->sections; ++ s != NULL && d != NULL; ++ s = s->next, d = d->next) ++ { ++ if ((d->flags & SEC_DEBUGGING) != 0) ++ break; ++ if (s == *sec ++ && strcmp (s->name, d->name) == 0) ++ { ++ *sec = d; ++ *syms = stash->f.syms; ++ break; ++ } ++ } ++ } ++} ++ + /* Unset vmas for adjusted sections in STASH. */ + + static void +@@ -3952,9 +4074,9 @@ place_sections (bfd *orig_bfd, struct dw + + i++; + } +- if (abfd == stash->bfd_ptr) ++ if (abfd == stash->f.bfd_ptr) + break; +- abfd = stash->bfd_ptr; ++ abfd = stash->f.bfd_ptr; + } + + if (i <= 1) +@@ -4017,14 +4139,14 @@ place_sections (bfd *orig_bfd, struct dw + p->adj_vma = sect->vma; + p++; + } +- if (abfd == stash->bfd_ptr) ++ if (abfd == stash->f.bfd_ptr) + break; +- abfd = stash->bfd_ptr; ++ abfd = stash->f.bfd_ptr; + } + } + +- if (orig_bfd != stash->bfd_ptr) +- set_debug_vma (orig_bfd, stash->bfd_ptr); ++ if (orig_bfd != stash->f.bfd_ptr) ++ set_debug_vma (orig_bfd, stash->f.bfd_ptr); + + return TRUE; + } +@@ -4128,13 +4250,13 @@ stash_maybe_update_info_hash_tables (str + struct comp_unit *each; + + /* Exit if hash tables are up-to-date. */ +- if (stash->all_comp_units == stash->hash_units_head) ++ if (stash->f.all_comp_units == stash->hash_units_head) + return TRUE; + + if (stash->hash_units_head) + each = stash->hash_units_head->prev_unit; + else +- each = stash->last_comp_unit; ++ each = stash->f.last_comp_unit; + + while (each) + { +@@ -4147,7 +4269,7 @@ stash_maybe_update_info_hash_tables (str + each = each->prev_unit; + } + +- stash->hash_units_head = stash->all_comp_units; ++ stash->hash_units_head = stash->f.all_comp_units; + return TRUE; + } + +@@ -4162,7 +4284,7 @@ stash_verify_info_hash_table (struct dwa + struct info_list_node *node; + bfd_boolean found; + +- for (each_unit = stash->all_comp_units; ++ for (each_unit = stash->f.all_comp_units; + each_unit; + each_unit = each_unit->next_unit) + { +@@ -4232,8 +4354,8 @@ stash_maybe_enable_info_hash_tables (bfd + /* We need a forced update so that the info hash tables will + be created even though there is no compilation unit. That + happens if STASH_INFO_HASH_TRIGGER is 0. */ +- stash_maybe_update_info_hash_tables (stash); +- stash->info_hash_status = STASH_INFO_HASH_ON; ++ if (stash_maybe_update_info_hash_tables (stash)) ++ stash->info_hash_status = STASH_INFO_HASH_ON; + } + + /* Find the file and line associated with a symbol and address using the +@@ -4342,7 +4464,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + { + /* Check that we did previously find some debug information + before attempting to make use of it. */ +- if (stash->bfd_ptr != NULL) ++ if (stash->f.bfd_ptr != NULL) + { + if (do_place && !place_sections (abfd, stash)) + return FALSE; +@@ -4362,10 +4484,20 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + } + stash->orig_bfd = abfd; + stash->debug_sections = debug_sections; +- stash->syms = symbols; ++ stash->f.syms = symbols; + if (!save_section_vma (abfd, stash)) + return FALSE; + ++ stash->f.abbrev_offsets = htab_create_alloc (10, hash_abbrev, eq_abbrev, ++ del_abbrev, calloc, free); ++ if (!stash->f.abbrev_offsets) ++ return FALSE; ++ ++ stash->alt.abbrev_offsets = htab_create_alloc (10, hash_abbrev, eq_abbrev, ++ del_abbrev, calloc, free); ++ if (!stash->alt.abbrev_offsets) ++ return FALSE; ++ + *pinfo = stash; + + if (debug_bfd == NULL) +@@ -4405,10 +4537,10 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + } + + symbols = bfd_get_outsymbols (debug_bfd); +- stash->syms = symbols; ++ stash->f.syms = symbols; + stash->close_on_cleanup = TRUE; + } +- stash->bfd_ptr = debug_bfd; ++ stash->f.bfd_ptr = debug_bfd; + + if (do_place + && !place_sections (abfd, stash)) +@@ -4431,7 +4563,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + total_size = msec->size; + if (! read_section (debug_bfd, &stash->debug_sections[debug_info], + symbols, 0, +- &stash->info_ptr_memory, &total_size)) ++ &stash->f.dwarf_info_buffer, &total_size)) + return FALSE; + } + else +@@ -4440,19 +4572,19 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + for (total_size = 0; + msec; + msec = find_debug_info (debug_bfd, debug_sections, msec)) +- { +- /* Catch PR25070 testcase overflowing size calculation here. */ +- if (total_size + msec->size < total_size +- || total_size + msec->size < msec->size) +- { +- bfd_set_error (bfd_error_no_memory); +- return FALSE; +- } +- total_size += msec->size; +- } ++ { ++ /* Catch PR25070 testcase overflowing size calculation here. */ ++ if (total_size + msec->size < total_size ++ || total_size + msec->size < msec->size) ++ { ++ bfd_set_error (bfd_error_no_memory); ++ return FALSE; ++ } ++ total_size += msec->size; ++ } + +- stash->info_ptr_memory = (bfd_byte *) bfd_malloc (total_size); +- if (stash->info_ptr_memory == NULL) ++ stash->f.dwarf_info_buffer = (bfd_byte *) bfd_malloc (total_size); ++ if (stash->f.dwarf_info_buffer == NULL) + return FALSE; + + total_size = 0; +@@ -4467,7 +4599,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + continue; + + if (!(bfd_simple_get_relocated_section_contents +- (debug_bfd, msec, stash->info_ptr_memory + total_size, ++ (debug_bfd, msec, stash->f.dwarf_info_buffer + total_size, + symbols))) + return FALSE; + +@@ -4475,35 +4607,33 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, + } + } + +- stash->info_ptr = stash->info_ptr_memory; +- stash->info_ptr_end = stash->info_ptr + total_size; +- stash->sec = find_debug_info (debug_bfd, debug_sections, NULL); +- stash->sec_info_ptr = stash->info_ptr; ++ stash->f.info_ptr = stash->f.dwarf_info_buffer; ++ stash->f.dwarf_info_size = total_size; + return TRUE; + } + +-/* Parse the next DWARF2 compilation unit at STASH->INFO_PTR. */ ++/* Parse the next DWARF2 compilation unit at FILE->INFO_PTR. */ + + static struct comp_unit * +-stash_comp_unit (struct dwarf2_debug *stash) ++stash_comp_unit (struct dwarf2_debug *stash, struct dwarf2_debug_file *file) + { + bfd_size_type length; + unsigned int offset_size; +- bfd_byte *info_ptr_unit = stash->info_ptr; ++ bfd_byte *info_ptr_unit = file->info_ptr; ++ bfd_byte *info_ptr_end = file->dwarf_info_buffer + file->dwarf_info_size; + +- if (stash->info_ptr >= stash->info_ptr_end) ++ if (file->info_ptr >= info_ptr_end) + return NULL; + +- length = read_4_bytes (stash->bfd_ptr, stash->info_ptr, +- stash->info_ptr_end); ++ length = read_4_bytes (file->bfd_ptr, file->info_ptr, info_ptr_end); + /* A 0xffffff length is the DWARF3 way of indicating + we use 64-bit offsets, instead of 32-bit offsets. */ + if (length == 0xffffffff) + { + offset_size = 8; +- length = read_8_bytes (stash->bfd_ptr, stash->info_ptr + 4, +- stash->info_ptr_end); +- stash->info_ptr += 12; ++ length = read_8_bytes (file->bfd_ptr, file->info_ptr + 4, ++ info_ptr_end); ++ file->info_ptr += 12; + } + /* A zero length is the IRIX way of indicating 64-bit offsets, + mostly because the 64-bit length will generally fit in 32 +@@ -4511,9 +4641,9 @@ stash_comp_unit (struct dwarf2_debug *st + else if (length == 0) + { + offset_size = 8; +- length = read_4_bytes (stash->bfd_ptr, stash->info_ptr + 4, +- stash->info_ptr_end); +- stash->info_ptr += 8; ++ length = read_4_bytes (file->bfd_ptr, file->info_ptr + 4, ++ info_ptr_end); ++ file->info_ptr += 8; + } + /* In the absence of the hints above, we assume 32-bit DWARF2 + offsets even for targets with 64-bit addresses, because: +@@ -4527,42 +4657,34 @@ stash_comp_unit (struct dwarf2_debug *st + else + { + offset_size = 4; +- stash->info_ptr += 4; ++ file->info_ptr += 4; + } + + if (length != 0 +- && stash->info_ptr + length <= stash->info_ptr_end +- && stash->info_ptr + length > stash->info_ptr) ++ && file->info_ptr + length <= info_ptr_end ++ && file->info_ptr + length > file->info_ptr) + { +- struct comp_unit *each = parse_comp_unit (stash, length, info_ptr_unit, +- offset_size); ++ struct comp_unit *each = parse_comp_unit (stash, file, ++ file->info_ptr, length, ++ info_ptr_unit, offset_size); + if (each) + { +- if (stash->all_comp_units) +- stash->all_comp_units->prev_unit = each; ++ if (file->all_comp_units) ++ file->all_comp_units->prev_unit = each; + else +- stash->last_comp_unit = each; ++ file->last_comp_unit = each; + +- each->next_unit = stash->all_comp_units; +- stash->all_comp_units = each; ++ each->next_unit = file->all_comp_units; ++ file->all_comp_units = each; + +- stash->info_ptr += length; +- +- if ((bfd_size_type) (stash->info_ptr - stash->sec_info_ptr) +- == stash->sec->size) +- { +- stash->sec = find_debug_info (stash->bfd_ptr, +- stash->debug_sections, +- stash->sec); +- stash->sec_info_ptr = stash->info_ptr; +- } ++ file->info_ptr += length; + return each; + } + } + + /* Don't trust any of the DWARF info after a corrupted length or + parse error. */ +- stash->info_ptr = stash->info_ptr_end; ++ file->info_ptr = info_ptr_end; + return NULL; + } + +@@ -4617,11 +4739,11 @@ _bfd_dwarf2_find_symbol_bias (asymbol ** + } + } + +- for (unit = stash->all_comp_units; unit; unit = unit->next_unit) ++ for (unit = stash->f.all_comp_units; unit; unit = unit->next_unit) + { + struct funcinfo * func; + +- comp_unit_maybe_decode_line_info (unit, stash); ++ comp_unit_maybe_decode_line_info (unit); + + for (func = unit->function_table; func != NULL; func = func->prev_func) + if (func->name && func->arange.low) +@@ -4649,15 +4771,17 @@ _bfd_dwarf2_find_symbol_bias (asymbol ** + /* Find the source code location of SYMBOL. If SYMBOL is NULL + then find the nearest source code location corresponding to + the address SECTION + OFFSET. +- Returns TRUE if the line is found without error and fills in ++ Returns 1 if the line is found without error and fills in + FILENAME_PTR and LINENUMBER_PTR. In the case where SYMBOL was + NULL the FUNCTIONNAME_PTR is also filled in. ++ Returns 2 if partial information from _bfd_elf_find_function is ++ returned (function and maybe file) by looking at symbols. DWARF2 ++ info is present but not regarding the requested code location. ++ Returns 0 otherwise. + SYMBOLS contains the symbol table for ABFD. +- DEBUG_SECTIONS contains the name of the dwarf debug sections. +- field and in the abbreviation offset, or zero to indicate that the +- default value should be used. */ ++ DEBUG_SECTIONS contains the name of the dwarf debug sections. */ + +-bfd_boolean ++int + _bfd_dwarf2_find_nearest_line (bfd *abfd, + asymbol **symbols, + asymbol *symbol, +@@ -4683,7 +4807,7 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + bfd_vma addr; + struct comp_unit* each; + struct funcinfo *function = NULL; +- bfd_boolean found = FALSE; ++ int found = FALSE; + bfd_boolean do_line; + + *filename_ptr = NULL; +@@ -4752,7 +4876,7 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + + /* A null info_ptr indicates that there is no dwarf2 info + (or that an error occured while setting up the stash). */ +- if (! stash->info_ptr) ++ if (! stash->f.info_ptr) + return FALSE; + + stash->inliner_chain = NULL; +@@ -4781,13 +4905,13 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + else + { + /* Check the previously read comp. units first. */ +- for (each = stash->all_comp_units; each; each = each->next_unit) ++ for (each = stash->f.all_comp_units; each; each = each->next_unit) + if ((symbol->flags & BSF_FUNCTION) == 0 + || each->arange.high == 0 + || comp_unit_contains_address (each, addr)) + { + found = comp_unit_find_line (each, symbol, addr, filename_ptr, +- linenumber_ptr, stash); ++ linenumber_ptr); + if (found) + goto done; + } +@@ -4801,18 +4925,16 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + unsigned int local_linenumber = 0; + unsigned int local_discriminator = 0; + +- for (each = stash->all_comp_units; each; each = each->next_unit) ++ for (each = stash->f.all_comp_units; each; each = each->next_unit) + { + bfd_vma range = (bfd_vma) -1; + + found = ((each->arange.high == 0 + || comp_unit_contains_address (each, addr)) +- && (range = comp_unit_find_nearest_line (each, addr, +- & local_filename, +- & local_function, +- & local_linenumber, +- & local_discriminator, +- stash)) != 0); ++ && (range = (comp_unit_find_nearest_line ++ (each, addr, &local_filename, ++ &local_function, &local_linenumber, ++ &local_discriminator))) != 0); + if (found) + { + /* PRs 15935 15994: Bogus debug information may have provided us +@@ -4849,7 +4971,7 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + } + + /* Read each remaining comp. units checking each as they are read. */ +- while ((each = stash_comp_unit (stash)) != NULL) ++ while ((each = stash_comp_unit (stash, &stash->f)) != NULL) + { + /* DW_AT_low_pc and DW_AT_high_pc are optional for + compilation units. If we don't have them (i.e., +@@ -4861,9 +4983,7 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + || each->arange.high == 0 + || comp_unit_contains_address (each, addr)) + && comp_unit_find_line (each, symbol, addr, +- filename_ptr, +- linenumber_ptr, +- stash)); ++ filename_ptr, linenumber_ptr)); + else + found = ((each->arange.high == 0 + || comp_unit_contains_address (each, addr)) +@@ -4871,24 +4991,35 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + filename_ptr, + &function, + linenumber_ptr, +- discriminator_ptr, +- stash) != 0); ++ discriminator_ptr) != 0); + + if (found) + break; + } + + done: +- if (function) +- { +- if (!function->is_linkage) ++ if (functionname_ptr && function && function->is_linkage) ++ *functionname_ptr = function->name; ++ else if (functionname_ptr ++ && (!*functionname_ptr ++ || (function && !function->is_linkage))) ++ { ++ asymbol *fun; ++ asymbol **syms = symbols; ++ asection *sec = section; ++ ++ _bfd_dwarf2_stash_syms (stash, abfd, &sec, &syms); ++ fun = _bfd_elf_find_function (abfd, syms, sec, offset, ++ *filename_ptr ? NULL : filename_ptr, ++ functionname_ptr); ++ ++ if (!found && fun != NULL) ++ found = 2; ++ ++ if (function && !function->is_linkage) + { +- asymbol *fun; + bfd_vma sec_vma; + +- fun = _bfd_elf_find_function (abfd, symbols, section, offset, +- *filename_ptr ? NULL : filename_ptr, +- functionname_ptr); + sec_vma = section->vma; + if (section->output_section != NULL) + sec_vma = section->output_section->vma + section->output_offset; +@@ -4899,8 +5030,8 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd + to stop a repeated search of symbols. */ + function->is_linkage = TRUE; + } +- *functionname_ptr = function->name; + } ++ + if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) + unset_sections (stash); + +@@ -4939,96 +5070,85 @@ _bfd_dwarf2_cleanup_debug_info (bfd *abf + { + struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo; + struct comp_unit *each; ++ struct dwarf2_debug_file *file; + + if (abfd == NULL || stash == NULL) + return; + +- for (each = stash->all_comp_units; each; each = each->next_unit) +- { +- struct abbrev_info **abbrevs = each->abbrevs; +- struct funcinfo *function_table = each->function_table; +- struct varinfo *variable_table = each->variable_table; +- size_t i; ++ if (stash->varinfo_hash_table) ++ bfd_hash_table_free (&stash->varinfo_hash_table->base); ++ if (stash->funcinfo_hash_table) ++ bfd_hash_table_free (&stash->funcinfo_hash_table->base); + +- for (i = 0; i < ABBREV_HASH_SIZE; i++) ++ file = &stash->f; ++ while (1) ++ { ++ for (each = file->all_comp_units; each; each = each->next_unit) + { +- struct abbrev_info *abbrev = abbrevs[i]; ++ struct funcinfo *function_table = each->function_table; ++ struct varinfo *variable_table = each->variable_table; + +- while (abbrev) ++ if (each->line_table && each->line_table != file->line_table) + { +- free (abbrev->attrs); +- abbrev = abbrev->next; ++ free (each->line_table->files); ++ free (each->line_table->dirs); + } +- } + +- if (each->line_table) +- { +- free (each->line_table->dirs); +- free (each->line_table->files); +- } ++ if (each->lookup_funcinfo_table) ++ { ++ free (each->lookup_funcinfo_table); ++ each->lookup_funcinfo_table = NULL; ++ } + +- while (function_table) +- { +- if (function_table->file) ++ while (function_table) + { +- free (function_table->file); +- function_table->file = NULL; ++ if (function_table->file) ++ { ++ free (function_table->file); ++ function_table->file = NULL; ++ } ++ if (function_table->caller_file) ++ { ++ free (function_table->caller_file); ++ function_table->caller_file = NULL; ++ } ++ function_table = function_table->prev_func; + } + +- if (function_table->caller_file) ++ while (variable_table) + { +- free (function_table->caller_file); +- function_table->caller_file = NULL; ++ if (variable_table->file) ++ { ++ free (variable_table->file); ++ variable_table->file = NULL; ++ } ++ variable_table = variable_table->prev_var; + } +- function_table = function_table->prev_func; + } + +- if (each->lookup_funcinfo_table) ++ if (file->line_table) + { +- free (each->lookup_funcinfo_table); +- each->lookup_funcinfo_table = NULL; ++ free (file->line_table->files); ++ free (file->line_table->dirs); + } ++ htab_delete (file->abbrev_offsets); + +- while (variable_table) +- { +- if (variable_table->file) +- { +- free (variable_table->file); +- variable_table->file = NULL; +- } +- +- variable_table = variable_table->prev_var; +- } ++ free (file->dwarf_line_str_buffer); ++ free (file->dwarf_str_buffer); ++ free (file->dwarf_ranges_buffer); ++ free (file->dwarf_line_buffer); ++ free (file->dwarf_abbrev_buffer); ++ free (file->dwarf_info_buffer); ++ if (file == &stash->alt) ++ break; ++ file = &stash->alt; + } +- +- if (stash->funcinfo_hash_table) +- bfd_hash_table_free (&stash->funcinfo_hash_table->base); +- if (stash->varinfo_hash_table) +- bfd_hash_table_free (&stash->varinfo_hash_table->base); +- if (stash->dwarf_abbrev_buffer) +- free (stash->dwarf_abbrev_buffer); +- if (stash->dwarf_line_buffer) +- free (stash->dwarf_line_buffer); +- if (stash->dwarf_str_buffer) +- free (stash->dwarf_str_buffer); +- if (stash->dwarf_line_str_buffer) +- free (stash->dwarf_line_str_buffer); +- if (stash->dwarf_ranges_buffer) +- free (stash->dwarf_ranges_buffer); +- if (stash->info_ptr_memory) +- free (stash->info_ptr_memory); ++ free (stash->sec_vma); ++ free (stash->adjusted_sections); + if (stash->close_on_cleanup) +- bfd_close (stash->bfd_ptr); +- if (stash->alt_dwarf_str_buffer) +- free (stash->alt_dwarf_str_buffer); +- if (stash->alt_dwarf_info_buffer) +- free (stash->alt_dwarf_info_buffer); +- if (stash->sec_vma) +- free (stash->sec_vma); +- if (stash->adjusted_sections) +- free (stash->adjusted_sections); +- if (stash->alt_bfd_ptr) +- bfd_close (stash->alt_bfd_ptr); ++ bfd_close (stash->f.bfd_ptr); ++ if (stash->alt.bfd_ptr) ++ bfd_close (stash->alt.bfd_ptr); + } + + /* Find the function to a particular section and offset, diff --git a/binutils-gold-mismatched-section-flags.patch b/binutils-gold-mismatched-section-flags.patch index 4125801..63dba2b 100644 --- a/binutils-gold-mismatched-section-flags.patch +++ b/binutils-gold-mismatched-section-flags.patch @@ -17,20 +17,3 @@ diff -rup binutils.orig/gold/layout.cc binutils-2.32/gold/layout.cc } if (os == NULL) -diff -rup binutils.orig/gold/object.cc binutils-2.32/gold/object.cc ---- binutils.orig/gold/object.cc 2019-06-24 14:37:36.012086906 +0100 -+++ binutils-2.32/gold/object.cc 2019-06-24 14:39:59.287165501 +0100 -@@ -1644,6 +1644,13 @@ Sized_relobj_file::do_ - omit[i] = true; - } - -+ // Skip empty sections without flags. -+ if (!(shdr.get_sh_flags() & ~elfcpp::SHF_GROUP) -+ && !shdr.get_sh_size()) -+ { -+ omit[i] = true; -+ } -+ - bool discard = omit[i]; - if (!discard) - { diff --git a/binutils-improved-note-merging.patch b/binutils-improved-note-merging.patch new file mode 100644 index 0000000..2f7b30c --- /dev/null +++ b/binutils-improved-note-merging.patch @@ -0,0 +1,1969 @@ +diff -rupN binutils.orig/binutils/objcopy.c binutils-2.33.1/binutils/objcopy.c +--- binutils.orig/binutils/objcopy.c 2019-10-28 11:01:40.438071332 +0000 ++++ binutils-2.33.1/binutils/objcopy.c 2019-10-28 11:05:27.697446056 +0000 +@@ -97,8 +97,14 @@ static int deterministic = -1; /* Enabl + static int status = 0; /* Exit status. */ + + static bfd_boolean merge_notes = FALSE; /* Merge note sections. */ +-static bfd_byte * merged_notes = NULL; /* Contents on note section undergoing a merge. */ +-static bfd_size_type merged_size = 0; /* New, smaller size of the merged note section. */ ++ ++typedef struct merged_note_section ++{ ++ asection * sec; /* The section that is being merged. */ ++ bfd_byte * contents;/* New contents of the section. */ ++ bfd_size_type size; /* New size of the section. */ ++ struct merged_note_section * next; /* Link to next merged note section. */ ++} merged_note_section; + + enum strip_action + { +@@ -1283,7 +1289,7 @@ is_update_section (bfd *abfd ATTRIBUTE_U + } + + static bfd_boolean +-is_merged_note_section (bfd * abfd, asection * sec) ++is_mergeable_note_section (bfd * abfd, asection * sec) + { + if (merge_notes + && bfd_get_flavour (abfd) == bfd_target_elf_flavour +@@ -1292,9 +1298,9 @@ is_merged_note_section (bfd * abfd, asec + We should add support for more note types. */ + && ((elf_section_data (sec)->this_hdr.sh_flags & SHF_GNU_BUILD_NOTE) != 0 + /* Old versions of GAS (prior to 2.27) could not set the section +- flags to OS-specific values, so we also accept sections with the +- expected name. */ +- || (strcmp (sec->name, GNU_BUILD_ATTRS_SECTION_NAME) == 0))) ++ flags to OS-specific values, so we also accept sections that ++ start with the expected name. */ ++ || (CONST_STRNEQ (sec->name, GNU_BUILD_ATTRS_SECTION_NAME)))) + return TRUE; + + return FALSE; +@@ -1917,56 +1923,81 @@ copy_unknown_object (bfd *ibfd, bfd *obf + return TRUE; + } + +-/* Returns the number of bytes needed to store VAL. */ +- +-static inline unsigned int +-num_bytes (unsigned long val) +-{ +- unsigned int count = 0; +- +- /* FIXME: There must be a faster way to do this. */ +- while (val) +- { +- count ++; +- val >>= 8; +- } +- return count; +-} +- + typedef struct objcopy_internal_note + { + Elf_Internal_Note note; ++ unsigned long padded_namesz; + bfd_vma start; + bfd_vma end; +- bfd_boolean modified; + } objcopy_internal_note; + +-/* Returns TRUE if a gap does, or could, exist between the address range +- covered by PNOTE1 and PNOTE2. */ ++#define DEBUG_MERGE 0 ++ ++#if DEBUG_MERGE ++#define merge_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__) ++#else ++#define merge_debug(format, ...) ++#endif ++ ++/* Returns TRUE iff PNOTE1 overlaps or adjoins PNOTE2. */ + + static bfd_boolean +-gap_exists (objcopy_internal_note * pnote1, +- objcopy_internal_note * pnote2) ++overlaps_or_adjoins (objcopy_internal_note * pnote1, ++ objcopy_internal_note * pnote2) + { +- /* Without range end notes, we assume that a gap might exist. */ +- if (pnote1->end == 0 || pnote2->end == 0) ++ if (pnote1->end < pnote2->start) ++ /* FIXME: Alignment of 16 bytes taken from x86_64 binaries. ++ Really we should extract the alignment of the section ++ covered by the notes. */ ++ return BFD_ALIGN (pnote1->end, 16) < pnote2->start; ++ ++ if (pnote2->end < pnote2->start) ++ return BFD_ALIGN (pnote2->end, 16) < pnote1->start; ++ ++ if (pnote1->end < pnote2->end) + return TRUE; + +- /* FIXME: Alignment of 16 bytes taken from x86_64 binaries. +- Really we should extract the alignment of the section covered by the notes. */ +- return BFD_ALIGN (pnote1->end, 16) < pnote2->start; ++ if (pnote2->end < pnote1->end) ++ return TRUE; ++ ++ return FALSE; ++} ++ ++/* Returns TRUE iff NEEDLE is fully contained by HAYSTACK. */ ++ ++static bfd_boolean ++contained_by (objcopy_internal_note * needle, ++ objcopy_internal_note * haystack) ++{ ++ return needle->start >= haystack->start && needle->end <= haystack->end; + } + + static bfd_boolean + is_open_note (objcopy_internal_note * pnote) + { +- return (pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_OPEN); ++ return pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_OPEN; + } + + static bfd_boolean + is_func_note (objcopy_internal_note * pnote) + { +- return (pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_FUNC); ++ return pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_FUNC; ++} ++ ++static bfd_boolean ++is_deleted_note (objcopy_internal_note * pnote) ++{ ++ return pnote->note.type == 0; ++} ++ ++static bfd_boolean ++is_version_note (objcopy_internal_note * pnote) ++{ ++ return (pnote->note.namesz > 4 ++ && pnote->note.namedata[0] == 'G' ++ && pnote->note.namedata[1] == 'A' ++ && pnote->note.namedata[2] == '$' ++ && pnote->note.namedata[3] == GNU_BUILD_ATTRIBUTE_VERSION); + } + + static bfd_boolean +@@ -1979,11 +2010,97 @@ is_64bit (bfd * abfd) + return elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64; + } + ++/* This sorting function is used to get the notes into an order ++ that makes merging easy. */ ++ ++static int ++compare_gnu_build_notes (const void * data1, const void * data2) ++{ ++ objcopy_internal_note * pnote1 = (objcopy_internal_note *) data1; ++ objcopy_internal_note * pnote2 = (objcopy_internal_note *) data2; ++ ++ /* Sort notes based upon the attribute they record. */ ++ int cmp = memcmp (pnote1->note.namedata + 3, ++ pnote2->note.namedata + 3, ++ pnote1->note.namesz < pnote2->note.namesz ? ++ pnote1->note.namesz - 3 : pnote2->note.namesz - 3); ++ if (cmp) ++ return cmp; ++ ++ if (pnote1->end < pnote2->start) ++ return -1; ++ if (pnote1->start > pnote2->end) ++ return 1; ++ ++ /* Overlaps - we should merge the two ranges. */ ++ if (pnote1->start < pnote2->start) ++ return -1; ++ if (pnote1->end > pnote2->end) ++ return 1; ++ ++ /* Put OPEN notes before function notes. */ ++ if (is_open_note (pnote1) && ! is_open_note (pnote2)) ++ return -1; ++ if (! is_open_note (pnote1) && is_open_note (pnote2)) ++ return 1; ++ ++ return 0; ++} ++ ++/* This sorting function is used to get the notes into an order ++ that makes eliminating address ranges easier. */ ++ ++static int ++sort_gnu_build_notes (const void * data1, const void * data2) ++{ ++ objcopy_internal_note * pnote1 = (objcopy_internal_note *) data1; ++ objcopy_internal_note * pnote2 = (objcopy_internal_note *) data2; ++ ++ if (pnote1->note.type != pnote2->note.type) ++ { ++ /* Move deleted notes to the end. */ ++ if (is_deleted_note (pnote1)) /* 1: OFD 2: OFD */ ++ return 1; ++ ++ /* Move OPEN notes to the start. */ ++ if (is_open_note (pnote1)) /* 1: OF 2: OFD */ ++ return -1; ++ ++ if (is_deleted_note (pnote2)) /* 1: F 2: O D */ ++ return -1; ++ ++ return 1; /* 1: F 2: O */ ++ } ++ ++ /* Sort by starting address. */ ++ if (pnote1->start < pnote2->start) ++ return -1; ++ if (pnote1->start > pnote2->start) ++ return 1; ++ ++ /* Then by end address (bigger range first). */ ++ if (pnote1->end > pnote2->end) ++ return -1; ++ if (pnote1->end < pnote2->end) ++ return 1; ++ ++ /* Then by attribute type. */ ++ if (pnote1->note.namesz > 4 ++ && pnote2->note.namesz > 4 ++ && pnote1->note.namedata[3] != pnote2->note.namedata[3]) ++ return pnote1->note.namedata[3] - pnote2->note.namedata[3]; ++ ++ return 0; ++} ++ + /* Merge the notes on SEC, removing redundant entries. + Returns the new, smaller size of the section upon success. */ + + static bfd_size_type +-merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte * contents) ++merge_gnu_build_notes (bfd * abfd, ++ asection * sec, ++ bfd_size_type size, ++ bfd_byte * contents) + { + objcopy_internal_note * pnotes_end; + objcopy_internal_note * pnotes = NULL; +@@ -1992,11 +2109,8 @@ merge_gnu_build_notes (bfd * abfd, asect + unsigned version_1_seen = 0; + unsigned version_2_seen = 0; + unsigned version_3_seen = 0; +- bfd_boolean duplicate_found = FALSE; + const char * err = NULL; + bfd_byte * in = contents; +- int attribute_type_byte; +- int val_start; + unsigned long previous_func_start = 0; + unsigned long previous_open_start = 0; + unsigned long previous_func_end = 0; +@@ -2015,20 +2129,33 @@ merge_gnu_build_notes (bfd * abfd, asect + relcount = bfd_canonicalize_reloc (abfd, sec, relpp, isympp); + free (relpp); + if (relcount != 0) +- goto done; ++ { ++ if (! is_strip) ++ non_fatal (_("%s[%s]: Cannot merge - there are relocations against this section"), ++ bfd_get_filename (abfd), bfd_section_name (abfd, sec)); ++ goto done; ++ } + } + + /* Make a copy of the notes and convert to our internal format. + Minimum size of a note is 12 bytes. Also locate the version + notes and check them. */ +- pnote = pnotes = (objcopy_internal_note *) xcalloc ((size / 12), sizeof (* pnote)); ++ pnote = pnotes = (objcopy_internal_note *) ++ xcalloc ((size / 12), sizeof (* pnote)); + while (remain >= 12) + { + bfd_vma start, end; + +- pnote->note.namesz = (bfd_get_32 (abfd, in ) + 3) & ~3; +- pnote->note.descsz = (bfd_get_32 (abfd, in + 4) + 3) & ~3; +- pnote->note.type = bfd_get_32 (abfd, in + 8); ++ pnote->note.namesz = bfd_get_32 (abfd, in); ++ pnote->note.descsz = bfd_get_32 (abfd, in + 4); ++ pnote->note.type = bfd_get_32 (abfd, in + 8); ++ pnote->padded_namesz = (pnote->note.namesz + 3) & ~3; ++ ++ if (((pnote->note.descsz + 3) & ~3) != pnote->note.descsz) ++ { ++ err = _("corrupt GNU build attribute note: description size not a factor of 4"); ++ goto done; ++ } + + if (pnote->note.type != NT_GNU_BUILD_ATTRIBUTE_OPEN + && pnote->note.type != NT_GNU_BUILD_ATTRIBUTE_FUNC) +@@ -2037,7 +2164,7 @@ merge_gnu_build_notes (bfd * abfd, asect + goto done; + } + +- if (pnote->note.namesz + pnote->note.descsz + 12 > remain) ++ if (pnote->padded_namesz + pnote->note.descsz + 12 > remain) + { + err = _("corrupt GNU build attribute note: note too big"); + goto done; +@@ -2050,21 +2177,17 @@ merge_gnu_build_notes (bfd * abfd, asect + } + + pnote->note.namedata = (char *)(in + 12); +- pnote->note.descdata = (char *)(in + 12 + pnote->note.namesz); ++ pnote->note.descdata = (char *)(in + 12 + pnote->padded_namesz); + +- remain -= 12 + pnote->note.namesz + pnote->note.descsz; +- in += 12 + pnote->note.namesz + pnote->note.descsz; ++ remain -= 12 + pnote->padded_namesz + pnote->note.descsz; ++ in += 12 + pnote->padded_namesz + pnote->note.descsz; + + if (pnote->note.namesz > 2 + && pnote->note.namedata[0] == '$' + && pnote->note.namedata[1] == GNU_BUILD_ATTRIBUTE_VERSION + && pnote->note.namedata[2] == '1') + ++ version_1_seen; +- else if (pnote->note.namesz > 4 +- && pnote->note.namedata[0] == 'G' +- && pnote->note.namedata[1] == 'A' +- && pnote->note.namedata[2] == '$' +- && pnote->note.namedata[3] == GNU_BUILD_ATTRIBUTE_VERSION) ++ else if (is_version_note (pnote)) + { + if (pnote->note.namedata[4] == '2') + ++ version_2_seen; +@@ -2170,11 +2293,18 @@ merge_gnu_build_notes (bfd * abfd, asect + + if (version_1_seen == 0 && version_2_seen == 0 && version_3_seen == 0) + { ++#if 0 + err = _("bad GNU build attribute notes: no known versions detected"); + goto done; ++#else ++ /* This happens with glibc. No idea why. */ ++ non_fatal (_("%s[%s]: Warning: version note missing - assuming version 3"), ++ bfd_get_filename (abfd), bfd_section_name (abfd, sec)); ++ version_3_seen = 2; ++#endif + } + +- if ((version_1_seen > 0 && version_2_seen > 0) ++ if ( (version_1_seen > 0 && version_2_seen > 0) + || (version_1_seen > 0 && version_3_seen > 0) + || (version_2_seen > 0 && version_3_seen > 0)) + { +@@ -2182,270 +2312,215 @@ merge_gnu_build_notes (bfd * abfd, asect + goto done; + } + +- /* Merging is only needed if there is more than one version note... */ +- if (version_1_seen == 1 || version_2_seen == 1 || version_3_seen == 1) +- goto done; +- +- attribute_type_byte = version_1_seen ? 1 : 3; +- val_start = attribute_type_byte + 1; +- +- /* We used to require that the first note be a version note, +- but this is no longer enforced. Due to the problems with +- linking sections with the same name (eg .gnu.build.note.hot) +- we cannot guarantee that the first note will be a version note. */ ++ /* We are now only supporting the merging v3+ notes ++ - it makes things much simpler. */ ++ if (version_3_seen == 0) ++ { ++ merge_debug ("%s: skipping merge - not using v3 notes", bfd_section_name (abfd, sec)); ++ goto done; ++ } ++ ++ merge_debug ("Merging section %s which contains %ld notes\n", ++ sec->name, pnotes_end - pnotes); ++ ++ /* Sort the notes. */ ++ qsort (pnotes, pnotes_end - pnotes, sizeof (* pnotes), ++ compare_gnu_build_notes); ++ ++#if DEBUG_MERGE ++ merge_debug ("Results of initial sort:\n"); ++ for (pnote = pnotes; pnote < pnotes_end; pnote ++) ++ merge_debug ("offset %#08lx range %#08lx..%#08lx type %ld attribute %d namesz %ld\n", ++ (pnote->note.namedata - (char *) contents) - 12, ++ pnote->start, pnote->end, ++ pnote->note.type, ++ pnote->note.namedata[3], ++ pnote->note.namesz ++ ); ++#endif + + /* Now merge the notes. The rules are: +- 1. Preserve the ordering of the notes. +- 2. Preserve any NT_GNU_BUILD_ATTRIBUTE_FUNC notes. +- 3. Eliminate any NT_GNU_BUILD_ATTRIBUTE_OPEN notes that have the same +- full name field as the immediately preceeding note with the same type +- of name and whose address ranges coincide. +- IE - if there are gaps in the coverage of the notes, then these gaps +- must be preserved. +- 4. Combine the numeric value of any NT_GNU_BUILD_ATTRIBUTE_OPEN notes +- of type GNU_BUILD_ATTRIBUTE_STACK_SIZE. +- 5. If an NT_GNU_BUILD_ATTRIBUTE_OPEN note is going to be preserved and +- its description field is empty then the nearest preceeding OPEN note +- with a non-empty description field must also be preserved *OR* the +- description field of the note must be changed to contain the starting +- address to which it refers. +- 6. Notes with the same start and end address can be deleted. +- 7. FIXME: Elminate duplicate version notes - even function specific ones ? */ ++ 1. If a note has a zero range, it can be eliminated. ++ 2. If two notes have the same namedata then: ++ 2a. If one note's range is fully covered by the other note ++ then it can be deleted. ++ 2b. If one note's range partially overlaps or adjoins the ++ other note then if they are both of the same type (open ++ or func) then they can be merged and one deleted. If ++ they are of different types then they cannot be merged. */ + for (pnote = pnotes; pnote < pnotes_end; pnote ++) + { +- int note_type; +- objcopy_internal_note * back; +- objcopy_internal_note * prev_open_with_range = NULL; ++ /* Skip already deleted notes. ++ FIXME: Can this happen ? We are scanning forwards and ++ deleting backwards after all. */ ++ if (is_deleted_note (pnote)) ++ continue; + +- /* Rule 6 - delete 0-range notes. */ ++ /* Rule 1 - delete 0-range notes. */ + if (pnote->start == pnote->end) + { +- duplicate_found = TRUE; ++ merge_debug ("Delete note at offset %#08lx - empty range\n", ++ (pnote->note.namedata - (char *) contents) - 12); + pnote->note.type = 0; + continue; + } + +- /* Rule 2 - preserve function notes. */ +- if (! is_open_note (pnote)) +- { +- int iter; +- +- /* Check to see if there is an identical previous function note. +- This can happen with overlays for example. */ +- for (iter = 0, back = pnote -1; back >= pnotes; back --) +- { +- if (back->start == pnote->start +- && back->end == pnote->end +- && back->note.namesz == pnote->note.namesz +- && memcmp (back->note.namedata, pnote->note.namedata, pnote->note.namesz) == 0) +- { +- duplicate_found = TRUE; +- pnote->note.type = 0; +- break; +- } +- +- /* Don't scan too far back however. */ +- if (iter ++ > 16) +- break; +- } +- continue; +- } +- +- note_type = pnote->note.namedata[attribute_type_byte]; +- +- /* Scan backwards from pnote, looking for duplicates. +- Clear the type field of any found - but do not delete them just yet. */ +- for (back = pnote - 1; back >= pnotes; back --) +- { +- int back_type = back->note.namedata[attribute_type_byte]; +- +- /* If this is the first open note with an address +- range that we have encountered then record it. */ +- if (prev_open_with_range == NULL +- && back->note.descsz > 0 +- && ! is_func_note (back)) +- prev_open_with_range = back; ++ int iter; ++ objcopy_internal_note * back; + +- if (! is_open_note (back)) +- continue; +- +- /* If the two notes are different then keep on searching. */ +- if (back_type != note_type) ++ /* Rule 2: Check to see if there is an identical previous note. */ ++ for (iter = 0, back = pnote - 1; back >= pnotes; back --) ++ { ++ if (is_deleted_note (back)) + continue; + +- /* Rule 4 - combine stack size notes. */ +- if (back_type == GNU_BUILD_ATTRIBUTE_STACK_SIZE) ++ /* Our sorting function should have placed all identically ++ attributed notes together, so if we see a note of a different ++ attribute type stop searching. */ ++ if (back->note.namesz != pnote->note.namesz ++ || memcmp (back->note.namedata, ++ pnote->note.namedata, pnote->note.namesz) != 0) ++ break; ++ ++ if (back->start == pnote->start ++ && back->end == pnote->end) + { +- unsigned char * name; +- unsigned long note_val; +- unsigned long back_val; +- unsigned int shift; +- unsigned int bytes; +- unsigned long byte; +- +- for (shift = 0, note_val = 0, +- bytes = pnote->note.namesz - val_start, +- name = (unsigned char *) pnote->note.namedata + val_start; +- bytes--;) +- { +- byte = (* name ++) & 0xff; +- note_val |= byte << shift; +- shift += 8; +- } +- +- for (shift = 0, back_val = 0, +- bytes = back->note.namesz - val_start, +- name = (unsigned char *) back->note.namedata + val_start; +- bytes--;) +- { +- byte = (* name ++) & 0xff; +- back_val |= byte << shift; +- shift += 8; +- } +- +- back_val += note_val; +- if (num_bytes (back_val) >= back->note.namesz - val_start) +- { +- /* We have a problem - the new value requires more bytes of +- storage in the name field than are available. Currently +- we have no way of fixing this, so we just preserve both +- notes. */ +- continue; +- } +- +- /* Write the new val into back. */ +- name = (unsigned char *) back->note.namedata + val_start; +- while (name < (unsigned char *) back->note.namedata +- + back->note.namesz) +- { +- byte = back_val & 0xff; +- * name ++ = byte; +- if (back_val == 0) +- break; +- back_val >>= 8; +- } +- +- duplicate_found = TRUE; ++ merge_debug ("Delete note at offset %#08lx - duplicate of note at offset %#08lx\n", ++ (pnote->note.namedata - (char *) contents) - 12, ++ (back->note.namedata - (char *) contents) - 12); + pnote->note.type = 0; + break; + } + +- /* Rule 3 - combine identical open notes. */ +- if (back->note.namesz == pnote->note.namesz +- && memcmp (back->note.namedata, +- pnote->note.namedata, back->note.namesz) == 0 +- && ! gap_exists (back, pnote)) ++ /* Rule 2a. */ ++ if (contained_by (pnote, back)) + { +- duplicate_found = TRUE; ++ merge_debug ("Delete note at offset %#08lx - fully contained by note at %#08lx\n", ++ (pnote->note.namedata - (char *) contents) - 12, ++ (back->note.namedata - (char *) contents) - 12); + pnote->note.type = 0; ++ break; ++ } + +- if (pnote->end > back->end) +- back->end = pnote->end; ++#if DEBUG_MERGE ++ /* This should not happen as we have sorted the ++ notes with earlier starting addresses first. */ ++ if (contained_by (back, pnote)) ++ merge_debug ("ERROR: UNEXPECTED CONTAINMENT\n"); ++#endif ++ ++ /* Rule 2b. */ ++ if (overlaps_or_adjoins (back, pnote) ++ && is_func_note (back) == is_func_note (pnote)) ++ { ++ merge_debug ("Delete note at offset %#08lx - merge into note at %#08lx\n", ++ (pnote->note.namedata - (char *) contents) - 12, ++ (back->note.namedata - (char *) contents) - 12); + +- if (version_3_seen) +- back->modified = TRUE; ++ back->end = back->end > pnote->end ? back->end : pnote->end; ++ back->start = back->start < pnote->start ? back->start : pnote->start; ++ pnote->note.type = 0; + break; + } + +- /* Rule 5 - Since we are keeping this note we must check to see +- if its description refers back to an earlier OPEN version +- note that has been scheduled for deletion. If so then we +- must make sure that version note is also preserved. */ +- if (version_3_seen) +- { +- /* As of version 3 we can just +- move the range into the note. */ +- pnote->modified = TRUE; +- pnote->note.type = NT_GNU_BUILD_ATTRIBUTE_FUNC; +- back->modified = TRUE; +- back->note.type = NT_GNU_BUILD_ATTRIBUTE_FUNC; +- } +- else ++ /* Don't scan too far back however. */ ++ if (iter ++ > 16) + { +- if (pnote->note.descsz == 0 +- && prev_open_with_range != NULL +- && prev_open_with_range->note.type == 0) +- prev_open_with_range->note.type = NT_GNU_BUILD_ATTRIBUTE_OPEN; ++ /* FIXME: Not sure if this can ever be triggered. */ ++ merge_debug ("ITERATION LIMIT REACHED\n"); ++ break; + } +- +- /* We have found a similar attribute but the details do not match. +- Stop searching backwards. */ +- break; + } +- } +- +- if (duplicate_found) +- { +- bfd_byte * new_contents; +- bfd_byte * old; +- bfd_byte * new; +- bfd_size_type new_size; +- bfd_vma prev_start = 0; +- bfd_vma prev_end = 0; +- +- /* Eliminate the duplicates. */ +- new = new_contents = xmalloc (size); +- for (pnote = pnotes, old = contents; +- pnote < pnotes_end; +- pnote ++) +- { +- bfd_size_type note_size = 12 + pnote->note.namesz + pnote->note.descsz; +- +- if (pnote->note.type != 0) ++#if DEBUG_MERGE ++ if (! is_deleted_note (pnote)) ++ merge_debug ("Unable to do anything with note at %#08lx\n", ++ (pnote->note.namedata - (char *) contents) - 12); ++#endif ++ } ++ ++ /* Resort the notes. */ ++ merge_debug ("Final sorting of notes\n"); ++ qsort (pnotes, pnotes_end - pnotes, sizeof (* pnotes), sort_gnu_build_notes); ++ ++ /* Reconstruct the ELF notes. */ ++ bfd_byte * new_contents; ++ bfd_byte * old; ++ bfd_byte * new; ++ bfd_size_type new_size; ++ bfd_vma prev_start = 0; ++ bfd_vma prev_end = 0; ++ ++ new = new_contents = xmalloc (size); ++ for (pnote = pnotes, old = contents; ++ pnote < pnotes_end; ++ pnote ++) ++ { ++ bfd_size_type note_size = 12 + pnote->padded_namesz + pnote->note.descsz; ++ ++ if (! is_deleted_note (pnote)) ++ { ++ /* Create the note, potentially using the ++ address range of the previous note. */ ++ if (pnote->start == prev_start && pnote->end == prev_end) ++ { ++ bfd_put_32 (abfd, pnote->note.namesz, new); ++ bfd_put_32 (abfd, 0, new + 4); ++ bfd_put_32 (abfd, pnote->note.type, new + 8); ++ new += 12; ++ memcpy (new, pnote->note.namedata, pnote->note.namesz); ++ if (pnote->note.namesz < pnote->padded_namesz) ++ memset (new + pnote->note.namesz, 0, pnote->padded_namesz - pnote->note.namesz); ++ new += pnote->padded_namesz; ++ } ++ else + { +- if (pnote->modified) ++ bfd_put_32 (abfd, pnote->note.namesz, new); ++ bfd_put_32 (abfd, is_64bit (abfd) ? 16 : 8, new + 4); ++ bfd_put_32 (abfd, pnote->note.type, new + 8); ++ new += 12; ++ memcpy (new, pnote->note.namedata, pnote->note.namesz); ++ if (pnote->note.namesz < pnote->padded_namesz) ++ memset (new + pnote->note.namesz, 0, pnote->padded_namesz - pnote->note.namesz); ++ new += pnote->padded_namesz; ++ if (is_64bit (abfd)) + { +- /* If the note has been modified then we must copy it by +- hand, potentially adding in a new description field. */ +- if (pnote->start == prev_start && pnote->end == prev_end) +- { +- bfd_put_32 (abfd, pnote->note.namesz, new); +- bfd_put_32 (abfd, 0, new + 4); +- bfd_put_32 (abfd, pnote->note.type, new + 8); +- new += 12; +- memcpy (new, pnote->note.namedata, pnote->note.namesz); +- new += pnote->note.namesz; +- } +- else +- { +- bfd_put_32 (abfd, pnote->note.namesz, new); +- bfd_put_32 (abfd, is_64bit (abfd) ? 16 : 8, new + 4); +- bfd_put_32 (abfd, pnote->note.type, new + 8); +- new += 12; +- memcpy (new, pnote->note.namedata, pnote->note.namesz); +- new += pnote->note.namesz; +- if (is_64bit (abfd)) +- { +- bfd_put_64 (abfd, pnote->start, new); +- bfd_put_64 (abfd, pnote->end, new + 8); +- new += 16; +- } +- else +- { +- bfd_put_32 (abfd, pnote->start, new); +- bfd_put_32 (abfd, pnote->end, new + 4); +- new += 8; +- } +- } ++ bfd_put_64 (abfd, pnote->start, new); ++ bfd_put_64 (abfd, pnote->end, new + 8); ++ new += 16; + } + else + { +- memcpy (new, old, note_size); +- new += note_size; ++ bfd_put_32 (abfd, pnote->start, new); ++ bfd_put_32 (abfd, pnote->end, new + 4); ++ new += 8; + } ++ + prev_start = pnote->start; + prev_end = pnote->end; + } +- +- old += note_size; + } + +- new_size = new - new_contents; +- memcpy (contents, new_contents, new_size); +- size = new_size; +- free (new_contents); ++ old += note_size; + } + ++#if DEBUG_MERGE ++ merge_debug ("Results of merge:\n"); ++ for (pnote = pnotes; pnote < pnotes_end; pnote ++) ++ if (! is_deleted_note (pnote)) ++ merge_debug ("offset %#08lx range %#08lx..%#08lx type %ld attribute %d namesz %ld\n", ++ (pnote->note.namedata - (char *) contents) - 12, ++ pnote->start, pnote->end, ++ pnote->note.type, ++ pnote->note.namedata[3], ++ pnote->note.namesz ++ ); ++#endif ++ ++ new_size = new - new_contents; ++ memcpy (contents, new_contents, new_size); ++ size = new_size; ++ free (new_contents); ++ + done: + if (err) + { +@@ -2784,52 +2859,61 @@ copy_object (bfd *ibfd, bfd *obfd, const + } + } + ++ merged_note_section * merged_note_sections = NULL; + if (merge_notes) + { + /* This palaver is necessary because we must set the output + section size first, before its contents are ready. */ +- osec = bfd_get_section_by_name (ibfd, GNU_BUILD_ATTRS_SECTION_NAME); +- if (osec && is_merged_note_section (ibfd, osec)) ++ for (osec = ibfd->sections; osec != NULL; osec = osec->next) + { +- bfd_size_type size; +- +- size = bfd_get_section_size (osec); ++ if (! is_mergeable_note_section (ibfd, osec)) ++ continue; ++ ++ bfd_size_type size = bfd_section_size (ibfd, osec); + if (size == 0) + { +- bfd_nonfatal_message (NULL, ibfd, osec, _("warning: note section is empty")); +- merge_notes = FALSE; ++ bfd_nonfatal_message (NULL, ibfd, osec, ++ _("warning: note section is empty")); ++ continue; + } +- else if (! bfd_get_full_section_contents (ibfd, osec, & merged_notes)) ++ ++ merged_note_section * merged = xmalloc (sizeof * merged); ++ merged->contents = NULL; ++ if (! bfd_get_full_section_contents (ibfd, osec, & merged->contents)) + { +- bfd_nonfatal_message (NULL, ibfd, osec, _("warning: could not load note section")); +- free (merged_notes); +- merged_notes = NULL; +- merge_notes = FALSE; ++ bfd_nonfatal_message (NULL, ibfd, osec, ++ _("warning: could not load note section")); ++ free (merged->contents); ++ free (merged); ++ continue; + } +- else ++ ++ merged->size = merge_gnu_build_notes (ibfd, osec, size, ++ merged->contents); ++ if (merged->size == size) ++ { ++ /* Merging achieves nothing. */ ++ merge_debug ("Merge of section %s achieved nothing - skipping\n", ++ bfd_section_name (obfd, osec)); ++ free (merged->contents); ++ free (merged); ++ continue; ++ } ++ ++ if (osec->output_section == NULL ++ || !bfd_set_section_size (obfd, osec->output_section, merged->size)) + { +- merged_size = merge_gnu_build_notes (ibfd, osec, size, merged_notes); +- if (merged_size == size) +- { +- /* Merging achieves nothing. */ +- free (merged_notes); +- merged_notes = NULL; +- merge_notes = FALSE; +- merged_size = 0; +- } +- else +- { +- if (osec->output_section == NULL +- || ! bfd_set_section_size (obfd, osec->output_section, merged_size)) +- { +- bfd_nonfatal_message (NULL, obfd, osec, _("warning: failed to set merged notes size")); +- free (merged_notes); +- merged_notes = NULL; +- merge_notes = FALSE; +- merged_size = 0; +- } +- } ++ bfd_nonfatal_message (NULL, obfd, osec, ++ _("warning: failed to set merged notes size")); ++ free (merged->contents); ++ free (merged); ++ continue; + } ++ ++ /* Add section to list of merged sections. */ ++ merged->sec = osec; ++ merged->next = merged_note_sections; ++ merged_note_sections = merged; + } + } + +@@ -3155,23 +3239,72 @@ copy_object (bfd *ibfd, bfd *obfd, const + } + } + +- if (merge_notes) ++ if (merged_note_sections != NULL) + { +- osec = bfd_get_section_by_name (obfd, GNU_BUILD_ATTRS_SECTION_NAME); +- if (osec && is_merged_note_section (obfd, osec)) ++ merged_note_section * merged = NULL; ++ ++ for (osec = obfd->sections; osec != NULL; osec = osec->next) + { +- if (! bfd_set_section_contents (obfd, osec, merged_notes, 0, merged_size)) ++ if (! is_mergeable_note_section (obfd, osec)) ++ continue; ++ ++ if (merged == NULL) ++ merged = merged_note_sections; ++ ++ /* It is likely that output sections are in the same order ++ as the input sections, but do not assume that this is ++ the case. */ ++ if (strcmp (bfd_section_name (obfd, merged->sec), ++ bfd_section_name (obfd, osec)) != 0) ++ { ++ for (merged = merged_note_sections; ++ merged != NULL; ++ merged = merged->next) ++ if (strcmp (bfd_section_name (obfd, merged->sec), ++ bfd_section_name (obfd, osec)) == 0) ++ break; ++ ++ if (merged == NULL) ++ { ++ bfd_nonfatal_message ++ (NULL, obfd, osec, ++ _("error: failed to copy merged notes into output")); ++ continue; ++ } ++ } ++ ++ if (! is_mergeable_note_section (obfd, osec)) ++ { ++ bfd_nonfatal_message ++ (NULL, obfd, osec, ++ _("error: failed to copy merged notes into output")); ++ continue; ++ } ++ ++ if (! bfd_set_section_contents (obfd, osec, merged->contents, 0, ++ merged->size)) + { +- bfd_nonfatal_message (NULL, obfd, osec, _("error: failed to copy merged notes into output")); ++ bfd_nonfatal_message ++ (NULL, obfd, osec, ++ _("error: failed to copy merged notes into output")); + return FALSE; + } ++ ++ merged = merged->next; ++ } ++ ++ /* Free the memory. */ ++ merged_note_section * next; ++ for (merged = merged_note_sections; merged != NULL; merged = next) ++ { ++ next = merged->next; ++ free (merged->contents); ++ free (merged); + } +- else if (! is_strip) +- bfd_nonfatal_message (NULL, obfd, osec, _("could not find any mergeable note sections")); +- free (merged_notes); +- merged_notes = NULL; +- merge_notes = FALSE; + } ++ else if (merge_notes && ! is_strip) ++ non_fatal (_("%s: Could not find any mergeable note sections"), ++ bfd_get_filename (ibfd)); + + if (gnu_debuglink_filename != NULL) + { +@@ -3962,7 +4095,7 @@ skip_section (bfd *ibfd, sec_ptr isectio + + /* When merging a note section we skip the copying of the contents, + but not the copying of the relocs associated with the contents. */ +- if (skip_copy && is_merged_note_section (ibfd, isection)) ++ if (skip_copy && is_mergeable_note_section (ibfd, isection)) + return TRUE; + + flags = bfd_get_section_flags (ibfd, isection); +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-32.d binutils-2.33.1/binutils/testsuite/binutils-all/note-2-32.d +--- binutils.orig/binutils/testsuite/binutils-all/note-2-32.d 2019-10-28 11:01:40.448071260 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-2-32.d 2019-10-28 11:01:52.413985684 +0000 +@@ -6,12 +6,11 @@ + + #... + [ ]+Owner[ ]+Data size[ ]+Description +-[ ]+\$1[ ]+0x00000004[ ]+OPEN[ ]+Applies to region from 0x100 \(note1.s\) +-[ ]+\$gcc 7.0.1[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\+true[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\*static[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\*0x0[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\$1[ ]+0x00000004[ ]+OPEN[ ]+Applies to region from 0x104 \(note2.s\) +-[ ]+!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x104 +-[ ]+\*pic[ ]+0x00000004[ ]+func[ ]+Applies to region from 0x104 \(func1\) ++[ ]+GA\$3p1[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 to 0x10b \(note1.s\) ++[ ]+GA\$gcc 7.0.1[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x10b ++[ ]+GA\*0x0[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 to 0x108 \(note1.s\) ++[ ]+GA\+true[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 to 0x104 \(note1.s\) ++[ ]+GA\*static[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x104 ++[ ]+GA!false[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x104 to 0x108 \(note2.s\) ++[ ]+GA\*pic[ ]+0x00000008[ ]+func[ ]+Applies to region from 0x104 to 0x106 \(func1\) + #... +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-32.s binutils-2.33.1/binutils/testsuite/binutils-all/note-2-32.s +--- binutils.orig/binutils/testsuite/binutils-all/note-2-32.s 2019-10-28 11:01:40.454071217 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-2-32.s 2019-10-28 11:01:52.413985684 +0000 +@@ -6,32 +6,37 @@ note1.s: + + .pushsection .gnu.build.attributes, "0x100000", %note + .balign 4 +- .dc.l 4 +- .dc.l 4 ++ .dc.l 8 ++ .dc.l 8 + .dc.l 0x100 +- .asciz "$1" ++ .asciz "GA$3p1" + .dc.l 0x100 ++ .dc.l 0x104 + +- .dc.l 12 ++ .dc.l 14 + .dc.l 0 + .dc.l 0x100 +- .asciz "$gcc 7.0.1" ++ .asciz "GA$gcc 7.0.1" ++ .dc.b 0,0 + +- .dc.l 3 ++ .dc.l 5 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2b, 0x2, 0 +- .dc.b 0 ++ .dc.b 0x47, 0x41, 0x2b, 0x2, 0 ++ .dc.b 0,0,0 + +- .dc.l 4 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2a, 0x7, 0, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0, 0 ++ .dc.b 0,0 + +- .dc.l 4 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2a, 0x6, 0, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0 ++ .dc.b 0,0 ++ + .popsection + + +@@ -42,33 +47,38 @@ func1: + .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note +- .dc.l 4 +- .dc.l 4 ++ .dc.l 8 ++ .dc.l 8 + .dc.l 0x100 +- .asciz "$1" ++ .asciz "GA$3p1" + .dc.l 0x104 +- +- .dc.l 12 ++ .dc.l 0x108 ++ ++ .dc.l 14 + .dc.l 0 + .dc.l 0x100 +- .asciz "$gcc 7.0.1" ++ .asciz "GA$gcc 7.0.1" ++ .dc.b 0,0 + +- .dc.l 3 ++ .dc.l 5 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x21, 0x2, 0 +- .dc.b 0 ++ .dc.b 0x47, 0x41, 0x21, 0x2, 0 ++ .dc.b 0,0,0 + +- .dc.l 4 +- .dc.l 4 ++ .dc.l 6 ++ .dc.l 8 + .dc.l 0x101 +- .dc.b 0x2a, 0x7, 1, 0 +- .dc.l 0x104 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 1, 0 ++ .dc.b 0,0 ++ .dc.l 0x104 ++ .dc.l 0x106 + +- .dc.l 4 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2a, 0x6, 0, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0 ++ .dc.b 0,0 + .popsection + + +@@ -77,16 +87,18 @@ note3.s: + .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note +- .dc.l 4 +- .dc.l 4 ++ .dc.l 8 ++ .dc.l 8 + .dc.l 0x100 +- .asciz "$1" ++ .asciz "GA$3p1" + .dc.l 0x108 ++ .dc.l 0x10b + +- .dc.l 12 ++ .dc.l 14 + .dc.l 0 + .dc.l 0x100 +- .asciz "$gcc 7.0.1" ++ .asciz "GA$gcc 7.0.1" ++ .dc.b 0,0 + + .popsection + +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-64.d binutils-2.33.1/binutils/testsuite/binutils-all/note-2-64.d +--- binutils.orig/binutils/testsuite/binutils-all/note-2-64.d 2019-10-28 11:01:40.449071253 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-2-64.d 2019-10-28 11:01:52.414985677 +0000 +@@ -10,12 +10,11 @@ + + #... + [ ]+Owner[ ]+Data size[ ]+Description +-[ ]+\$1[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 \(note1.s\) +-[ ]+\$gcc 7.0.1[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\+true[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\*static[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\*0x0[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 +-[ ]+\$1[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x104 \(note2.s\) +-[ ]+!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x104 +-[ ]+\*pic[ ]+0x00000008[ ]+func[ ]+Applies to region from 0x104 \(func1\) ++[ ]+GA\$3p1[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x10b \(note1.s\) ++[ ]+GA\$gcc 7.0.1[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x10b ++[ ]+GA\*0x0[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x108 \(note1.s\) ++[ ]+GA\+true[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x104 \(note1.s\) ++[ ]+GA\*static[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x104 ++[ ]+GA!false[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x104 to 0x108 \(note2.s\) ++[ ]+GA\*pic[ ]+0x00000010[ ]+func[ ]+Applies to region from 0x104 to 0x106 \(func1\) + #... +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-2-64.s binutils-2.33.1/binutils/testsuite/binutils-all/note-2-64.s +--- binutils.orig/binutils/testsuite/binutils-all/note-2-64.s 2019-10-28 11:01:40.452071232 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-2-64.s 2019-10-28 11:01:52.414985677 +0000 +@@ -6,32 +6,43 @@ note1.s: + + .pushsection .gnu.build.attributes, "0x100000", %note + .balign 4 +- .dc.l 4 + .dc.l 8 ++ .dc.l 16 + .dc.l 0x100 +- .asciz "$1" ++ .asciz "GA$3p1" + .8byte 0x100 ++ .8byte 0x104 + +- .dc.l 12 ++ .dc.l 14 + .dc.l 0 + .dc.l 0x100 +- .asciz "$gcc 7.0.1" ++ .asciz "GA$gcc 7.0.1" ++ .dc.b 0,0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2b, 0x2, 0 ++ .dc.b 0,0,0 + +- .dc.l 3 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2b, 0x2, 0 +- .dc.b 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0, 0 ++ .dc.b 0,0 + +- .dc.l 4 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2a, 0x7, 0, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0 ++ .dc.b 0,0 + +- .dc.l 4 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2a, 0x6, 0, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0, 0 ++ .dc.b 0,0 ++ + .popsection + + +@@ -43,33 +54,38 @@ func1: + .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note +- .dc.l 4 +- .dc.l 8 ++ .dc.l 8 ++ .dc.l 16 + .dc.l 0x100 +- .asciz "$1" ++ .asciz "GA$3p1" + .8byte 0x104 ++ .8byte 0x108 + +- .dc.l 12 ++ .dc.l 14 + .dc.l 0 + .dc.l 0x100 +- .asciz "$gcc 7.0.1" +- +- .dc.l 3 ++ .asciz "GA$gcc 7.0.1" ++ .dc.b 0,0 ++ ++ .dc.l 5 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x21, 0x2, 0 +- .dc.b 0 ++ .dc.b 0x47, 0x41, 0x21, 0x2, 0 ++ .dc.b 0,0,7 + +- .dc.l 4 +- .dc.l 8 ++ .dc.l 6 ++ .dc.l 16 + .dc.l 0x101 +- .dc.b 0x2a, 0x7, 1, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 1, 0 ++ .dc.b 0,0 + .8byte 0x104 ++ .8byte 0x106 + +- .dc.l 4 ++ .dc.l 6 + .dc.l 0 + .dc.l 0x100 +- .dc.b 0x2a, 0x6, 0, 0 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0, 0 ++ .dc.b 0,0 + .popsection + + +@@ -78,15 +94,17 @@ note3.s: + .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note +- .dc.l 4 +- .dc.l 8 ++ .dc.l 8 ++ .dc.l 16 + .dc.l 0x100 +- .asciz "$1" ++ .asciz "GA$3p1" + .8byte 0x108 ++ .8byte 0x10b + +- .dc.l 12 ++ .dc.l 14 + .dc.l 0 + .dc.l 0x100 +- .asciz "$gcc 7.0.1" ++ .asciz "GA$gcc 7.0.1" ++ .dc.b 0,0 + + .popsection +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-32.d binutils-2.33.1/binutils/testsuite/binutils-all/note-3-32.d +--- binutils.orig/binutils/testsuite/binutils-all/note-3-32.d 2019-10-28 11:01:40.456071203 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-3-32.d 2019-10-28 11:01:52.414985677 +0000 +@@ -7,12 +7,12 @@ + #... + Displaying notes found in: .gnu.build.attributes + [ ]+Owner[ ]+Data size[ ]+Description +-[ ]+GA\$2p1[ ]+0x0000000.[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 \(note_1.s\) +-[ ]+GA\$gcc 6.3.1 20161221[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 +-[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\$3p1[ ]+0x0000000.[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 \(note_1.s\) + [ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 +-[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\$gcc 6.3.1 20161221[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 + [ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 + [ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 +-[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 + #... +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-32.s binutils-2.33.1/binutils/testsuite/binutils-all/note-3-32.s +--- binutils.orig/binutils/testsuite/binutils-all/note-3-32.s 2019-10-28 11:01:40.451071238 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-3-32.s 2019-10-28 11:01:52.414985677 +0000 +@@ -9,10 +9,11 @@ note_1.s: + .balign 4 + + .dc.l 8 +- .dc.l 4 ++ .dc.l 8 + .dc.l 0x100 +- .asciz "GA$2p1" +- .dc.l note_1.s ++ .asciz "GA$3p1" ++ .dc.l 0x100 /* note_1.s */ ++ .dc.l 0x122 /* note_1.s end */ + + .dc.l 23 + .dc.l 0 +@@ -55,4 +56,12 @@ note_1.s: + .dc.l 0x100 + .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 + .dc.b 0, 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ + .popsection +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-64.d binutils-2.33.1/binutils/testsuite/binutils-all/note-3-64.d +--- binutils.orig/binutils/testsuite/binutils-all/note-3-64.d 2019-10-28 11:01:40.452071232 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-3-64.d 2019-10-28 11:01:52.414985677 +0000 +@@ -7,12 +7,12 @@ + #... + Displaying notes found in: .gnu.build.attributes + [ ]+Owner[ ]+Data size[ ]+Description +-[ ]+GA\$2p1[ ]+0x0000000.[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 \(note_1.s\) +-[ ]+GA\$gcc 6.3.1 20161221[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 +-[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\$3p1[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 \(note_1.s\) + [ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 +-[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\$gcc 6.3.1 20161221[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 + [ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 + [ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 +-[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x122 + #... +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-3-64.s binutils-2.33.1/binutils/testsuite/binutils-all/note-3-64.s +--- binutils.orig/binutils/testsuite/binutils-all/note-3-64.s 2019-10-28 11:01:40.450071246 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-3-64.s 2019-10-28 11:01:52.414985677 +0000 +@@ -9,10 +9,11 @@ note_1.s: + .balign 4 + + .dc.l 8 +- .dc.l 8 ++ .dc.l 16 + .dc.l 0x100 +- .asciz "GA$2p1" +- .8byte note_1.s ++ .asciz "GA$3p1" ++ .8byte 0x100 /* note_1.s */ ++ .8byte 0x122 /* note_1 end */ + + .dc.l 23 + .dc.l 0 +@@ -55,4 +56,11 @@ note_1.s: + .dc.l 0x100 + .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 + .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ + .popsection +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-32.d binutils-2.33.1/binutils/testsuite/binutils-all/note-4-32.d +--- binutils.orig/binutils/testsuite/binutils-all/note-4-32.d 2019-10-28 11:01:40.453071224 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-4-32.d 2019-10-28 11:01:52.414985677 +0000 +@@ -8,12 +8,12 @@ + Displaying notes found in: .gnu.build.attributes + [ ]+Owner[ ]+Data size[ ]+Description + [ ]+GA\$3p3[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 \(note_4.s\) +-[ ]+GA\$gcc 7.2.1 20170915[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 +-[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 + [ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 +-[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 ++[ ]+GA\$gcc 7.2.1 20170915[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 + [ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 + [ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 +-[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x10. to 0x110 + [ ]+GA\*strong[ ]+0x00000008[ ]+func[ ]+Applies to region from 0x10. to 0x10c.* + #... +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-32.s binutils-2.33.1/binutils/testsuite/binutils-all/note-4-32.s +--- binutils.orig/binutils/testsuite/binutils-all/note-4-32.s 2019-10-28 11:01:40.448071260 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-4-32.s 2019-10-28 11:01:52.414985677 +0000 +@@ -18,8 +18,8 @@ note_4.s_end: + .dc.l 8 + .dc.l 0x100 + .asciz "GA$3p3" +- .dc.l note_4.s - 2 +- .dc.l note_4.s_end ++ .dc.l 0x100 /* note_4.s - 2 */ ++ .dc.l 0x110 /* note_4.s_end */ + + .dc.l 23 + .dc.l 0 +@@ -63,12 +63,18 @@ note_4.s_end: + .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 + .dc.b 0, 0, 0 + ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ + .dc.l 6 + .dc.l 8 + .dc.l 0x101 + .dc.b 0x47, 0x41, 0x2a, 0x2, 0x3, 0 + .dc.b 0, 0 +- .dc.l bar +- .dc.l bar_end ++ .dc.l 0x108 /* bar */ ++ .dc.l 0x10c /* bar_end */ + + .popsection +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-64.d binutils-2.33.1/binutils/testsuite/binutils-all/note-4-64.d +--- binutils.orig/binutils/testsuite/binutils-all/note-4-64.d 2019-10-28 11:01:40.448071260 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-4-64.d 2019-10-28 11:01:52.414985677 +0000 +@@ -8,12 +8,12 @@ + Displaying notes found in: .gnu.build.attributes + [ ]+Owner[ ]+Data size[ ]+Description + [ ]+GA\$3p3[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 \(note_4.s\) +-[ ]+GA\$gcc 7.2.1 20170915[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 +-[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 + [ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 +-[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\$gcc 7.2.1 20170915[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 + [ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 + [ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 +-[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 +-[ ]+GA\*strong[ ]+0x00000010[ ]+func[ ]+Applies to region from 0x110 to 0x11c.* ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*strong[ ]+0x00000010[ ]+func[ ]+Applies to region from 0x110 to 0x120.* + #... +diff -rupN binutils.orig/binutils/testsuite/binutils-all/note-4-64.s binutils-2.33.1/binutils/testsuite/binutils-all/note-4-64.s +--- binutils.orig/binutils/testsuite/binutils-all/note-4-64.s 2019-10-28 11:01:40.447071267 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/note-4-64.s 2019-10-28 11:01:52.421985627 +0000 +@@ -22,8 +22,8 @@ note_4.s_end: + .dc.l 16 + .dc.l 0x100 + .asciz "GA$3p3" +- .8byte note_4.s - 2 +- .8byte note_4.s_end ++ .8byte 0x100 /* note_4.s - 2 */ ++ .8byte 0x120 /* note_4.s_end */ + + .dc.l 23 + .dc.l 0 +@@ -68,11 +68,17 @@ note_4.s_end: + .dc.b 0, 0, 0 + + .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 + .dc.l 16 + .dc.l 0x101 + .dc.b 0x47, 0x41, 0x2a, 0x2, 0x3, 0 + .dc.b 0, 0 +- .8byte bar +- .8byte bar_end ++ .8byte 0x110 /* bar */ ++ .8byte 0x120 /* bar_end */ + + .popsection +diff -rupN binutils.orig/binutils/testsuite/binutils-all/objcopy.exp binutils-2.33.1/binutils/testsuite/binutils-all/objcopy.exp +--- binutils.orig/binutils/testsuite/binutils-all/objcopy.exp 2019-10-28 11:01:40.450071246 +0000 ++++ binutils-2.33.1/binutils/testsuite/binutils-all/objcopy.exp 2019-10-28 11:01:52.421985627 +0000 +@@ -1108,10 +1108,12 @@ if [is_elf_format] { + run_dump_test "note-2-64" + run_dump_test "note-3-64" + run_dump_test "note-4-64" ++ run_dump_test "note-6-64" + } else { + run_dump_test "note-2-32" + run_dump_test "note-3-32" + run_dump_test "note-4-32" ++ run_dump_test "note-6-32" + } + run_dump_test "note-5" + } +--- /dev/null 2019-10-25 08:17:39.968055193 +0100 ++++ fred/binutils/testsuite/binutils-all/note-6-32.s 2019-10-25 14:35:54.248969792 +0100 +@@ -0,0 +1,145 @@ ++ .text ++ .org 0x100 ++ .global note_test ++note_test: ++note_1_start: ++ .word 0 ++note_1_end: ++note_2_start: ++ .word 0 ++note_2_end: ++note_3_start: ++ .word 0 ++note_3_end: ++note_test_end: ++ .size note_test, note_test_end - note_test ++ ++ .pushsection .gnu.build.attributes, "", %note ++ .balign 4 ++ ++ .dc.l 8 ++ .dc.l 8 ++ .dc.l 0x100 ++ .asciz "GA$3p1" ++ .4byte 0x100 /* note_1_start */ ++ .4byte 0x102 /* note_1_end */ ++ ++ .dc.l 23 ++ .dc.l 0 ++ .dc.l 0x100 ++ .asciz "GA$gcc 8.3.1 20190507" ++ .dc.b 0 ++ ++ .dc.l 10 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 ++ .dc.b 0, 0, 0 ++ ++ ++ .dc.l 8 ++ .dc.l 8 ++ .dc.l 0x100 ++ .asciz "GA$3p1" ++ .4byte 0x102 /* note_2_start */ ++ .4byte 0x106 /* note_3_end */ ++ ++ .dc.l 23 ++ .dc.l 0 ++ .dc.l 0x100 ++ .asciz "GA$gcc 8.3.1 20190507" ++ .dc.b 0 ++ ++ .dc.l 10 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 ++ .dc.b 0, 0, 0 ++ ++ ++ .dc.l 8 ++ .dc.l 8 ++ .dc.l 0x101 ++ .asciz "GA$3p1" ++ .4byte 0x102 /* note_2_start */ ++ .4byte 0x104 /* note_2_end */ ++ ++ .dc.l 16 ++ .dc.l 0 ++ .dc.l 0x101 ++ .asciz "GA$hello world" ++ ++ ++ .dc.l 8 ++ .dc.l 8 ++ .dc.l 0x101 ++ .asciz "GA$3p1" ++ .4byte 0x104 /* note_3_start */ ++ .4byte 0x106 /* note_3_end */ ++ ++ .dc.l 16 ++ .dc.l 0 ++ .dc.l 0x101 ++ .asciz "GA$hello world" ++ ++ .popsection +--- /dev/null 2019-10-25 08:17:39.968055193 +0100 ++++ fred/binutils/testsuite/binutils-all/note-6-32.d 2019-10-25 14:37:59.481089241 +0100 +@@ -0,0 +1,20 @@ ++#PROG: objcopy ++#readelf: --notes --wide ++#objcopy: --merge-notes ++#name: v3 gnu build attribute note merging (32-bit) ++#source: note-6-32.s ++ ++#... ++Displaying notes found in: .gnu.build.attributes ++[ ]+Owner[ ]+Data size[ ]+Description ++[ ]+GA\$3p1[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 \(note_test\) ++[ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\$gcc 8.3.1 20190507[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\$3p1[ ]+0x00000008[ ]+func[ ]+Applies to region from 0x102 to 0x106 ++[ ]+GA\$hello world[ ]+0x00000000[ ]+func[ ]+Applies to region from 0x102 to 0x106 ++#... +--- /dev/null 2019-10-25 08:17:39.968055193 +0100 ++++ fred/binutils/testsuite/binutils-all/note-6-64.d 2019-10-25 13:50:10.733181842 +0100 +@@ -0,0 +1,20 @@ ++#PROG: objcopy ++#readelf: --notes --wide ++#objcopy: --merge-notes ++#name: v3 gnu build attribute note merging (64-bit) ++#source: note-6-64.s ++ ++#... ++Displaying notes found in: .gnu.build.attributes ++[ ]+Owner[ ]+Data size[ ]+Description ++[ ]+GA\$3p1[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 \(note_test\) ++[ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\$gcc 8.3.1 20190507[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x106 ++[ ]+GA\$3p1[ ]+0x00000010[ ]+func[ ]+Applies to region from 0x102 to 0x106 ++[ ]+GA\$hello world[ ]+0x00000000[ ]+func[ ]+Applies to region from 0x102 to 0x106 ++#... +--- /dev/null 2019-10-25 08:17:39.968055193 +0100 ++++ fred/binutils/testsuite/binutils-all/note-6-64.s 2019-10-25 14:36:31.670706667 +0100 +@@ -0,0 +1,145 @@ ++ .text ++ .org 0x100 ++ .global note_test ++note_test: ++note_1_start: ++ .word 0 ++note_1_end: ++note_2_start: ++ .word 0 ++note_2_end: ++note_3_start: ++ .word 0 ++note_3_end: ++note_test_end: ++ .size note_test, note_test_end - note_test ++ ++ .pushsection .gnu.build.attributes, "", %note ++ .balign 4 ++ ++ .dc.l 8 ++ .dc.l 16 ++ .dc.l 0x100 ++ .asciz "GA$3p1" ++ .8byte 0x100 /* note_1_start */ ++ .8byte 0x102 /* note_1_end */ ++ ++ .dc.l 23 ++ .dc.l 0 ++ .dc.l 0x100 ++ .asciz "GA$gcc 8.3.1 20190507" ++ .dc.b 0 ++ ++ .dc.l 10 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 ++ .dc.b 0, 0, 0 ++ ++ ++ .dc.l 8 ++ .dc.l 16 ++ .dc.l 0x100 ++ .asciz "GA$3p1" ++ .8byte 0x102 /* note_2_start */ ++ .8byte 0x106 /* note_3_end */ ++ ++ .dc.l 23 ++ .dc.l 0 ++ .dc.l 0x100 ++ .asciz "GA$gcc 8.3.1 20190507" ++ .dc.b 0 ++ ++ .dc.l 10 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 ++ .dc.b 0, 0, 0 ++ ++ ++ .dc.l 8 ++ .dc.l 16 ++ .dc.l 0x101 ++ .asciz "GA$3p1" ++ .8byte 0x102 /* note_2_start */ ++ .8byte 0x104 /* note_2_end */ ++ ++ .dc.l 16 ++ .dc.l 0 ++ .dc.l 0x101 ++ .asciz "GA$hello world" ++ ++ ++ .dc.l 8 ++ .dc.l 16 ++ .dc.l 0x101 ++ .asciz "GA$3p1" ++ .8byte 0x104 /* note_3_start */ ++ .8byte 0x106 /* note_3_end */ ++ ++ .dc.l 16 ++ .dc.l 0 ++ .dc.l 0x101 ++ .asciz "GA$hello world" ++ ++ .popsection +--- binutils.orig/binutils/objcopy.c 2019-11-05 12:01:47.440187230 +0000 ++++ binutils-2.33.1/binutils/objcopy.c 2019-11-05 12:02:51.346706812 +0000 +@@ -2526,7 +2526,7 @@ merge_gnu_build_notes (bfd * ab + { + bfd_set_error (bfd_error_bad_value); + bfd_nonfatal_message (NULL, abfd, sec, err); +- status = 1; ++ /* status = 1; */ + } + + free (pnotes); +--- binutils.orig/binutils/objcopy.c 2019-11-06 21:57:19.772862679 +0000 ++++ binutils-2.33.1/binutils/objcopy.c 2019-11-06 22:00:00.206626724 +0000 +@@ -2869,6 +2869,11 @@ copy_object (bfd *ibfd, bfd *obfd, const + if (! is_mergeable_note_section (ibfd, osec)) + continue; + ++ /* If the section is going to be completly deleted then ++ do not bother to merge it. */ ++ if (osec->output_section == NULL) ++ continue; ++ + bfd_size_type size = bfd_section_size (ibfd, osec); + if (size == 0) + { +@@ -2883,25 +2888,19 @@ copy_object (bfd *ibfd, bfd *obfd, const + { + bfd_nonfatal_message (NULL, ibfd, osec, + _("warning: could not load note section")); +- free (merged->contents); + free (merged); + continue; + } + + merged->size = merge_gnu_build_notes (ibfd, osec, size, + merged->contents); +- if (merged->size == size) +- { +- /* Merging achieves nothing. */ +- merge_debug ("Merge of section %s achieved nothing - skipping\n", +- bfd_section_name (obfd, osec)); +- free (merged->contents); +- free (merged); +- continue; +- } + +- if (osec->output_section == NULL +- || !bfd_set_section_size (obfd, osec->output_section, merged->size)) ++ /* FIXME: Once we have read the contents in, we must write ++ them out again. So even if the mergeing has achieved ++ nothing we still add this entry to the merge list. */ ++ ++ if (size != merged->size ++ && !bfd_set_section_size (obfd, osec->output_section, merged->size)) + { + bfd_nonfatal_message (NULL, obfd, osec, + _("warning: failed to set merged notes size")); +@@ -3268,16 +3267,16 @@ copy_object (bfd *ibfd, bfd *obfd, const + { + bfd_nonfatal_message + (NULL, obfd, osec, +- _("error: failed to copy merged notes into output")); ++ _("error: failed to locate merged notes")); + continue; + } + } + +- if (! is_mergeable_note_section (obfd, osec)) ++ if (merged->contents == NULL) + { + bfd_nonfatal_message + (NULL, obfd, osec, +- _("error: failed to copy merged notes into output")); ++ _("error: failed to merge notes")); + continue; + } + +--- binutils.orig/binutils/objcopy.c 2019-11-20 16:49:37.481749288 +0000 ++++ binutils-2.33.1/binutils/objcopy.c 2019-11-20 16:50:25.294371622 +0000 +@@ -2450,7 +2450,9 @@ merge_gnu_build_notes (bfd * ab + bfd_vma prev_start = 0; + bfd_vma prev_end = 0; + +- new = new_contents = xmalloc (size); ++ /* Not sure how, but the notes might grow in size. ++ (eg see PR 1774507). Allow for this here. */ ++ new = new_contents = xmalloc (size * 2); + for (pnote = pnotes, old = contents; + pnote < pnotes_end; + pnote ++) +@@ -2517,8 +2519,11 @@ merge_gnu_build_notes (bfd * ab + #endif + + new_size = new - new_contents; +- memcpy (contents, new_contents, new_size); +- size = new_size; ++ if (new_size < size) ++ { ++ memcpy (contents, new_contents, new_size); ++ size = new_size; ++ } + free (new_contents); + + done: diff --git a/cross-binutils.spec b/cross-binutils.spec index 5ccd383..1d2bdbe 100644 --- a/cross-binutils.spec +++ b/cross-binutils.spec @@ -65,7 +65,7 @@ Summary: A GNU collection of cross-compilation binary utilities Name: %{cross}-binutils Version: 2.33.1 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv3+ URL: https://sourceware.org/binutils @@ -172,6 +172,24 @@ Patch14: binutils-gold-mismatched-section-flags.patch # Lifetime: Fixed in 2.34 (maybe) Patch15: binutils-CVE-2019-1010204.patch +# Purpose: Improve objdump's ability to merge GNU build attribute notes. +# Lifetime: Fixed in 2.34 +Patch16: binutils-improved-note-merging.patch + +# Purpose: Fix a potential seg-fault in the BFD library when parsing +# pathalogical debug_info sections. +# Lifetime: Fixed in 2.34 +Patch17: binutils-CVE-2019-17451.patch + +# Purpose: Fix a memory exhaustion bug in the BFD library when parsing +# corrupt DWARF debug information. +# Lifetime: Fixed in 2.34 +Patch18: binutils-CVE-2019-17450.patch + +# Purpose: Improve addr2line's ability to translate addresses into file/line numbers. +# Lifetime: Fixed in 2.34 +Patch19: binutils-addr2line-fixes.patch + #---------------------------------------------------------------------------- BuildRequires: texinfo >= 4.0, gettext, flex, bison, zlib-devel @@ -762,6 +780,9 @@ cd - %do_files xtensa-linux-gnu %{build_xtensa} %changelog +* Mon Jan 06 2020 Peter Robinson - 2.33.1-2 +- sync with binutils 2.33.1-11 + * Tue Oct 15 2019 Peter Robinson 2.33.1-1 - Sync with binutils-2.33.1-1