From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4P6nD6tbXGdfeRUAWB0awg (envelope-from ) for ; Fri, 13 Dec 2024 11:07:07 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bXT3D8zz; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3C17C1E097; Fri, 13 Dec 2024 11:07:07 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9F1421E091 for ; Fri, 13 Dec 2024 11:07:06 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5386D3858C35 for ; Fri, 13 Dec 2024 16:07:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5386D3858C35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bXT3D8zz Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 6CCC73857C47 for ; Fri, 13 Dec 2024 15:58:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CCC73857C47 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6CCC73857C47 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734105488; cv=none; b=I14Kmw4BNQl+KkJ6MRFJ19zH2mkfob/Y3sdqVq2pZKZUj4/4B1ykfQwrNLYIFI608bssPoqC4ii+/uQnc/oi3wAp8SrjIWKQe8BCkFcRhc7XRzt3aOQ6v+Yvq4iyXHVb3QnDjGnf+K5ndG3JX2SPvRK7lwVaHO3cdKEXkz027V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734105488; c=relaxed/simple; bh=Ne/Du5emYyyl8TEiT731hO8tkvndddcywhPsFOH/i1s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BoHkXjcntzev7Rz0VCAPKgUQ7RD9u+OjcKUmTaLXoK4cR9fFXpiwD7bSAKUI1I4kGj68YKjEDa2zR2h6UZLdL1oA+gmKRl79GrAMp8X7CizjYWzM2ZepJhjepHhfPen7k/X028ZD+Jh0hO3yN8WZwri9tMgH+p1S7eChIXg8ywE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CCC73857C47 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5d3e6f6cf69so3151758a12.1 for ; Fri, 13 Dec 2024 07:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734105487; x=1734710287; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wWBUtnpd84OOyEs/NlonETxXE70XcEoZPmNz7+Y6Xa0=; b=bXT3D8zzZrhJ/DnOiwn7pbw2203/yj1wHTHlyi351xU3ySB0rSlXFg1Pjhyfwi92sC uYBqk00z6q6K+nf3g3GHnu0HC5OI2Swp7ls50UlD6mWpybdsFzaEqrxuxOFj6CDmQu7D rK5M0Q1e8Mc/KyTDCTlFh0XLgRDye7jHNO+CJepiStFZl+f4FqNBzWvuaYV1XM/o5yrM sQjNE4gtQU7+acJdPLL9FCPax6qW4xvOpJrmCjF6j1FX+hobcPmzjFRgjxVSthMO38QI zw9qpAbbMhEKPO+nL4EdE7I0RQ0wvc9Y8fyGwsaX8puFPX1kQ5QTLCCzywL02ewBDLyt 7TBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734105487; x=1734710287; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wWBUtnpd84OOyEs/NlonETxXE70XcEoZPmNz7+Y6Xa0=; b=eSufp9hJLYISdNacZRsp86dPdOoRwaitb5YCCMkpWLk6D4JYBv98m3+fOeraKE1Jrc wTUpkFYu2hoOWmkGL8pkNBt58foWGBdKbSQQRpTfyrGcTtQP7IgmFVkIu9iUSmuqb7qd IWJLXAym4RIxdcz9F0xvrzcFiCiPSQBYl4/wuRXhb6Ou7KRgcU6RItygxm17D7xlXlhI 5f8DCTHzkFF8BBEPUtgZDITIpl4CyxeVSWGcdM50wbj/4Y0Q/vWbSVV1ykn52BoI9khD hCpd1C6U3oL1PiAnoeEk8p34mjL0zORFH1DEHwRg0eQRg3ophyeVupjASMQFt+Gn8fI3 SVcw== X-Gm-Message-State: AOJu0Yzp1K9oN2t+NvneAqSxxZ8ScpVCQvl55ZTzsjsPSnGKkbZ4OLtI e/e3J5+XcPqKe54752FK29UdoD073JNdZZTuEmb/6a0/Fv3JS6yJFt+ngl8a X-Gm-Gg: ASbGncsnEivHrJovcCGWXCcBc1jvXF6msV0C5KU+GQaa5WP4KQA0FOD9fiREKkm+2QN zlrWYQD84XBjVF7Nhe/VFMatdCG0lg3JEkGCU0qYRvrzQU09MD7M0Rf4GYg3TXE01bhaUxEvNjg mKCHPCNj+julrNdRGFwaD4xW8Cl1XJGm/y1fnPswiFOyqOS+N/I4jPGTBerGoqGtuYI9akjh1B7 XPccRHBZqUHYtFyDK/pX8uZOOT3JU4X2SRlY3c5lI3qCcs03hT8xU2zYnF1rxgDuG55gIgE X-Google-Smtp-Source: AGHT+IGxAhF5mURSKlWjptmE8qYLg+bQiNekoAAZOPm9bViSFSjp+ZPGq1Kvx1yS1cIv8wQOOAv/Aw== X-Received: by 2002:a05:6402:26cf:b0:5d0:e826:f0ec with SMTP id 4fb4d7f45d1cf-5d63c2e5349mr3191101a12.4.1734105486683; Fri, 13 Dec 2024 07:58:06 -0800 (PST) Received: from SYRN16-0224-L.. ([109.245.202.111]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5d6501d5863sm95355a12.76.2024.12.13.07.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 07:58:06 -0800 (PST) From: Milica Matic X-Google-Original-From: Milica Matic To: gdb-patches@sourceware.org Cc: milica.matic@htecgroup.com, simark@simark.ca, cfu@wavecomp.com, aburgess@redhat.com, kevinb@redhat.com, macro@orcam.me.uk, djordje.todorovic@htecgroup.com, Matthew Fortune , Faraz Shahbazker Subject: [PATCH 20/21] Workaround for line info in compressed MIPS func Date: Fri, 13 Dec 2024 16:53:27 +0100 Message-Id: <20241213155328.406003-22-milica.matic@htecgroup.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241213155328.406003-1-milica.matic@htecgroup.com> References: <20241213155328.406003-1-milica.matic@htecgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Matthew Fortune This fix allows the first address of a MIPS16/microMIPS function to be used to get the filename/line and function that it belongs to whereas it has previously needed the ISA bit to be set in the address for the first instruction to match up correctly. Note: we should really be checking the output of addr2line, but the binutils test-framework doesn't have that capability yet. Expected addr2line output for both new tests is: $ addr2line -a 0x400000 0x400004 0x40000c -p -e 0x00400000: .*-lineno.c:1 0x00400004: .*-lineno.c:2 0x0040000c: .*-lineno.c:3 Cherry-picked 2279503 from https://github.com/MIPS/binutils-gdb Signed-off-by: Faraz Shahbazker Signed-off-by: Milica Matic Changelog: bfd/ * elfxx-mips.c (_bfd_mips_elf_find_nearest_line): If no matching line is found for an address, retry with the ISA bit set in case searching at the beginning of a MIPS16/microMIPS section. ld/testsuite/ * ld-mips-elf/mips16-lineno.s: New test source. * ld-mips-elf/micromips-lineno.s: New test source. * ld-mips-elf/mips16-lineno.d: New test. * ld-mips-elf/micromips-lineno.d: New test. * ld-mips-elf/mips-elf.exp: Run the new tests --- bfd/elfxx-mips.c | 19 +++++++-- ld/testsuite/ld-mips-elf/micromips-lineno.d | 33 +++++++++++++++ ld/testsuite/ld-mips-elf/micromips-lineno.s | 44 ++++++++++++++++++++ ld/testsuite/ld-mips-elf/mips16-lineno.d | 32 ++++++++++++++ ld/testsuite/ld-mips-elf/mips16-lineno.s | 46 +++++++++++++++++++++ 5 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 ld/testsuite/ld-mips-elf/micromips-lineno.d create mode 100644 ld/testsuite/ld-mips-elf/micromips-lineno.s create mode 100644 ld/testsuite/ld-mips-elf/mips16-lineno.d create mode 100644 ld/testsuite/ld-mips-elf/mips16-lineno.s diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 68b439c456a..f0c5e7ae6cd 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -13423,6 +13423,7 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols, unsigned int *discriminator_ptr) { asection *msec; + bool found = false; if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset, filename_ptr, functionname_ptr, @@ -13513,9 +13514,21 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols, /* Fall back on the generic ELF find_nearest_line routine. */ - return _bfd_elf_find_nearest_line (abfd, symbols, section, offset, - filename_ptr, functionname_ptr, - line_ptr, discriminator_ptr); + found = _bfd_elf_find_nearest_line (abfd, symbols, section, offset, + filename_ptr, functionname_ptr, + line_ptr, discriminator_ptr); + + /* The bfd_find_nearest_line_discriminator may not be able to find filename + and line if pc points to start of a MIPS compressed function. This is + because ISA bit is set in the line number entries. For example, if start + of a function is 0x80200750 then line number entries start from 0x80200751 + (31st bit is set). Set ISA bit of the pc and search again. + if (found && *filename_ptr == NULL && *line_ptr == 0 && (offset & 1) == 0) + found = _bfd_elf_find_nearest_line (abfd, symbols, section, + offset | 1, + filename_ptr, functionname_ptr, + line_ptr, discriminator_ptr); */ + return found; } bool diff --git a/ld/testsuite/ld-mips-elf/micromips-lineno.d b/ld/testsuite/ld-mips-elf/micromips-lineno.d new file mode 100644 index 00000000000..09d8008580d --- /dev/null +++ b/ld/testsuite/ld-mips-elf/micromips-lineno.d @@ -0,0 +1,33 @@ +#name: MICROMIPS address mapping to debug line information +#ld: -Ttext 0x400020 +#objdump: -dlr +#source: micromips-lineno.s + +.*: +file format .*mips.* + +Disassembly of section \.text: + +00400020 <__start>: +__start\(\): + 400020: 00000000 nop + +00400024 : +foo\(\): + 400024: 0c00 nop +.*micromips-lineno.c:1 + 400026: 47e3 jrc ra + +00400028 : +.*micromips-lineno.c:2 + 400028: 03e00009 jr ra +bar\(\): +.*micromips-lineno.c:2 + 40002c: 00000000 nop + +00400030 : +baz\(\): + 400030: 0c00 nop +.*micromips-lineno.c:3 + 400032: 47e3 jrc ra + +#pass diff --git a/ld/testsuite/ld-mips-elf/micromips-lineno.s b/ld/testsuite/ld-mips-elf/micromips-lineno.s new file mode 100644 index 00000000000..0dced268360 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/micromips-lineno.s @@ -0,0 +1,44 @@ + # Dummy file name + .file 1 "micromips-lineno.c" + .section .text.foo,"ax",@progbits + .globl foo + .globl main + .globl start + .globl _start + .globl __start + # Dummy line number 1 + .loc 1 1 0 + .set micromips + .set nomips16 + .ent foo +foo: + nop + jr $ra + .end foo + .section .text.bar,"ax",@progbits + .globl bar + # Dummy line number 2 + .loc 1 2 0 + .set nomicromips + .ent bar +bar: + nop + jr $ra + .end bar + .section .text.baz,"ax",@progbits + .globl baz + # Dummy line number 3 + .loc 1 3 0 + .set micromips + .ent baz +baz: + nop + jr $ra + .end baz + + .text +main: +start: +_start: +__start: + .byte 0 diff --git a/ld/testsuite/ld-mips-elf/mips16-lineno.d b/ld/testsuite/ld-mips-elf/mips16-lineno.d new file mode 100644 index 00000000000..05dde9348a4 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/mips16-lineno.d @@ -0,0 +1,32 @@ +#name: MIPS16 address mapping to debug line information +#as: -march=mips2 -mabi=32 +#ld: -Ttext 0x400020 +#objdump: -dlr +#source: mips16-lineno.s + +.*: +file format .*mips.* + +Disassembly of section \.text: + +00400020 <\_\_start>: +\_\_start\(\): + 400020: 00000000 nop + +00400024 : +foo\(\): + 400024: e820 jr ra +.*mips16-lineno.c:1 + 400026: 6500 nop + +00400028 : +.*mips16-lineno.c:2 + 400028: 03e00008 jr ra +bar\(\): +.*mips16-lineno.c:2 + 40002c: 00000000 nop + +00400030 : +baz\(\): + 400030: e820 jr ra +.*mips16-lineno.c:3 + 400032: 6500 nop diff --git a/ld/testsuite/ld-mips-elf/mips16-lineno.s b/ld/testsuite/ld-mips-elf/mips16-lineno.s new file mode 100644 index 00000000000..48c2baa4948 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/mips16-lineno.s @@ -0,0 +1,46 @@ + # Dummy file name + .file 1 "mips16-lineno.c" + .section .text.foo,"ax",@progbits + .globl foo + .globl main + .globl start + .globl _start + .globl __start + # Dummy line number 1 + .loc 1 1 0 + .set mips16 + .set nomicromips + .ent foo +foo: + nop + jr $ra + .end foo + .section .text.bar,"ax",@progbits + .globl bar + # Dummy line number 2 + .loc 1 2 0 + .set nomips16 + .ent bar +bar: + nop + jr $ra + .end bar + .section .text.baz,"ax",@progbits + .globl baz + # Dummy line number 3 + .loc 1 3 0 + .set mips16 + .ent baz +baz: + nop + jr $ra + .end baz + + + .text +main: +start: +_start: +__start: + .byte 0 + -- 2.34.1