[Ltrace-devel] r40 - in ltrace/trunk: . sysdeps/linux-gnu/alpha sysdeps/linux-gnu/arm sysdeps/linux-gnu/i386 sysdeps/linux-gnu/ia64 sysdeps/linux-gnu/m68k sysdeps/linux-gnu/ppc sysdeps/linux-gnu/s390 sysdeps/linux-gnu/sparc sysdeps/linux-gnu/x86_64

Paul Gilliam pgilliam-guest at costa.debian.org
Mon Apr 24 20:06:24 UTC 2006


Author: pgilliam-guest
Date: 2006-04-24 20:06:23 +0000 (Mon, 24 Apr 2006)
New Revision: 40

Modified:
   ltrace/trunk/ChangeLog
   ltrace/trunk/elf.c
   ltrace/trunk/ltrace.1
   ltrace/trunk/options.c
   ltrace/trunk/process_event.c
   ltrace/trunk/sysdeps/linux-gnu/alpha/arch.h
   ltrace/trunk/sysdeps/linux-gnu/arm/arch.h
   ltrace/trunk/sysdeps/linux-gnu/i386/arch.h
   ltrace/trunk/sysdeps/linux-gnu/ia64/arch.h
   ltrace/trunk/sysdeps/linux-gnu/m68k/arch.h
   ltrace/trunk/sysdeps/linux-gnu/ppc/arch.h
   ltrace/trunk/sysdeps/linux-gnu/s390/arch.h
   ltrace/trunk/sysdeps/linux-gnu/sparc/arch.h
   ltrace/trunk/sysdeps/linux-gnu/x86_64/arch.h
Log:
Some versions of ltrace need to set a breakpoint at "_start", or somewhere, so
that breakpoints can be set *after* the dynamic loader has run.  By default,
ltrace looks for "_start" in the symbol table.  But if the target program has
been stripped, there is no symbol table.

This patch changes things so that if "_start" (or whatever the user specified
using -X) could not be found, the value of "e_entry" in the elf header will be
assumed to be that address.

This patch *also* makes all the "_start" stuff conditional on
PLT_REINITALISATION_BP.  If an architecture doesn't need this stuff, then
it doesn't define PLT_REINITALISATION_BP in it's "arch.h" file (which is
copied to sysdep/linux-gnu/sysdep.h by configure).
--This line, and those b elow, will be ignored--

M    trunk/elf.c
M    trunk/ChangeLog
M    trunk/sysdeps/linux-gnu/arm/arch.h
M    trunk/sysdeps/linux-gnu/ppc/arch.h
M    trunk/sysdeps/linux-gnu/m68k/arch.h
M    trunk/sysdeps/linux-gnu/alpha/arch.h
M    trunk/sysdeps/linux-gnu/i386/arch.h
M    trunk/sysdeps/linux-gnu/x86_64/arch.h
M    trunk/sysdeps/linux-gnu/s390/arch.h
M    trunk/sysdeps/linux-gnu/ia64/arch.h
M    trunk/sysdeps/linux-gnu/sparc/arch.h
M    trunk/process_event.c
M    trunk/ltrace.1
M    trunk/options.c


Modified: ltrace/trunk/ChangeLog
===================================================================
--- ltrace/trunk/ChangeLog	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/ChangeLog	2006-04-24 20:06:23 UTC (rev 40)
@@ -1,3 +1,24 @@
+ 2006-04-24  Paul Gilliam <pgilliam at us.ibm.com>
+
+	* elf.c: Use PLT_REINITALISATION_BP for those architectures that need
+	to re-initialize breakpoints after the dynamic linker has run.  Also,
+	use value of "e_entry" for address of PLT_REINITALISATION_BP if the
+	 target program has been stripped.
+	* ltrace.1: Note that fact that "-X" is only available on architectures
+	that need it.
+	* options.c: Use PLT_REINITALISATION_BP for those architectures that
+	need to re-initialize breakpoints after the dynamic linker has run.
+	* process_event.c: ditto.
+	* sysdeps/linux-gnu/ppc/arch.h: This is the only such architecture.
+	* sysdeps/linux-gnu/arm/arch.h: Delete use of PLT_REINITALISATION_BP.
+	* sysdeps/linux-gnu/m68k/arch.h: ditto.
+	* sysdeps/linux-gnu/alpha/arch.h: ditto.
+	* sysdeps/linux-gnu/i386/arch.h: ditto.
+	* sysdeps/linux-gnu/x86_64/arch.h: ditto.
+	* sysdeps/linux-gnu/s390/arch.h: ditto.
+	* sysdeps/linux-gnu/ia64/arch.h: ditto.
+	* sysdeps/linux-gnu/sparc/arch.h: ditto.
+
 2006-04-24  Paul Gilliam <pgilliam at us.ibm.com>
 
 	* elf.c: Adds some casts to keep a more picky version of GCC happy.

