Message ID | 20230323075908.23013-1-lihui@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 479923870894 for <patchwork@sourceware.org>; Thu, 23 Mar 2023 07:59:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 0B51C3858433 for <gdb-patches@sourceware.org>; Thu, 23 Mar 2023 07:59:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B51C3858433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxJAzXBhxkPT8QAA--.24281S3; Thu, 23 Mar 2023 15:59:21 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxLuTWBhxkuTMKAA--.38992S2; Thu, 23 Mar 2023 15:59:18 +0800 (CST) From: Hui Li <lihui@loongson.cn> To: gdb-patches@sourceware.org Subject: [PATCH] gdb/elfread.c: Add plt symbol check for _PROCEDURE_LINKAGE_TABLE_ Date: Thu, 23 Mar 2023 15:59:08 +0800 Message-Id: <20230323075908.23013-1-lihui@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxLuTWBhxkuTMKAA--.38992S2 X-CM-SenderInfo: 5olk3xo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7tw1fuFyxCF13Xr1xuFyxGrg_yoW8tFy3pr WUK345WF4rJr1DC3Z8t3Z5XrW5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F_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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
gdb/elfread.c: Add plt symbol check for _PROCEDURE_LINKAGE_TABLE_
|
|
Commit Message
Hui Li
March 23, 2023, 7:59 a.m. UTC
In the current code, when execute the following test on LoongArch:
$ make check-gdb TESTS="gdb.base/gnu-ifunc.exp"
=== gdb Summary ===
# of expected passes 111
# of unexpected failures 62
This is because some architectures such as LoongArch define the symbol
_PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. Add plt
symbol check for _PROCEDURE_LINKAGE_TABLE_ to improved the judgment of
plt symbol and to get correct target function address of STT_GNU_IFUNC.
```
loongson@bogon:~$ cat test.c
int main(int argc, char const *argv[])
{
printf("hello world\n");
return 0;
}
loongson@bogon:~$ gcc test.c -o test
loongson@bogon:~$ objdump -d test
test: file format elf64-loongarch
Disassembly of section .plt:
0000000120004000 <_PROCEDURE_LINKAGE_TABLE_>:
120004000: 8e 01 00 1c ad bd 11 00 cf 01 c0 28 ad 51 ff 02 ...........(.Q..
120004010: cc 01 c0 02 ad 05 45 00 8c 21 c0 28 e0 01 00 4c ......E..!.(...L
0000000120004020 <__libc_start_main@plt>:
120004020: 1c00018f pcaddu12i $t3, 12(0xc)
120004024: 28ffc1ef ld.d $t3, $t3, -16(0xff0)
120004028: 4c0001ed jirl $t1, $t3, 0
12000402c: 03400000 andi $zero, $zero, 0x0
0000000120004030 <abort@plt>:
120004030: 1c00018f pcaddu12i $t3, 12(0xc)
120004034: 28ffa1ef ld.d $t3, $t3, -24(0xfe8)
120004038: 4c0001ed jirl $t1, $t3, 0
12000403c: 03400000 andi $zero, $zero, 0x0
0000000120004040 <puts@plt>:
120004040: 1c00018f pcaddu12i $t3, 12(0xc)
120004044: 28ff81ef ld.d $t3, $t3, -32(0xfe0)
120004048: 4c0001ed jirl $t1, $t3, 0
12000404c: 03400000 andi $zero, $zero, 0x0
...
```
With this patch:
$ make check-gdb TESTS="gdb.base/gnu-ifunc.exp"
=== gdb Summary ===
#of expected passes 173
Signed-off-by: Hui Li <lihui@loongson.cn>
---
gdb/elfread.c | 3 +++
1 file changed, 3 insertions(+)
Comments
>>>>> Hui Li <lihui@loongson.cn> writes: > This is because some architectures such as LoongArch define the symbol > _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. Add plt > symbol check for _PROCEDURE_LINKAGE_TABLE_ to improved the judgment of > plt symbol and to get correct target function address of STT_GNU_IFUNC. It would be helpful to know how precisely things go wrong. The patch itself seems reasonable enough -- hacky maybe but not out of the ordinary way -- but I don't understand how it relates to the problem. Like, why does ignoring this symbol here affect the results? Tom
On 2023/3/25 上午12:16, Tom Tromey wrote: >>>>>> Hui Li <lihui@loongson.cn> writes: > >> This is because some architectures such as LoongArch define the symbol >> _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. Add plt >> symbol check for _PROCEDURE_LINKAGE_TABLE_ to improved the judgment of >> plt symbol and to get correct target function address of STT_GNU_IFUNC. > > It would be helpful to know how precisely things go wrong. > The patch itself seems reasonable enough -- hacky maybe but not out of > the ordinary way -- but I don't understand how it relates to the problem. > Like, why does ignoring this symbol here affect the results? > > Tom > Thanks for your review. This is a minor fix for one of the subfunction about ifunc. The principle of ifunc and its implementation in gdb are not explained in detail. So it's hard to understand how it relates to the problem. I change the commit message to explain this process in detail, and send V2. https://sourceware.org/pipermail/gdb-patches/2023-March/198303.html Thanks. Hui
diff --git a/gdb/elfread.c b/gdb/elfread.c index b414da9ed21..1e606783c33 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -722,6 +722,9 @@ elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr) if (len > 4 && strcmp (target_name + len - 4, "@plt") == 0) return 0; + if (strcmp (target_name, "_PROCEDURE_LINKAGE_TABLE_") == 0) + return 0; + htab = elf_objfile_gnu_ifunc_cache_data.get (objfile); if (htab == NULL) {