From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2044.outbound.protection.outlook.com [40.107.95.44]) by sourceware.org (Postfix) with ESMTPS id D29113858D37 for ; Wed, 20 Jul 2022 05:03:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D29113858D37 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AB0j62tV+JxWXezu6tmdwix58le1hIj9mUN3D0c1RafkxvdPt6F3/ot1oAzFQHQExJt6zGIXuw6hjzZhPNNqYtH4KXos50cXFuco6EHVcopKKaB6Na00DI78nXT6PJ3opyrvqC459zbvV8xPNGpitpwsTxit8xW4uOmSm8CwaQMMU0SzvMElynIRKLUaHAAeenJmKuHAV3SJ+QS6EtmUb/GZHZvn40gV+UHNCnSrJ27xpYFgOBrmnXL//RhFA1Z7ZNEvfQrIMzYrMFm6sZy2BAiv+08DBz6XKigev5+Zx05TBgbkCHHqpZ5vxUGBqsRaSTlYwrl6pVSSf6EP6VHk6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RKWyaJV5VuuZ/Jm1tXk4lwVEk0mKvyINKppNIvTXPOo=; b=Ew3PiWbjLJVTKuOIOEC1HhZLHaOtPUqUZgK1zIsxoVmjHr04ranRTbt+VXlkJD7MG+QMyJdfhpJUVTHEKsJuV3Vov0sVYzFxQMU6fEkKJ0NcdTTs+rpkAjomsgswV0bC9nWUdszkqZgQF9Y3L5GagdKKvibQeRGBF05c6FpVOjITCTi/YPCCqugTjaCbbK5U+0ie5MMAU//i10sKv5QMCVCymhjH34LA36ESHmPeXkY0lp864OIMQD3gsL5lEUWuNR9tBthrCiECLbiSNH2BcenStOy0bZr5bomz9g5Za/l/ohbRGp7sLu/N1mph38M3iVC3pBp1nvQCo4Bl3bGW3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none Received: from DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) by PH7PR12MB6695.namprd12.prod.outlook.com (2603:10b6:510:1b2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.17; Wed, 20 Jul 2022 05:03:47 +0000 Received: from DM6PR12MB4219.namprd12.prod.outlook.com ([fe80::2cc6:6f5e:d686:6764]) by DM6PR12MB4219.namprd12.prod.outlook.com ([fe80::2cc6:6f5e:d686:6764%4]) with mapi id 15.20.5438.023; Wed, 20 Jul 2022 05:03:47 +0000 From: "Potharla, Rupesh" To: "Potharla, Rupesh via Binutils" CC: "Parasuraman, Hariharan" , "George, Jini Susan" , "Natarajan, Kavitha" Subject: RE: [PATCH] bfd: Fix issues with files in debug_line table with dwarf5. Thread-Topic: [PATCH] bfd: Fix issues with files in debug_line table with dwarf5. Thread-Index: AdiQOGk8IeKfK0nGRseSbjql2cGXqQLvXZug Date: Wed, 20 Jul 2022 05:03:46 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Enabled=true; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_SetDate=2022-07-05T06:36:11Z; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Method=Privileged; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Name=Public-AIP 2.0; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_ActionId=5e5d1a1d-6f3d-48b9-a152-4c8a65e16fb1; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_ContentBits=1 msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_enabled: true msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_setdate: 2022-07-20T05:03:42Z msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_method: Privileged msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_name: Public-AIP 2.0 msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_siteid: 3dd8961f-e488-4e60-8e11-a82d994e183d msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_actionid: 9175a758-4e60-4782-ab1c-c3e3b78c97c1 msip_label_d4243a53-6221-4f75-8154-e4b33a5707a1_contentbits: 0 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a733daef-d005-42a0-2ab9-08da6a0d3a31 x-ms-traffictypediagnostic: PH7PR12MB6695:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jE0vEdCgwnRiIEQ0LuFbT8GQsW4lMZo3ybHNyfzGIvL41As5LtIDjDyOYqjCPWIqwLrBBOx+qUvjYKboOP6WensYIngFaXGfcd/dad0rfpjJM2kCZjOIp+/c1IX5rj2hPH8L/zCmwKWLRyhtAKpDviIF3tcSAphzxi5BlmfwHmxUfStHShuE6nJRb8hSKvvI81BDhqYHCcxedQsJGYi01EbLd39bRS2zW6kK5gLc+jwHc+u/fQEZ9wQdAD+NTcRqcinNs0FqvojXqKujbCfAhLFxMgB9tC6AIOL80PbTbWzReaRTpFln4bnVg1SslAdEqYgczFhSYVK5KqpVxx8hjF9Tqhs6k9LyBKystv2p7Ub2uzX3vxFvUoZ2FEfJRR/0J7+IzZpst77tpMcBmj2bII9MP2tflyXi7RTlr+zZd1Y/nXaTcJUDeIAIqyA2OX6DTkWvZDJzAoNfokodqv68mWWNJqmX3G8iesG6O/OaOtO14cS2Ph42HRPBVCKH/29EZV8vMWBvKZaVfcNo1bkC9iYCPyXA/ws+2A8F60b1XPWZk640deinUR8GgY4fTipxpWFO5AgttFUKbcQLCQ3zFO3eDf+Sa3IIPvEIojnG9jD0T5spd4VFOKqK+AgX/Gldkmpph+5o66l8QGihZvcpNWS+yH/fGJgWAbysC6mhBR5Ua/fKn8g41FkazvbdymXVtKXxFny6/dtywfxE2peUeGY21wEjCsIEn4XnxeRS7O7imFVB3GgG8N1qHQOaM9VaF3biA4XRAl283Crg3xfQF3vr7Mojzr/miSHyNM8nBZtEnwq8dfXjr6P2IaFFJRhzyZNrDs5xt1+Dj854pyyDfw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB4219.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(39860400002)(376002)(396003)(346002)(136003)(71200400001)(86362001)(478600001)(6916009)(38070700005)(83380400001)(54906003)(186003)(26005)(316002)(41300700001)(53546011)(2906002)(6506007)(5660300002)(4326008)(7696005)(66556008)(64756008)(66446008)(66476007)(8676002)(8936002)(33656002)(52536014)(76116006)(9686003)(66946007)(38100700002)(55016003)(122000001)(2004002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?HW/TMyx1jLL+CIXJGrJ9RstA7FzCOrmJpGM2TW2CtYcikdTF50A7Ix1U4M/T?= =?us-ascii?Q?kZJseGGYaCKvXxkR1OMtbePNq+wb+jt4MypH1StSUz+FfCJadD9GCm76in/t?= =?us-ascii?Q?0uJkzFoj+G4CZtmiYGpl25lpp3rWGBpbwUu5ipmtpUHCwNwL/SfYCYZbe12g?= =?us-ascii?Q?EeQwrtAbdB5pQHmxfbZWI7pUimGS/EGhIJfxJAsV03po63bsWbKl0W0At+qY?= =?us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V3iNW5KLFyxQf4Dr6hDkB?= =?us-ascii?Q?RN4QSvy/q6b+be2T5Yw+qNtfRD7erJSLm37DclTIMIDzdI7ieEwfMMqz5LZu?= =?us-ascii?Q?Vs65rY2ilnhZgbB66+Of/ZYk5MQlCN8v1TgJZt9gxQJi4i45yeyuOqB+nvII?= =?us-ascii?Q?i+8qr0e6ynwjCIhP0t9bQzUEG4mV00rQ3dT7Qx/tcJj0pXT4bvZaxsCEIB0o?= =?us-ascii?Q?yavcaUUubvsyGs1eyUklM0kWgkrWS73bfdApVUJ+4sJkp4I3Ke3gyd1sE7HQ?= =?us-ascii?Q?ZVDLlKmb9wKAHhO9VbNsDixgTZS3pvgYNAy4X3RemhWnssP5nC5zUrp0Yviw?= =?us-ascii?Q?9ATlpJHlba8OwKQoTvSMzNJxwy4Rn+ZNUysRqHXDCzhM1VxtW513vs87AvVY?= =?us-ascii?Q?4DfTvvUgx3x9YMKscxX424IycCEcIpgKWbYAbwLDHKNKHTlTYLDXfcOvy1Ke?= =?us-ascii?Q?8PD3rSWQzdBfHoDNKNqMeQsWC1EH3g7H4zlbaWvo?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4219.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a733daef-d005-42a0-2ab9-08da6a0d3a31 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jul 2022 05:03:46.9610 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: YV98P5F+WaUb8PwwVq0/I/lwJurPFD1JEflRC8fv/XuIZ4fS8sEkpiVEjuMU5hKkrPrYejqTBOyUO5/f5OGZKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6695 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jul 2022 05:03:53 -0000 [Public] Hi, Can you review my code changes and send in your comments ? Regards, Rupesh P From: Potharla, Rupesh Sent: Tuesday, July 5, 2022 12:16 PM To: Potharla, Rupesh via Binutils Cc: Parasuraman, Hariharan ; George, Jini Su= san ; Natarajan, Kavitha Subject: [PATCH] bfd: Fix issues with files in debug_line table with dwarf5= . [Public] Hi, While working on the implementation of DW_FORM_strx forms, addr2line tool c= ould not print file names even after the implementation of strx forms. I fo= und an issue with adding the file names to the file table with dwarf5 and c= lang. With dwarf5 debug line version, the file index is starting with zero, but t= he code is expecting it to be 1 which is the case with other dwarf versions= . >From the contents of .debug_line compiled with clang and dwarf5, the file n= ames array index is starting with zero. standard_opcode_lengths[DW_LNS_set_isa] =3D 1 include_directories[ 0] =3D "/home/rupesh/addr2line" file_names[ 0]: name: "prog1.c" dir_index: 0 md5_checksum: da4ea4c312af96d39b13557acdf23f05 Address Line Column File ISA Discriminator Flags ------------------ ------ ------ ------ --- ------------- ------------- The below line skipping zero entry was added as part of commit 19d80e5fec54= 8e681c453d15b4ae5b49bc080acc is ignoring the file names in the zeroth index= . I have no idea why this line was added. Removing the line is working for = programs compiled with clang using dwarf5. With my fix, I am not seeing any= issues with GCC and dwarf5 because currently GCC's debug_line version is 3= even when compiled with dwarf5. /* 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; Made code changes to fix this issue. Added a new test case for addr2line to= test the changes. And fixed a minor bug in read_indexed_address where in o= ffset_size is used instead of addr_size. Can you review the code changes a= nd send in your comments/suggestions? Regards, Rupesh P Patch Inline: Fixed an issue with the file index for dwarf5. Added addr2line test case. read_indexed_address is using offset_size instead of addr_size while reading addrx forms, fixed that as well. --- bfd/dwarf2.c | 21 ++++--- binutils/testsuite/binutils-all/addr2line.exp | 59 +++++++++++++++++++ binutils/testsuite/config/default.exp | 6 ++ 3 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 binutils/testsuite/binutils-all/addr2line.exp diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index aaa2d84887f..2a992d67bc7 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -1369,7 +1369,7 @@ read_indexed_address (uint64_t idx, struct comp_unit = *unit) &file->dwarf_addr_buffer, &file->dwarf_addr_siz= e)) return 0; - if (_bfd_mul_overflow (idx, unit->offset_size, &offset)) + if (_bfd_mul_overflow (idx, unit->addr_size, &offset)) return 0; offset +=3D unit->dwarf_addr_offset; @@ -1380,9 +1380,9 @@ read_indexed_address (uint64_t idx, struct comp_unit = *unit) info_ptr =3D file->dwarf_addr_buffer + offset; - if (unit->offset_size =3D=3D 4) + if (unit->addr_size =3D=3D 4) return bfd_get_32 (unit->abfd, info_ptr); - else if (unit->offset_size =3D=3D 8) + else if (unit->addr_size =3D=3D 8) return bfd_get_64 (unit->abfd, info_ptr); else return 0; @@ -1731,6 +1731,7 @@ struct line_info_table unsigned int num_files; unsigned int num_dirs; unsigned int num_sequences; + unsigned int version; char * comp_dir; char ** dirs; struct fileinfo* files; @@ -1951,6 +1952,8 @@ concat_filename (struct line_info_table *table, unsig= ned int file) { char *filename; + if (table->version >=3D 5) + file =3D file + 1; if (table =3D=3D NULL || file - 1 >=3D table->num_files) { /* FILE =3D=3D 0 means unknown. */ @@ -2579,10 +2582,8 @@ read_formatted_entries (struct comp_unit *unit, bfd_= byte **bufp, } } - /* 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; } *bufp =3D buf; @@ -2747,6 +2748,7 @@ decode_line_info (struct comp_unit *unit) table->sequences =3D NULL; table->lcl_head =3D NULL; + table->version =3D lh.version; if (lh.version >=3D 5) { @@ -2789,13 +2791,16 @@ 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; + int index =3D table->version >=3D 5 ? 0 : 1; unsigned int line =3D 1; unsigned int column =3D 0; unsigned int discriminator =3D 0; int is_stmt =3D lh.default_is_stmt; int end_sequence =3D 0; unsigned int dir, xtime, size; + + filename =3D table->num_files ? concat_filename (table, index) : NUL= L; /* eraxxon@alumni.rice.edu: Against = the DWARF2 specs, some compilers generate address sequences that are wildly out of order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler diff --git a/binutils/testsuite/binutils-all/addr2line.exp b/binutils/tests= uite/binutils-all/addr2line.exp new file mode 100644 index 00000000000..153e83c2ace --- /dev/null +++ b/binutils/testsuite/binutils-all/addr2line.exp @@ -0,0 +1,59 @@ +# Copyright (C) 2018-2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-130= 1, USA. + + global $NM + global $ADDR2LINE + + set testname "addr2line" + if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog execut= able debug] !=3D "" } { + verbose "Unable to compile test file." + untested "addr2line" + return + } + + #testcase for default option. + set output [binutils_run $NM "tmpdir/testprog"] + regexp -line {^[0-9]+\s+[A-Z]\s+main} $output contents + set list [regexp -inline -all -- {\S+} $contents] + + set got [binutils_run $ADDR2LINE "-e tmpdir/testprog [lindex $list 0]= "] + set want "$srcdir/$subdir/testprog.c:\[0-9\]+" + if ![regexp $want $got] then { + fail "$testname $got\n" + } else { + pass "$testname" + } + + #testcase for -f option. + regexp -line {^[0-9]+\s+[A-Z]\s+fn} $output contents + set list [regexp -inline -all -- {\S+} $contents] + + set got [binutils_run $ADDR2LINE "-f -e tmpdir/testprog [lindex $list= 0]"] + set want "fn\n$srcdir/$subdir/testprog.c:\[0-9\]+" + if ![regexp $want $got] then { + fail "$testname -f option $got\n" + } else { + pass "$testname -f option" + } + + #testcase for -s option. + set got [binutils_run $ADDR2LINE "-s -e tmpdir/testprog [lindex $list= 0]"] + set want "testprog.c:\[0-9\]+" + if ![regexp $want $got] then { + fail "$testname -s option $got\n" + } else { + pass "$testname -s option" + } diff --git a/binutils/testsuite/config/default.exp b/binutils/testsuite/con= fig/default.exp index c654bd4081c..7192c929a83 100644 --- a/binutils/testsuite/config/default.exp +++ b/binutils/testsuite/config/default.exp @@ -40,6 +40,12 @@ if ![info exists NM] then { if ![info exists NMFLAGS] then { set NMFLAGS "" } +if ![info exists ADDR2LINE] then { + set ADDR2LINE [findfile $base_dir/addr2line $base_dir/addr2line [trans= form nm]] +} +if ![info exists ADDR2LINEFLAGS] then { + set ADDR2LINEFLAGS "" +} if ![info exists SIZE] then { set SIZE [findfile $base_dir/size] } -- 2.17.1