Modified: ltrace/trunk/elf.c
===================================================================
--- ltrace/trunk/elf.c	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/elf.c	2006-04-24 20:06:23 UTC (rev 40)
@@ -25,7 +25,9 @@
 static int in_load_libraries(const char *name, struct ltelf *lte);
 static GElf_Addr elf_plt2addr(struct ltelf *ltc, void *addr);
 
+#ifdef PLT_REINITALISATION_BP
 extern char *PLTs_initialized_by_here;
+#endif
 
 static void do_init_elf(struct ltelf *lte, const char *filename)
 {
@@ -387,8 +389,10 @@
 			      "Couldn't get relocation from \"%s\"",
 			      proc->filename);
 
+#ifdef PLT_REINITALISATION_BP
 		if (!sym.st_value && PLTs_initialized_by_here)
 			proc->need_to_reinitialize_breakpoints = 1;
+#endif
 
 		name = lte->dynstr + sym.st_name;
 		if (in_load_libraries(name, lte)) {
@@ -400,12 +404,15 @@
 		}
 	}
 
+#ifdef PLT_REINITALISATION_BP
 	if (proc->need_to_reinitialize_breakpoints) {
-		/* Add "PLTs_initialized_by_here" to opt_x list, if not already there. */
+		/* Add "PLTs_initialized_by_here" to opt_x list, if not
+                   already there. */
 		main_cheat = (struct opt_x_t *)malloc(sizeof(struct opt_x_t));
 		if (main_cheat == NULL)
 			error(EXIT_FAILURE, 0, "Couldn allocate memory");
 		main_cheat->next = opt_x;
+		main_cheat->found = 0;
 		main_cheat->name = PLTs_initialized_by_here;
 
 		for (xptr = opt_x; xptr; xptr = xptr->next)
@@ -418,6 +425,7 @@
 		if (main_cheat)
 			opt_x = main_cheat;
 	}
+#endif
 
 	for (i = 0; i < lte->symtab_count; ++i) {
 		GElf_Sym sym;
@@ -448,13 +456,28 @@
 	for (xptr = opt_x; xptr; xptr = xptr->next)
 		if ( ! xptr->found) {
 			char *badthing = "WARNING";
-			if (E_ENTRY_NAME && strcmp(xptr->name, E_ENTRY_NAME)) {
+#ifdef PLT_REINITALISATION_BP
+			if (strcmp(xptr->name, PLTs_initialized_by_here) == 0) {
+				if (lte->ehdr.e_entry) {
+					add_library_symbol (
+						elf_plt2addr (lte, (void*)(long)
+							lte->ehdr.e_entry),
+						PLTs_initialized_by_here,
+						lib_tail, 1, 0);
+					fprintf (stderr, "WARNING: Using e_ent"
+						 "ry from elf header (%p) for "
+						 "address of \"%s\"\n", (void*)
+						 (long) lte->ehdr.e_entry,
+						 PLTs_initialized_by_here);
+					continue;
+				}
 				badthing = "ERROR";
 				exit_out = 1;
 			}
+#endif
 			fprintf (stderr,
-				 "%s: Couldn't find symbol \"%s\" in file \"%s\"\n",
-			badthing, xptr->name, proc->filename);
+				 "%s: Couldn't find symbol \"%s\" in file \"%s"
+			         "\"\n", badthing, xptr->name, proc->filename);
 		}
 	if (exit_out) {
 		exit (1);

Modified: ltrace/trunk/ltrace.1
===================================================================
--- ltrace/trunk/ltrace.1	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/ltrace.1	2006-04-24 20:06:23 UTC (rev 40)
@@ -132,7 +132,8 @@
 after the dynamic linker has run.  If this flag is used, then the breakpoint
 is set at
 .IR extern ,
-which must be an external function.  By default, 'main' is used.
+which must be an external function.  By default, '_start' is used.
+NOTE: this flag is only available on the architectures that need it.
 .TP
 .I \-x extern
 Trace the external function

Modified: ltrace/trunk/options.c
===================================================================
--- ltrace/trunk/options.c	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/options.c	2006-04-24 20:06:23 UTC (rev 40)
@@ -53,9 +53,11 @@
 /* List of global function names given to -x: */
 struct opt_x_t *opt_x = NULL;
 
+#ifdef PLT_REINITALISATION_BP
 /* Set a break on the routine named here in order to re-initialize breakpoints
    after all the PLTs have been initialzed */
-char *PLTs_initialized_by_here = PLTs_INIT_BY_HERE;
+char *PLTs_initialized_by_here = PLT_REINITALISATION_BP;
+#endif
 
 static void usage(void)
 {
@@ -120,8 +122,10 @@
 		"  -V                  output version information and exit.\n"
 # endif
 		"  -x NAME             treat the global NAME like a library subroutine.\n"
+#ifdef PLT_REINITALISATION_BP
 		"  -X NAME             same as -x; and PLT's will be initialized by here.\n"
-		"\nReport bugs to Juan Cespedes <cespedes at debian.org>\n",
+#endif
+		"\nReport bugs to ltrace-devel at lists.alioth.debian.org\n",
 		progname);
 #endif
 }
@@ -318,7 +322,12 @@
 			       "version 2 or later for copying conditions.  There is NO warranty.\n");
 			exit(0);
 		case 'X':
