[LTO]: Follow FIELD_DECL references from LTO

Jim Blandy jimb@codesourcery.com
Wed Aug 15 21:10:00 GMT 2007


Here is an (untested) function for Kenny to try that takes an LTO
reference to a field in the DWARF info and finds the appropriate tree.
It looked to me as if all the .debug_info dies had already been turned
into trees anyway, so this was a matter of making sure FIELD_DECLs
were recorded in the die->tree hash table, and then looking them up.

gcc/lto/ChangeLog:
2007-08-15  Jim Blandy  <jimb@codesourcery.com>

	* lto.c (lto_read_member_DIE): Record the tree we create in
	fd->die_cache.  (Our 'die' argument is no longer unused.)
	(lto_resolve_field_ref): New function.
	* lto.h (lto_resolve_field_ref): New declaration.

Index: lto/lto.c
===================================================================
--- lto/lto.c	(revision 127370)
+++ lto/lto.c	(working copy)
@@ -2080,7 +2080,7 @@
 
 static tree
 lto_read_member_DIE (lto_info_fd *fd,
-		     lto_die_ptr die ATTRIBUTE_UNUSED,
+		     lto_die_ptr die,
 		     const DWARF2_abbrev *abbrev,
 		     lto_context *context)
 {
@@ -2266,6 +2266,10 @@
     layout_decl (decl, bitpos_align);
   DECL_CONTEXT (decl) = context->parentdata;
 
+  /* Record our new decl as having come from this die, so we can
+     resolve references to it from lto data.  */
+  lto_cache_store_DIE (fd, die, decl);
+
   /* Now set the offset explicitly.  This bit of code was stolen from the
      Ada front end.  */
   SET_DECL_OFFSET_ALIGN (decl,
@@ -3323,6 +3327,31 @@
   return fn;
 }
 
+tree 
+lto_resolve_field_ref (lto_info_fd *info_fd,
+                       lto_context *context,
+                       const lto_ref *ref)
+{
+  lto_die_ptr die;
+  lto_context *new_context = context;
+  tree field;
+
+  /* At present, we only support a single DWARF section.  */
+  if (ref->section != 0)
+    lto_abi_mismatch_error ();
+  /* Map REF to a DIE.  */
+  die = lto_resolve_reference (info_fd, ref->offset, context, &new_context);
+  /* Map DIE to a variable.  */
+  field = lto_cache_lookup_DIE (info_fd, die, /*skip=*/false);
+  if (!field || TREE_CODE (field) != FIELD_DECL)
+    lto_file_corrupt_error ((lto_fd *)info_fd); 
+  /* Clean up.  */
+  if (new_context != context)
+    XDELETE (new_context);
+
+  return field;
+}
+
 void
 lto_main (int debug_p ATTRIBUTE_UNUSED)
 {
Index: lto/lto.h
===================================================================
--- lto/lto.h	(revision 127370)
+++ lto/lto.h	(working copy)
@@ -158,6 +158,11 @@
 				lto_context *context,
 				const lto_ref *ref);
 
+/* Return the FIELD_DECL referred to by REF.  */
+extern tree lto_resolve_field_ref (lto_info_fd *info_fd,
+				lto_context *context,
+				const lto_ref *ref);
+
 /* lto-elf.c */
 
 /* Open the ELF input file indicated by FILENAME.  Return */



More information about the Gcc-patches mailing list