This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: [lto] PATCH: Add support for referencing types from function bodies


Mark Mitchell wrote:
> Since Kenny's not going to use DWARF for function bodies, he needs a
> way to reference global entities (i.e., types, functions, and
> variables with static storage duration) from within his function-body
> representation.
>
> This patch provides an interface for doing that.  During emission of
> the function-body representation, when a global reference is required,
> call one of the lto_*_ref functions (e.g., lto_type_ref), and emit the
> reference returned.  Then, when reading a function body, call
> lto_resolve_type_ref to turn that back into a tree.  The interface
> here is functional; the actual representation of bits on disk for the
> referenes is entirely up to the caller.
>
> Kenny, please let me know if you have questions about this.  I've
> only been able to test it very lightly, since the code to actual
> read/write function bodies isn't there yet.  The only part of the
> interface that is actually implemented is that for types.  So, in
> theory, you should now be able to encode a function body that uses
> integer types and no local variables, e.g.:
>
>   int f() { return 7; }
>
>   
And what about field_decls and const_decls (at least for the ones in
enums)?  Seems like I need an interface to access these?

Also is the purpose of the section, so that you can link several .o
files together without merging the type sections.  I assume that each
lto_out_ref will be assembled into a 64 bit
value, 32 bits for the section number and 32 bits for the offset within
the section.  Or do these things need to be bigger for a 64 bit machine?

Kenny