+#ifdef PLT_REINITALISATION_BP
 			PLTs_initialized_by_here = optarg;
+#else
+			fprintf(stderr, "WANRING: \"-X\" not used for this "
+				"architecture: assuming you meant \"-x\"\n");
+#endif
 			/* Fall Thru */
 
 		case 'x':

Modified: ltrace/trunk/process_event.c
===================================================================
--- ltrace/trunk/process_event.c	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/process_event.c	2006-04-24 20:06:23 UTC (rev 40)
@@ -332,11 +332,12 @@
 		    get_return_addr(event->proc, event->proc->stack_pointer);
 		output_left(LT_TOF_FUNCTION, event->proc, sbp->libsym->name);
 		callstack_push_symfunc(event->proc, sbp->libsym);
-		if (PLTs_initialized_by_here
-		    && event->proc->need_to_reinitialize_breakpoints
+#ifdef PLT_REINITALISATION_BP
+		if (event->proc->need_to_reinitialize_breakpoints
 		    && (strcmp(sbp->libsym->name, PLTs_initialized_by_here) ==
 			0))
 			reinitialize_breakpoints(event->proc);
+#endif
 
 		continue_after_breakpoint(event->proc, sbp);
 		return;

Modified: ltrace/trunk/sysdeps/linux-gnu/alpha/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/alpha/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/alpha/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -6,6 +6,3 @@
 #define LT_ELF_MACHINE  EM_ALPHA
 #define LT_ELFCLASS2    ELFCLASS64
 #define LT_ELF_MACHINE2	EM_FAKE_ALPHA
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME      "_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/arm/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/arm/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/arm/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -4,6 +4,3 @@
 
 #define LT_ELFCLASS	ELFCLASS32
 #define LT_ELF_MACHINE	EM_ARM
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME    "_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/i386/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/i386/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/i386/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -4,6 +4,3 @@
 
 #define LT_ELFCLASS	ELFCLASS32
 #define LT_ELF_MACHINE	EM_386
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME    "_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/ia64/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/ia64/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/ia64/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -7,6 +7,3 @@
 
 #define LT_ELFCLASS   ELFCLASS64
 #define LT_ELF_MACHINE EM_IA_64
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME	"_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/m68k/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/m68k/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/m68k/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -4,6 +4,3 @@
 
 #define LT_ELFCLASS	ELFCLASS32
 #define LT_ELF_MACHINE	EM_68K
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME    "_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/ppc/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/ppc/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/ppc/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -1,7 +1,6 @@
 #define BREAKPOINT_VALUE { 0x7f, 0xe0, 0x00, 0x08 }
 #define BREAKPOINT_LENGTH 4
 #define DECR_PC_AFTER_BREAK 0
-#define E_ENTRY_NAME    "_start"
 
 #define LT_ELFCLASS	ELFCLASS32
 #define LT_ELF_MACHINE	EM_PPC
@@ -9,10 +8,6 @@
 #define LT_ELFCLASS2	ELFCLASS64
 #define LT_ELF_MACHINE2	EM_PPC64
 
-#define PLTs_INIT_BY_HERE E_ENTRY_NAME
+#define PLT_REINITALISATION_BP    "_start"
 
-#else
-
-#define PLTs_INIT_BY_HERE NULL
-
 #endif

Modified: ltrace/trunk/sysdeps/linux-gnu/s390/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/s390/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/s390/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -16,6 +16,3 @@
 #define LT_ELFCLASS	ELFCLASS32
 #define LT_ELF_MACHINE	EM_S390
 #endif
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME    "_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/sparc/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/sparc/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/sparc/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -6,6 +6,3 @@
 #define LT_ELF_MACHINE  EM_SPARC
 #define LT_ELFCLASS2    ELFCLASS32
 #define LT_ELF_MACHINE2	EM_SPARC32PLUS
-
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME    "_start"

Modified: ltrace/trunk/sysdeps/linux-gnu/x86_64/arch.h
===================================================================
--- ltrace/trunk/sysdeps/linux-gnu/x86_64/arch.h	2006-04-24 16:25:37 UTC (rev 39)
+++ ltrace/trunk/sysdeps/linux-gnu/x86_64/arch.h	2006-04-24 20:06:23 UTC (rev 40)
@@ -7,9 +7,6 @@
 #define LT_ELFCLASS2	ELFCLASS32
 #define LT_ELF_MACHINE2	EM_386
 
-#define PLTs_INIT_BY_HERE NULL
-#define E_ENTRY_NAME    "_start"
-
 /* __NR_fork, __NR_clone, __NR_clone2, __NR_vfork and __NR_execve
    from asm-i386/unistd.h.  */
 #define FORK_EXEC_SYSCALLS , { 2, 120, -1, 190, 11 }




More information about the Ltrace-devel mailing list