From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2124) id E45CE382F0AD; Tue, 30 Aug 2022 15:02:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E45CE382F0AD Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nick Clifton To: bfd-cvs@sourceware.org Subject: [binutils-gdb] BFD library: Use entry 0 in directory and filename tables of DWARF-5 debug info. X-Act-Checkin: binutils-gdb X-Git-Author: Nick Clifton X-Git-Refname: refs/heads/master X-Git-Oldrev: f79688953fb09dbe5c0ecf33a8db15054d49fb8d X-Git-Newrev: 37833b966576c5d25e797ea3b6c33d0459a71892 Message-Id: <20220830150216.E45CE382F0AD@sourceware.org> Date: Tue, 30 Aug 2022 15:02:16 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Aug 2022 15:02:17 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D37833b966576= c5d25e797ea3b6c33d0459a71892 commit 37833b966576c5d25e797ea3b6c33d0459a71892 Author: Nick Clifton Date: Tue Aug 30 16:01:20 2022 +0100 BFD library: Use entry 0 in directory and filename tables of DWARF-5 de= bug info. =20 PR 29529 * dwarf2.c (struct line_info_table): Add new field: use_dir_and_file_0. (concat_filename): Use new field to help select the correct tab= le slot. (read_formatted_entries): Do not skip entry 0. (decode_line_info): Set new field depending upon the version of DWARF being parsed. Initialise filename based upon the setting= of the new field. Diff: --- bfd/ChangeLog | 12 ++++++ bfd/dwarf2.c | 86 +++++++++++++++++++++++++---------= ---- ld/ChangeLog | 5 +++ ld/testsuite/ld-x86-64/pr27587.err | 2 +- 4 files changed, 76 insertions(+), 29 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 88643b8a036..f5a03c7e7f5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2022-08-30 Nick Clifton + + PR 29529 + * dwarf2.c (struct line_info_table): Add new field: + use_dir_and_file_0. + (concat_filename): Use new field to help select the correct table + slot. + (read_formatted_entries): Do not skip entry 0. + (decode_line_info): Set new field depending upon the version of + DWARF being parsed. Initialise filename based upon the setting of + the new field. + 2022-08-22 Frederic Cambus =20 * config.bfd (aarch64-*-openbsd*): Add target. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 6e5d40b8241..c513ef180bc 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -1779,6 +1779,7 @@ struct line_info_table unsigned int num_files; unsigned int num_dirs; unsigned int num_sequences; + bool use_dir_and_file_0; char * comp_dir; char ** dirs; struct fileinfo* files; @@ -1999,16 +2000,30 @@ concat_filename (struct line_info_table *table, uns= igned int file) { char *filename; =20 - if (table =3D=3D NULL || file - 1 >=3D table->num_files) + /* Pre DWARF-5 entry 0 in the directory and filename tables was not used. + So in order to save space in the tables used here the info for, eg + directory 1 is stored in slot 0 of the directory table, directory 2 + in slot 1 and so on. + + Starting with DWARF-5 the 0'th entry is used so there is a one to one + mapping between DWARF slots and internal table entries. */ + if (! table->use_dir_and_file_0) { - /* FILE =3D=3D 0 means unknown. */ - if (file) - _bfd_error_handler - (_("DWARF error: mangled line number section (bad file number)")); + /* Pre DWARF-5, FILE =3D=3D 0 means unknown. */ + if (file =3D=3D 0) + return strdup (""); + -- file; + } + + if (table =3D=3D NULL || file >=3D table->num_files) + { + _bfd_error_handler + (_("DWARF error: mangled line number section (bad file number)")); return strdup (""); } =20 - filename =3D table->files[file - 1].name; + filename =3D table->files[file].name; + if (filename =3D=3D NULL) return strdup (""); =20 @@ -2019,12 +2034,17 @@ concat_filename (struct line_info_table *table, uns= igned int file) char *name; size_t len; =20 - if (table->files[file - 1].dir + if (table->files[file].dir /* PR 17512: file: 0317e960. */ - && table->files[file - 1].dir <=3D table->num_dirs + && table->files[file].dir <=3D table->num_dirs /* PR 17512: file: 7f3d2e4b. */ && table->dirs !=3D NULL) - subdir_name =3D table->dirs[table->files[file - 1].dir - 1]; + { + if (table->use_dir_and_file_0) + subdir_name =3D table->dirs[table->files[file].dir]; + else + subdir_name =3D table->dirs[table->files[file].dir - 1]; + } =20 if (!subdir_name || !IS_ABSOLUTE_PATH (subdir_name)) dir_name =3D table->comp_dir; @@ -2065,10 +2085,12 @@ concat_filename (struct line_info_table *table, uns= igned int file) =20 /* Check whether [low1, high1) can be combined with [low2, high2), i.e., they touch or overlap. */ -static bool ranges_overlap (bfd_vma low1, - bfd_vma high1, - bfd_vma low2, - bfd_vma high2) + +static bool +ranges_overlap (bfd_vma low1, + bfd_vma high1, + bfd_vma low2, + bfd_vma high2) { if (low1 =3D=3D low2 || high1 =3D=3D high2) return true; @@ -2095,15 +2117,16 @@ static bool ranges_overlap (bfd_vma low1, /* Insert an address range in the trie mapping addresses to compilation un= its. Will return the new trie node (usually the same as is being sent in, but in case of a leaf-to-interior conversion, or expansion of a leaf, it ma= y be - different), or NULL on failure. - */ -static struct trie_node *insert_arange_in_trie(bfd *abfd, - struct trie_node *trie, - bfd_vma trie_pc, - unsigned int trie_pc_bits, - struct comp_unit *unit, - bfd_vma low_pc, - bfd_vma high_pc) + different), or NULL on failure. */ + +static struct trie_node * +insert_arange_in_trie (bfd *abfd, + struct trie_node *trie, + bfd_vma trie_pc, + unsigned int trie_pc_bits, + struct comp_unit *unit, + bfd_vma low_pc, + bfd_vma high_pc) { bfd_vma clamped_low_pc, clamped_high_pc; int ch, from_ch, to_ch; @@ -2241,7 +2264,6 @@ static struct trie_node *insert_arange_in_trie(bfd *a= bfd, return trie; } =20 - static bool arange_add (struct comp_unit *unit, struct arange *first_arange, struct trie_node **trie_root, bfd_vma low_pc, bfd_vma high_pc) @@ -2627,10 +2649,8 @@ read_formatted_entries (struct comp_unit *unit, bfd_= byte **bufp, } } =20 - /* Skip the first "zero entry", which is the compilation dir/file. = */ - if (datai !=3D 0) - if (!callback (table, fe.name, fe.dir, fe.time, fe.size)) - return false; + if (!callback (table, fe.name, fe.dir, fe.time, fe.size)) + return false; } =20 *bufp =3D buf; @@ -2807,6 +2827,7 @@ decode_line_info (struct comp_unit *unit) if (!read_formatted_entries (unit, &line_ptr, line_end, table, line_info_add_file_name)) goto fail; + table->use_dir_and_file_0 =3D true; } else { @@ -2829,6 +2850,7 @@ decode_line_info (struct comp_unit *unit) if (!line_info_add_file_name (table, cur_file, dir, xtime, size)) goto fail; } + table->use_dir_and_file_0 =3D false; } =20 /* Read the statement sequences until there's nothing left. */ @@ -2837,7 +2859,7 @@ decode_line_info (struct comp_unit *unit) /* State machine registers. */ bfd_vma address =3D 0; unsigned char op_index =3D 0; - char * filename =3D table->num_files ? concat_filename (table, 1) : = NULL; + char * filename =3D NULL; unsigned int line =3D 1; unsigned int column =3D 0; unsigned int discriminator =3D 0; @@ -2852,6 +2874,14 @@ decode_line_info (struct comp_unit *unit) bfd_vma low_pc =3D (bfd_vma) -1; bfd_vma high_pc =3D 0; =20 + if (table->num_files) + { + if (table->use_dir_and_file_0) + filename =3D concat_filename (table, 0); + else + filename =3D concat_filename (table, 1); + } + /* Decode the table. */ while (!end_sequence && line_ptr < line_end) { diff --git a/ld/ChangeLog b/ld/ChangeLog index f4fa772cdf0..15cf800a231 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2022-08-30 Nick Clifton + + PR 29529 + * testsuite/ld-x86-64/pr27587.err: Update expected output. + 2022-08-18 Ralf Habacker =20 PR 28362 diff --git a/ld/testsuite/ld-x86-64/pr27587.err b/ld/testsuite/ld-x86-64/pr= 27587.err index fa870790813..807750ca9d3 100644 --- a/ld/testsuite/ld-x86-64/pr27587.err +++ b/ld/testsuite/ld-x86-64/pr27587.err @@ -1,3 +1,3 @@ #... -.*pr27587.i:4: undefined reference to `stack_size' +.*pr27587/:4: undefined reference to `stack_size' #...