public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/breakpoint] Handle .plt.sec in in_plt_section
@ 2021-01-06 15:37 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-01-06 15:37 UTC (permalink / raw)
  To: gdb-patches

Hi,

Consider the following test-case small.c:
...
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

 int main (void) {
   int *p = (int *)malloc (sizeof(int) * 4);
   memset (p, 0, sizeof(p));
   printf ("p[0] = %d; p[3] = %d\n", p[0], p[3]);
   return 0;
 }
...

On Ubuntu 20.4, we get:
...
$ gcc -O0 -g small.c
$ gdb -batch a.out -ex start -ex step
Temporary breakpoint 1, main () at small.c:6
6         int *p = (int *) malloc(sizeof(int) * 4);
p[0] = 0; p[3] = 0
[Inferior 1 (process $dec) exited normally]
...
but after switching off the on-by-default fcf-protection, we get the desired
behaviour:
...
$ gcc -O0 -g small.c -fcf-protection=none
$ gdb -batch a.out -ex start -ex step
Temporary breakpoint 1, main () at small.c:6
6         int *p = (int *) malloc(sizeof(int) * 4);
7         memset (p, 0, sizeof(p));
...

Using "set debug infrun 1", the first observable difference between the two
debug sessions is that with -fcf-protection=none we get:
...
[infrun] process_event_stop_test: stepped into dynsym resolve code
...
In this case, "in_solib_dynsym_resolve_code (malloc@plt)" returns true because
"in_plt_section (malloc@plt)" returns true.

With -fcf-protection=full, "in_solib_dynsym_resolve_code (malloc@plt)" returns
false because "in_plt_section (malloc@plt)" returns false, because the section
name for malloc@plt is .plt.sec instead of .plt, which is not handled in
in_plt_section:
...
static inline int
in_plt_section (CORE_ADDR pc)
{
  return pc_in_section (pc, ".plt");
}
...

Fix this by handling .plt.sec in in_plt_section.

Tested on x86_64-linux.

[ Another requirement to be able to reproduce this is to have a dynamic linker
with a "malloc" minimal symbol, which causes find_solib_trampoline_target to
find it, such that skip_language_trampoline returns the address for the
dynamic linkers malloc.  This causes the step machinery to set a breakpoint
there, and to continue, expecting to hit it. Obviously, we execute glibc's
malloc instead, so the breakpoint is not hit and we continue to program
completion. ]

Any comments?

Thanks,
- Tom

[gdb/breakpoint] Handle .plt.sec in in_plt_section

gdb/ChangeLog:

2021-01-06  Tom de Vries  <tdevries@suse.de>

	PR breakpoints/27151
	* objfiles.h (in_plt_section): Handle .plt.sec.

---
 gdb/objfiles.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 49578ee890c..052f109db4d 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -786,7 +786,8 @@ extern int pc_in_section (CORE_ADDR, const char *);
 static inline int
 in_plt_section (CORE_ADDR pc)
 {
-  return pc_in_section (pc, ".plt");
+  return (pc_in_section (pc, ".plt")
+	  || pc_in_section (pc, ".plt.sec"));
 }
 
 /* Keep a registry of per-objfile data-pointers required by other GDB

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-06 15:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 15:37 [PATCH][gdb/breakpoint] Handle .plt.sec in in_plt_section Tom de Vries

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).