home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / dld / defs.h < prev    next >
C/C++ Source or Header  |  1994-10-02  |  7KB  |  218 lines

  1. /* defs.h -- global definitions. */
  2.  
  3. /* This file is part of DLD, a dynamic link/unlink editor for C.
  4.    
  5.    Copyright (C) 1990 by W. Wilson Ho.
  6.  
  7.    The author can be reached electronically by how@ivy.ucdavis.edu or
  8.    through physical mail at:
  9.  
  10.    W. Wilson Ho
  11.    Division of Computer Science
  12.    University of California at Davis
  13.    Davis, CA 95616
  14.  */
  15.  
  16. /* This program is free software; you can redistribute it and/or modify it
  17.    under the terms of the GNU General Public License as published by the
  18.    Free Software Foundation; either version 1, or (at your option) any
  19.    later version. */
  20.  
  21.  
  22. #include <a.out.h>
  23. #include <ar.h>
  24. #include <stdio.h>
  25. #include <sys/types.h>
  26. #include <strings.h>
  27. #include <sys/stat.h>
  28. #include <sys/file.h>
  29. #include <sys/param.h>
  30. #include <setjmp.h>
  31. #include "dld.h"
  32.  
  33. #ifdef linux
  34. #include <stdlib.h>
  35. #ifndef N_COMM
  36. #define N_COMM 16
  37. #endif
  38. #endif
  39.  
  40.  
  41. /* Each input file, and each library member ("subfile") being loaded,
  42.    has a `file_entry' structure for it.
  43.  
  44.    For files specified by command args, these are contained in the vector
  45.    which `file_table' points to.
  46.  
  47.    For library members, they are dynamically allocated,
  48.    and chained through the `chain' field.
  49.    The chain is found in the `subfiles' field of the `file_entry'.
  50.    The `file_entry' objects for the members have `superfile' fields pointing
  51.    to the one for the library.  */
  52.  
  53. struct file_entry {
  54.     /* Name of this file.  */
  55.     char *filename;
  56.     /* Name to use for the symbol giving address of text start */
  57.     /* Usually the same as filename, but for a file spec'd with -l
  58.        this is the -l switch itself rather than the filename.  */
  59.     char *local_sym_name;
  60.  
  61.     /* For library member, points to next entry for next member.
  62.        For object or library *file*, points to previously loaded entry */
  63.     struct file_entry *chain;
  64.  
  65.     /* number of undefined symbols referenced by this module */
  66.     int undefined_symbol_count;
  67.   
  68.     /* chain of file_entry that defines symbols this file references */
  69.     struct file_chain *refs;
  70.  
  71.     /* chain of file_entry that references symbols defined in this file */
  72.     struct file_chain *refs_by;
  73.   
  74.     /* reference count -- number of entries referenceing myself */
  75.     int ref_count;
  76.     
  77.     /* Describe the layout of the contents of the file */
  78.  
  79.     /* The file's a.out header.  */
  80.     struct exec header;
  81.  
  82.     /* Describe data from the file loaded into core */
  83.  
  84.     /* Symbol table of the file.  */
  85.     struct nlist *symbols;
  86.     /* Size in bytes of string table.  */
  87.     int string_size;
  88.     /* Pointer to the string table.
  89.        The string table is not kept in core all the time,
  90.        but when it is in core, its address is here.  */
  91.     char *strings;
  92.  
  93.     /* Relocation information of the file. */
  94.  
  95.     /* Start of this file's text relocation information. */
  96.     struct dld_reloc_info *text_reloc;
  97.     /* Start of this file's data relocation information. */
  98.     struct dld_reloc_info *data_reloc;
  99.     
  100.     /* Relation of this file's segments to the output buffer */
  101.  
  102.     /* Start of this file's text seg in the output file core image.  */
  103.     int text_start_address;
  104.     /* Start of this file's data seg in the output file core image.  */
  105.     int data_start_address;
  106.     /* Start of this file's bss seg in the output file core image.  */
  107.     int bss_start_address;
  108.  
  109.     /* For library members only */
  110.  
  111.     /* For a library, points to chain of entries for the library members.  */
  112.     struct file_entry *subfiles;
  113.     /* For a library member, offset of the member within the archive.
  114.        Zero for files that are not library members.  */
  115.     int starting_offset;
  116.     /* Size of contents of this file, if library member.  */
  117.     int total_size;
  118.     /* For library member, points to the library's own entry.  */
  119.     struct file_entry *superfile;
  120.  
  121.     /* 1 if file is a library. */
  122.     char library_flag;
  123.  
  124.     /* 1 if file's header has been read into this structure.  */
  125.     char header_read_flag;
  126.  
  127.     /* 1 if this module has all external references resolved */
  128.     char all_symbols_resolved_flag;
  129.   
  130.     /* 1 if functions in this module can be safely executed. */
  131.     char executable_flag;
  132.  
  133.     /* 1 if this module has already been (soft) unlinked. */
  134.     char already_unlink;
  135.     /* 1 means search a set of directories for this file.  */
  136.     /* char search_dirs_flag; */
  137. };
  138.  
  139.  
  140. /* format of file_entry chain */
  141. struct file_chain {
  142.     struct file_chain *next;
  143.     struct file_entry *entry;
  144. };
  145.  
  146. /* Symbol table */
  147.  
  148. /* Global symbol data is recorded in these structures,
  149.    one for each global symbol.
  150.    They are found via hashing in 'symtab', which points to a vector of buckets.
  151.    Each bucket is a chain of these structures through the link field.  */
  152.  
  153. typedef
  154.   struct glosym
  155.     {
  156.       /* Pointer to next symbol in this symbol's hash bucket.  */
  157.       struct glosym *link;
  158.       /* Name of this symbol.  */
  159.       char *name;
  160.       /* Value of this symbol as a global symbol.  */
  161.       long value;
  162. #ifdef linux
  163.       /* Nonzero means that this is an indirect symbol (alias),
  164.      indirect points to the symbol that is referenced */
  165.       struct glosym *indirect;
  166. #endif
  167.       /* Points to the file_entry that defines this symbol */
  168.       struct file_entry *defined_by;
  169.       /* chain of file_entry that contains reference to this symbol */
  170.       struct file_chain *referenced_by;
  171.       /* Nonzero means a definition of this global symbol is known to exist.
  172.      Library members should not be loaded on its account.  */
  173.       char defined;
  174.       /* Nonzero means a reference to this global symbol has been seen
  175.      in a file that is surely being loaded. */
  176.       char referenced;
  177.     }
  178.   symbol;
  179.  
  180. /* Number of buckets in symbol hash table */
  181. #define    TABSIZE    1009
  182.  
  183. /* this is commonly used in removing single linked-list elements. */
  184. #define del_link_list_elt(head, prev, current, next) { \
  185.     if (prev == 0) { \
  186.     head = current->next; \
  187.     free (current); \
  188.     current = head; \
  189.     } else { \
  190.     prev->next = current->next; \
  191.     free (current); \
  192.     current = prev->next; \
  193.     } }
  194.  
  195. /* The symbol hash table: a vector of TABSIZE pointers to struct glosym. */
  196. extern symbol *_dld_symtab[TABSIZE];
  197.  
  198. /* variable for saving the environment */
  199. extern jmp_buf _dld_env;
  200.  
  201. /* pointer to the lastest (newest) file entry */
  202. extern struct file_entry *_dld_latest_entry;
  203.  
  204. /* dummy file_entry to hold all "dangling" symbols. */
  205. extern struct file_entry *_dld_dummy_entry;
  206.  
  207. /* true if the executable flags are up-to-date */
  208. extern char _dld_exec_flags_valid;
  209.  
  210. extern int _dld_malloc ();
  211. extern symbol *_dld_getsym ();
  212. extern symbol *_dld_getsym_soft ();
  213. extern void _dld_enter_global_ref ();
  214. extern void _dld_unlink_entry ();
  215. extern void _dld_create_dummy_entry ();
  216. extern void _dld_patch_all_files ();
  217.  
  218.