public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/elfread.c: Add plt symbol check for _PROCEDURE_LINKAGE_TABLE_
@ 2023-03-23  7:59 Hui Li
  2023-03-24 16:16 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Hui Li @ 2023-03-23  7:59 UTC (permalink / raw)
  To: gdb-patches

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(+)

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)
     {
-- 
2.38.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-27  9:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23  7:59 [PATCH] gdb/elfread.c: Add plt symbol check for _PROCEDURE_LINKAGE_TABLE_ Hui Li
2023-03-24 16:16 ` Tom Tromey
2023-03-27  9:39   ` Hui Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).