> --
> Mark Mitchell
> CodeSourcery
> mark@codesourcery.com
> (650) 331-3385 x713
>
> 2006-09-03  Mark Mitchell  <mark@codesourcery.com>
>
> 	* gcc/tree.h (SYMTAB_DIE): Remove reference to SDB format in
> 	comments.
> 	* gcc/dwarf2out.c (assign_symbol_name): New function.
> 	(assign_symbol_names): Use it.
> 	(lto_init_ref): New function.
> 	(lto_type_ref): Likewise.
> 	(lto_var_ref): Likewise.
> 	(lto_fn_ref): Likewise.
> 	* gcc/dwarf2out.h (lto_out_ref): New structure.
> 	(lto_type_ref): Declare.
> 	(lto_var_ref): Likewise.
> 	(lto_fn_ref): Likewise.
>
> 2006-09-03  Mark Mitchell  <mark@codesourcery.com>
>
> 	* lto.c (<inttypes.h>): Don't include it.
> 	(lto_context): Don't typedef it.
> 	(lto_resolve_reference): New function.
> 	(lto_read_form): Use it.
> 	(lto_resolve_type_ref): New function.
> 	(lto_resolve_var_ref): Likewise.
> 	(lto_resolve_fn_ref): Likewise.
> 	* lto.h (<inttypes.h>): Include it.
> 	(lto_context): New type.
> 	(lto_ref): New structure.
> 	(lto_resolve_type_ref): Declare.
> 	(lto_resolve_var_ref): Likewise.
> 	(lto_resolve_fn_ref): Likewise.
>
> Index: lto/lto.c
> ===================================================================
> --- lto/lto.c	(revision 116676)
> +++ lto/lto.c	(working copy)
> @@ -30,7 +30,6 @@ Boston, MA 02110-1301, USA.  */
>  #include "cgraph.h"
>  #include "ggc.h"
>  #include "lto.h"
> -#include <inttypes.h>
>  
>  /* References 
>  
> @@ -112,7 +111,7 @@ typedef struct DWARF2_form_data
>  
>  /* Information passed from parent DIEs to child DIEs to give context
>     about the current location in the scope tree.  */
> -typedef struct lto_context
> +struct lto_context
>  {
>    /* The start of the current compilation unit info.  This is right
>       *after* the header, at the beginning of the DIE entries, so if
> @@ -130,7 +129,7 @@ typedef struct lto_context
>    /* If the last DIE read (with lto_read_DIE) was a type, then this
>       field is the type.  NULL otherwise.  */
>    tree type;
> -} lto_context;
> +};
>  
>  /* We can't use DWARF_Internal_CompUnit because it does not track the
>     offset from the beginning of debug_info, which is necessary for
> @@ -584,6 +583,38 @@ find_cu_for_offset (const lto_info_fd *f
>    return fd->units[first - 1];
>  }
>  
> +/* Resolve a reference to the DIE at offset OFFSET.  Returns a pointer
> +   to the DIE, as mapped into memory.  Sets *NEW_CONTEXT to CONTEXT,
> +   or to a newly allocated context corresponding to the DIE referred
> +   to by OFFSET.  If *NEW_CONTEXT != CONTEXT upon return, the caller
> +   must free *NEW_CONTEXT when it is no longer needed.  */
> +static const char *
> +lto_resolve_reference (lto_info_fd *info_fd,
> +		       uint64_t offset,
> +		       const lto_context *context,
> +		       lto_context **new_context)
> +{
> +  DWARF2_CompUnit *cu;
> +  const char *reference;
> +
> +  /* Swap context if necessary.  */
> +  cu = find_cu_for_offset (info_fd, offset);
> +  if (cu != context->cu)
> +    {
> +      *new_context = XCNEW (lto_context);
> +      **new_context = *context;
> +      lto_set_cu_context (*new_context, info_fd, cu);
> +      context = *new_context;
> +    }
> +  /* Resolve reference.  */
> +  reference = (context->cu_start
> +	       + lto_check_size_t_val (offset, "offset too large"));
> +  if (reference >= context->cu_end)
> +    lto_file_corrupt_error ((lto_fd *)info_fd);
> +
> +  return reference;
> +}
> +
>  /* Read the value of the attribute ATTR from INFO_FD.  CONTEXT is as for
>     the DIE readers.  Upon return, *OUT contains the data read,
>     and FORM_CONTEXT is the context necessary to do something with the
> @@ -817,7 +848,6 @@ lto_read_form (lto_info_fd *info_fd, 
>      case DW_FORM_ref_addr:
>        {
>  	uint64_t offset;
> -	DWARF2_CompUnit *cu;
>  
>  	/* The standard says 
>  	   "In the 32-bit DWARF format, this offset is a 4-byte unsigned
> @@ -828,26 +858,13 @@ lto_read_form (lto_info_fd *info_fd, 
>  	  offset = lto_read_uword (fd);
>  	else
>  	  offset = lto_read_udword (fd);
> -	
> -	cu = find_cu_for_offset (info_fd, offset);
> -
> -	/* Swap context if necessary.  */
> -	if (cu != context->cu)
> -	  {
> -	    lto_context *new_context = XCNEW (lto_context);
> -	    
> -	    *new_context = *context;
> -	    
> -	    lto_set_cu_context (new_context, info_fd, cu);
> -	    *form_context = new_context;
> -	  }
>  
>  	out->cl = DW_cl_reference;
>  	out->u.reference 
> -	  = ((*form_context)->cu_start
> -	     + lto_check_size_t_val (offset, "offset too large"));
> -	if (out->u.reference >= (*form_context)->cu_end)
> -	  lto_file_corrupt_error (fd);
> +	  = lto_resolve_reference (info_fd,
> +				   offset,
> +				   context,
> +				   form_context);
>        }
>        break;
>  
> @@ -1723,6 +1740,45 @@ lto_file_read (lto_file *file)
>    return true;
>  }
>  
> +tree 
> +lto_resolve_type_ref (lto_info_fd *info_fd,
> +		      lto_context *context,
> +		      const lto_ref *ref)
> +{
> +  const char *reference;
> +  lto_context *new_context;
> +  tree type;
> +
> +  /* At present, we only support a single DWARF section.  */
> +  if (ref->section != 0)
> +    lto_abi_mismatch_error ();
> +  reference = lto_resolve_reference (info_fd, ref->offset, context,
> +				     &new_context);
> +  /* Resolve the reference.  */
> +  type = lto_read_referenced_type_DIE (info_fd, context, reference);
> +  /* Clean up.  */
> +  if (new_context != context)
> +    XDELETE (new_context);
> +
> +  return type;
> +}
> +
> +tree 
> +lto_resolve_var_ref (lto_info_fd *info_fd ATTRIBUTE_UNUSED,
> +		     lto_context *context ATTRIBUTE_UNUSED,
> +		     const lto_ref *ref ATTRIBUTE_UNUSED)
> +{
> +  abort ();
> +}
> +
> +tree 
> +lto_resolve_fn_ref (lto_info_fd *info_fd ATTRIBUTE_UNUSED,
> +		    lto_context *context ATTRIBUTE_UNUSED,
> +		    const lto_ref *ref ATTRIBUTE_UNUSED)
> +{
> +  abort ();
> +}
> +
>  void
>  lto_main (int debug_p ATTRIBUTE_UNUSED)
>  {
> Index: lto/lto.h
> ===================================================================
> --- lto/lto.h	(revision 116676)
> +++ lto/lto.h	(working copy)
> @@ -25,12 +25,14 @@ Boston, MA 02110-1301, USA.  */
>  /* Included files.  */
>  
>  #include "hashtab.h"
> +#include <inttypes.h>
>  
>  /* Forward Declarations */
>  
>  typedef struct lto_file lto_file;
>  typedef struct DWARF2_abbrev DWARF2_abbrev;
>  typedef struct DWARF2_CompUnit DWARF2_CompUnit;
> +typedef struct lto_context lto_context;
>  
>  /* Types */
>  
> @@ -87,6 +89,15 @@ struct lto_file
>    lto_abbrev_fd debug_abbrev;
>  };
>  
> +/* A reference to a global entity (type, variable, or function).  */
> +typedef struct lto_ref
> +{
> +  /* The DWARF compilation unit containing the entity.  */
> +  unsigned section;
> +  /* The offset of the DIE corresponding to the entity.  */
> +  uint64_t offset;
> +} lto_ref;
> +
>  /* lto.c */
>   
>  /* Read all of the input object files, generate a TREE representation
> @@ -108,6 +119,21 @@ extern void lto_file_close (lto_file *fi
>     processed.  */
>  extern bool lto_file_read (lto_file *file);
>  
> +/* Return the TYPE referred to by REF.  */
> +extern tree lto_resolve_type_ref (lto_info_fd *info_fd,
> +				  lto_context *context,
> +				  const lto_ref *ref);
> +
> +/* Return the VAR_DECL referred to by REF.  */
> +extern tree lto_resolve_var_ref (lto_info_fd *info_fd,
> +				 lto_context *context,
> +				 const lto_ref *ref);
> +
> +/* Return the FUNCTION_DECL referred to by REF.  */
> +extern tree lto_resolve_fn_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 */
>   


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