Home | History | Annotate | Download | only in elfcopy
      1 #ifndef ELFCOPY_H
      2 #define ELFCOPY_H
      3 
      4 #include <libelf.h>
      5 #include <libebl.h>
      6 #include <elf.h>
      7 #include <gelf.h>
      8 
      9 typedef struct shdr_info_t {
     10 	/* data from original file: */
     11 	Elf_Scn *scn;			/* original section */
     12 	/* Original-section header. */
     13     GElf_Shdr old_shdr;
     14     /* Starts out as the original header, but we modify this variable when we
     15        compose the new section information. */
     16 	GElf_Shdr shdr;
     17     /* This oddly-named flag causes adjust_elf() to look at the size of the
     18        relocation sections before the modification, as opposed to the new
     19        size, in order to determine the number of relocation entries. */
     20     bool use_old_shdr_for_relocation_calculations;
     21 	const char *name;		/* name of the original section */
     22     /* If we do not want to modify a section's data, we set this field to NULL.
     23        This will cause clone_elf() to extract the original section's data and
     24        copy it over to the new section.  If, on the other hand, we do want to
     25        change the data, we call elf_newdata() by ourselves and set *data to
     26        the return value.
     27     */
     28 	Elf_Data *data;
     29     Elf_Data *newdata;
     30 
     31 	/* data for new file  */
     32 
     33 	/* Index in new file. Before we assign numbers to the sections in the
     34 	   new file, the idx field has the following meaning:
     35 		0 -- will strip
     36 		1 -- present but not yet investigated
     37 		2 -- handled (stripped or decided not to stip).
     38 	*/
     39 	Elf32_Word idx;
     40 	Elf_Scn *newscn; /* new section handle */
     41 	struct Ebl_Strent *se; /* contribution to shstr section */
     42 	/* The following three variables are for symbol-table-sections (SHT_DYNSYM
     43        and SHT_SYMTAB).
     44 
     45        newsymidx: contains a mapping between the indices of old symbols and new
     46                   symbols. If a symbol table has changed, then newsymidx !=
     47                   NULL; otherwise, it is NULL.  Thus newsymidx can be used also
     48                   as a flag.
     49 
     50        dynsymst: handle to the new symbol-strings section.
     51 	*/
     52 	Elf32_Word *newsymidx;
     53     struct Ebl_Strtab *dynsymst;
     54     /* The following variable is used by SHT_DYNSYM, SHT_SYMTAB and SHT_DYNAMIC
     55        sections only.  For the symbol tables, this is a parallel array to the
     56        symbol table that stores the symbol name's index into the symbol-strings
     57        table.
     58 
     59        For the dynamic section, this is an array parallel to the array of
     60        structures that the dynamic section is; for each structure that
     61        represents a string field, the element at the same index into symse
     62        contains the offset of that string into the new dynamic-symbol table.
     63     */
     64     struct Ebl_Strent **symse;
     65 } shdr_info_t;
     66 
     67 /*
     68 Symbol_filter:
     69 	On input: symbol_filter[i] indicates whether to keep a symbol (1) or to
     70 	          remove it from the symbol table.
     71     On output: symbol_filter[i] indicates whether a symbol was removed (0) or
     72 	           kept (1) in the symbol table.
     73 */
     74 
     75 void adjust_elf(Elf *elf, const char *elf_name,
     76                 Elf *newelf, const char *newelf_name,
     77                 Ebl *ebl,
     78                 GElf_Ehdr *ehdr, /* store ELF header of original library */
     79                 bool *sym_filter, int num_symbols,
     80                 struct shdr_info_t *shdr_info, int shdr_info_len,
     81                 GElf_Phdr *phdr_info,
     82                 size_t highest_scn_num,
     83                 size_t shnum,
     84                 size_t shstrndx,
     85                 struct Ebl_Strtab *shst,
     86                 bool sections_dropped_or_rearranged,
     87                 int dynamic_idx, /* index in shdr_info[] of .dynamic section */
     88                 int dynsym_idx, /* index in shdr_info[] of dynamic symbol table */
     89                 int shady,
     90                 Elf_Data **shstrtab_data,
     91                 bool adjust_section_offsets,
     92                 bool rebuild_shstrtab);
     93 
     94 #endif/*ELFCOPY_H*/
     95