Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Feb 2008 01:49:08 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 135541 for review
Message-ID:  <200802170149.m1H1n8fm093647@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=135541

Change 135541 by jb@jb_freebsd1 on 2008/02/17 01:48:46

	Add a linker method to get the CTF data and a function to load
	it into the elf_file structure.
	
	I chose to just include kern_ctf.c in both link_elf.c and
	link_elf_obj.c so that it doesn't have to exist twice. There is
	a lot of (annoyingly) similar code in link_elf.c and link_elf_obj.c.
	
	To use the CTF data in DDB, we need a clean-room coder to write
	the code based on what I say the format is.

Affected files ...

.. //depot/projects/dtrace/src/sys/kern/kern_ctf.c#1 add
.. //depot/projects/dtrace/src/sys/kern/kern_linker.c#28 edit
.. //depot/projects/dtrace/src/sys/kern/link_elf.c#15 edit
.. //depot/projects/dtrace/src/sys/kern/link_elf_obj.c#12 edit
.. //depot/projects/dtrace/src/sys/kern/linker_if.m#7 edit
.. //depot/projects/dtrace/src/sys/sys/linker.h#19 edit

Differences ...

==== //depot/projects/dtrace/src/sys/kern/kern_linker.c#28 (text+ko) ====

@@ -647,6 +647,14 @@
 	return (0);
 }
 
+int
+linker_ctf_get(linker_file_t file, const uint8_t **data, int *len)
+{
+	KLD_LOCK_ASSERT();
+
+	return (LINKER_CTF_GET(file, data, len));
+}
+
 static int
 linker_file_add_dependency(linker_file_t file, linker_file_t dep)
 {

==== //depot/projects/dtrace/src/sys/kern/link_elf.c#15 (text+ko) ====

@@ -27,6 +27,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/sys/kern/link_elf.c,v 1.95 2008/01/13 14:44:09 attilio Exp $");
 
+#include "opt_ddb.h"
 #include "opt_gdb.h"
 #include "opt_mac.h"
 
@@ -98,11 +99,15 @@
     long		ddbstrcnt;	/* number of bytes in string table */
     caddr_t		symbase;	/* malloc'ed symbold base */
     caddr_t		strbase;	/* malloc'ed string base */
+    caddr_t		ctftab;		/* CTF table */
+    long		ctfcnt;		/* number of bytes in CTF table */
 #ifdef GDB
     struct link_map	gdb;		/* hooks for gdb */
 #endif
 } *elf_file_t;
 
+#include <kern/kern_ctf.c>
+
 static int	link_elf_link_common_finish(linker_file_t);
 static int	link_elf_link_preload(linker_class_t cls,
 				      const char*, linker_file_t*);
@@ -138,6 +143,7 @@
     KOBJMETHOD(linker_lookup_set,	link_elf_lookup_set),
     KOBJMETHOD(linker_each_function_name, link_elf_each_function_name),
     KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
+    KOBJMETHOD(linker_ctf_get,          link_elf_ctf_get),
     { 0, 0 }
 };
 
@@ -909,6 +915,8 @@
 	free(ef->symbase, M_LINKER);
     if (ef->strbase)
 	free(ef->strbase, M_LINKER);
+    if (ef->ctftab)
+	free(ef->ctftab, M_LINKER);
 }
 
 static void

==== //depot/projects/dtrace/src/sys/kern/link_elf_obj.c#12 (text+ko) ====

@@ -106,8 +106,13 @@
 	caddr_t		shstrtab;	/* Section name string table */
 	long		shstrcnt;	/* number of bytes in string table */
 
+	caddr_t		ctftab;		/* CTF table */
+	long		ctfcnt;		/* number of bytes in CTF table */
+
 } *elf_file_t;
 
+#include <kern/kern_ctf.c>
+
 static int	link_elf_link_preload(linker_class_t cls,
 		    const char *, linker_file_t *);
 static int	link_elf_link_preload_finish(linker_file_t);
@@ -142,6 +147,7 @@
 	KOBJMETHOD(linker_lookup_set,		link_elf_lookup_set),
 	KOBJMETHOD(linker_each_function_name,	link_elf_each_function_name),
 	KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
+	KOBJMETHOD(linker_ctf_get,		link_elf_ctf_get),
 	{ 0, 0 }
 };
 
@@ -815,6 +821,8 @@
 			free(ef->relatab, M_LINKER);
 		if (ef->progtab)
 			free(ef->progtab, M_LINKER);
+		if (ef->ctftab)
+			free(ef->ctftab, M_LINKER);
 		if (file->filename != NULL)
 			preload_delete_name(file->filename);
 		/* XXX reclaim module memory? */
@@ -847,6 +855,8 @@
 		free(ef->ddbstrtab, M_LINKER);
 	if (ef->shstrtab)
 		free(ef->shstrtab, M_LINKER);
+	if (ef->ctftab)
+		free(ef->ctftab, M_LINKER);
 }
 
 static const char *

==== //depot/projects/dtrace/src/sys/kern/linker_if.m#7 (text+ko) ====

@@ -96,6 +96,16 @@
 };
 
 #
+# Load CTF data if necessary and if there is a .SUNW_ctf section
+# in the ELF file, returning a pointer to the data and the length.
+#
+METHOD int ctf_get {
+	linker_file_t	file;
+	const uint8_t	**data;
+	int		*len;
+};
+
+#
 # Load a file, returning the new linker_file_t in *result.  If
 # the class does not recognise the file type, zero should be
 # returned, without modifying *result.  If the file is

==== //depot/projects/dtrace/src/sys/sys/linker.h#19 (text+ko) ====

@@ -266,7 +266,7 @@
 int	elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
 const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx);
 const char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx);
-int sdt_reloc_resolve(uint8_t *, void *);
+int	linker_ctf_get(linker_file_t, const uint8_t **, int *);
 
 int elf_cpu_load_file(linker_file_t);
 int elf_cpu_unload_file(linker_file_t);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802170149.m1H1n8fm093647>