This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch 09/15] PIE: symbol-less (exec-file only) executables


On Sat, 09 Jan 2010 00:44:42 +0100, Tom Tromey wrote:
> The RHS of the "<" needs parens if it is going to be split.
+
> Likewise, parens around the second argument to paddress, or different
> splitting.

Fixed.


> This is ok with the formatting nits fixed.

Checked-in.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2010-01/msg00121.html

--- src/gdb/ChangeLog	2010/01/14 20:48:25	1.11247
+++ src/gdb/ChangeLog	2010/01/14 21:01:24	1.11248
@@ -1,5 +1,11 @@
 2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	Support PIEs with no symfile_objfile.
+	* exec.c (print_section_info <abfd == exec_bfd>): Relocate Entry point.
+	* solib-svr4.c (svr4_relocate_main_executable <exec_bfd>): New block.
+
+2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* solib-svr4.c (svr4_relocate_main_executable): Move the static exec
 	code part to ...
 	(svr4_static_exec_displacement): ... a new function.
--- src/gdb/exec.c	2010/01/01 07:31:31	1.92
+++ src/gdb/exec.c	2010/01/14 21:01:24	1.93
@@ -674,8 +674,36 @@
   wrap_here ("        ");
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
   if (abfd == exec_bfd)
-    printf_filtered (_("\tEntry point: %s\n"),
-                     paddress (gdbarch, bfd_get_start_address (abfd)));
+    {
+      bfd_vma displacement;
+
+      for (p = t->sections; p < t->sections_end; p++)
+	{
+	  asection *asect = p->the_bfd_section;
+
+	  if ((bfd_get_section_flags (abfd, asect) & (SEC_ALLOC | SEC_LOAD))
+	      != (SEC_ALLOC | SEC_LOAD))
+	    continue;
+
+	  if (bfd_get_section_vma (abfd, asect) <= abfd->start_address
+	      && abfd->start_address < (bfd_get_section_vma (abfd, asect)
+					+ bfd_get_section_size (asect)))
+	    {
+	      displacement = p->addr - bfd_get_section_vma (abfd, asect);
+	      break;
+	    }
+	}
+      if (p == t->sections_end)
+	{
+	  warning (_("Cannot find section for the entry point of %s.\n"),
+		   bfd_get_filename (abfd));
+	  displacement = 0;
+	}
+
+      printf_filtered (_("\tEntry point: %s\n"),
+		       paddress (gdbarch, (bfd_get_start_address (abfd)
+					   + displacement)));
+    }
   for (p = t->sections; p < t->sections_end; p++)
     {
       printf_filtered ("\t%s", hex_string_custom (p->addr, wid));
--- src/gdb/solib-svr4.c	2010/01/14 20:48:26	1.111
+++ src/gdb/solib-svr4.c	2010/01/14 21:01:24	1.112
@@ -1649,6 +1649,15 @@
 
       objfile_relocate (symfile_objfile, new_offsets);
     }
+  else if (exec_bfd)
+    {
+      asection *asect;
+
+      for (asect = exec_bfd->sections; asect != NULL; asect = asect->next)
+	exec_set_section_address (bfd_get_filename (exec_bfd), asect->index,
+				  (bfd_section_vma (exec_bfd, asect)
+				   + displacement));
+    }
 }
 
 /*
--- src/gdb/testsuite/ChangeLog	2010/01/14 20:48:26	1.2083
+++ src/gdb/testsuite/ChangeLog	2010/01/14 21:01:25	1.2084
@@ -1,5 +1,12 @@
 2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	Support PIEs with no symfile_objfile.
+	* gdb.base/break-interp.exp: New argument at the test_ld calls.
+	(test_ld): New parameter trynosym.
+	(test_ld <$trynosym>): New block.
+
+2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* gdb.base/break-interp.exp: New file.
 
 2010-01-13  Phil Muldoon  <pmuldoon@redhat.com>
--- src/gdb/testsuite/gdb.base/break-interp.exp	2010/01/14 20:48:26	1.1
+++ src/gdb/testsuite/gdb.base/break-interp.exp	2010/01/14 21:01:25	1.2
@@ -223,7 +223,7 @@
     }
 }
 
-proc test_ld {file ifmain} {
+proc test_ld {file ifmain trynosym} {
     global srcdir subdir gdb_prompt
 
     # First test normal `file'-command loaded $FILE with symbols.
@@ -239,6 +239,50 @@
     if $ifmain {
 	reach "main" continue
     }
+
+    if !$trynosym {
+	return
+    }
+
+    global pf_prefix
+    set old_ldprefix $pf_prefix
+    lappend pf_prefix "symbol-less:"
+
+    # Test also `exec-file'-command loaded $FILE - therefore without symbols.
+    # SYMBOL_OBJFILE is not available and only EXEC_BFD must be used.
+
+    gdb_exit
+    gdb_start
+    # Clear it to never find any separate debug infos in $debug_root.
+    gdb_test "set debug-file-directory"
+    gdb_reinitialize_dir $srcdir/$subdir
+
+    # Test no (error) message has been printed by `exec-file'.
+    set escapedfile [string_to_regexp $file]
+    gdb_test "exec-file $file" "exec-file $escapedfile" "load"
+
+    if $ifmain {
+	reach "dl_main" run
+
+	set test "info files"
+	set entrynohex ""
+	gdb_test_multiple $test $test {
+	    -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n.*$gdb_prompt $" {
+		set entrynohex $expect_out(1,string) 
+		pass $test
+	    }
+	}
+	if {$entrynohex != ""} {
+	    gdb_test "break *0x$entrynohex" "" "break at entry point"
+	    gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached"
+	}
+    } else {
+	# There is no symbol to break at ld.so.  Moreover it can exit with an
+	# error code.
+	gdb_test "run" "Program exited (normally|with code \[0-9\]+)\\." "ld.so exit"
+    }
+
+    set pf_prefix $old_ldprefix
 }
 
 # Create separate binaries for each testcase - to make the possible reported
@@ -322,7 +366,7 @@
 	if ![prelink$ldprelink $interp] {
 	    continue
 	}
-	test_ld $interp 0
+	test_ld $interp 0 [expr {$ldsepdebug == "NO"}]
 
 	if ![copy $interp $interp_saved] {
 	    continue
@@ -401,7 +445,7 @@
 
 		    if {[prelink$binprelink "--dynamic-linker=$interp --ld-library-path=$dir $exec $interp [concat $dests]" $exec]
 		        && [copy $interp_saved $interp]} {
-			test_ld $exec 1
+			test_ld $exec 1 [expr {$binsepdebug == "NO"}]
 		    }
 		}
 	    }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]