static void write_resolution (void) { unsigned int i; FILE *f; check (resolution_file, LDPL_FATAL, "resolution file not specified"); f = fopen (resolution_file, "w"); check (f, LDPL_FATAL, "could not open file"); fprintf (f, "%d\n", num_claimed_files); for (i = 0; i < num_claimed_files; i++) { struct plugin_file_info *info = &claimed_files[i]; struct plugin_symtab *symtab = &info->symtab; struct ld_plugin_symbol *syms = symtab->syms; get_symbols (info->handle, symtab->nsyms, syms); finish_conflict_resolution (symtab, &info->conflicts); fprintf (f, "%s %d\n", info->name, symtab->nsyms + info->conflicts.nsyms); dump_symtab (f, symtab); if (info->conflicts.nsyms) { dump_symtab (f, &info->conflicts); free_symtab (&info->conflicts); } } fclose (f); }
void load_symtab(Elf_Ehdr * pehdr, char *pexe) { Elf_Sym *symtab; Elf_Shdr *symsect; int symtabsize; Elf_Shdr *pshdr; Elf_Shdr *psymshdr; char *shname; int i; symtab = NULL; for (i = 0; i < pehdr->e_shnum; i++) { pshdr = (Elf_Shdr *) (pexe + pehdr->e_shoff + (i * pehdr->e_shentsize)); if (SHT_REL != pshdr->sh_type && SHT_RELA != pshdr->sh_type) continue; psymshdr = (Elf_Shdr *) (pexe + pehdr->e_shoff + (pshdr->sh_link * pehdr->e_shentsize)); #ifdef DEBUG fprint_shstr(stdout, pshdr->sh_name); printf("\n"); #endif symtab = (Elf_Sym *) (pexe + psymshdr->sh_offset); symsect = psymshdr; symtabsize = psymshdr->sh_size; #ifdef DEBUG dump_symtab(symsect, symtab, symtabsize); #endif hide_sym(pehdr, symsect, symtab, symtabsize, pshdr->sh_link); } }
void flt_dump_symtab(const char *table_name) { CLASS *p; if (table_name == 0) { dump_init(); for (p = classes; p != 0; p = p->next) { flt_dump_symtab(p->name); } } else if ((p = find_symtab(table_name)) != 0) { dump_update(p->name); flt_message("%ctable %s\n", dump_meta_ch, p->name); dump_symtab(p, dump_class); dump_symtab(p, dump_keyword); } }
static void write_resolution (void) { unsigned int i; FILE *f; check (resolution_file, LDPL_FATAL, "resolution file not specified"); f = fopen (resolution_file, "w"); check (f, LDPL_FATAL, "could not open file"); fprintf (f, "%d\n", num_claimed_files); for (i = 0; i < num_claimed_files; i++) { struct plugin_file_info *info = &claimed_files[i]; struct plugin_symtab *symtab = &info->symtab; struct ld_plugin_symbol *syms = symtab->syms; /* Version 2 of API supports IRONLY_EXP resolution that is accepted by GCC-4.7 and newer. */ if (get_symbols_v2) get_symbols_v2 (info->handle, symtab->nsyms, syms); else get_symbols (info->handle, symtab->nsyms, syms); finish_conflict_resolution (symtab, &info->conflicts); fprintf (f, "%s %d\n", info->name, symtab->nsyms + info->conflicts.nsyms); dump_symtab (f, symtab); if (info->conflicts.nsyms) { dump_symtab (f, &info->conflicts); free_symtab (&info->conflicts); } } fclose (f); }
DEBUG_FUNCTION void debug_symtab (void) { dump_symtab (stderr); }
int show_symtab( char **argv ) { if( *argv ) error_ret("bad args",-1); dump_symtab( get_elf() ); return( COMMAND_SUCCESS ); }
static void test_symtab( void ) { Symbol *sym; SymbolHash *symtab, *symtab2; list_open("test.lst"); opts.symtable = TRUE; opts.list = TRUE; warn("Create current module\n"); set_cur_module( new_module() ); warn("Create symbol\n"); sym = Symbol_create(S("Var1"), 123, TYPE_CONSTANT, 0, NULL, NULL); dump_Symbol(sym); OBJ_DELETE(sym); sym = Symbol_create(S("Var1"), 123, TYPE_CONSTANT, 0, CURRENTMODULE, NULL); dump_Symbol(sym); CURRENTMODULE->modname = "MODULE"; dump_Symbol(sym); warn("Delete symbol\n"); OBJ_DELETE(sym); warn("Global symtab\n"); dump_SymbolHash(global_symtab, "global"); dump_SymbolHash(static_symtab, "static"); warn("check case insensitive - CH_0024\n"); symtab = OBJ_NEW(SymbolHash); assert( symtab ); _define_sym(S("Var1"), 1, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("var1"), 2, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("VAR1"), 3, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); dump_SymbolHash(symtab, "tab1"); assert( find_symbol(S("Var1"), symtab)->value == 1 ); assert( find_symbol(S("var1"), symtab)->value == 2 ); assert( find_symbol(S("VAR1"), symtab)->value == 3 ); dump_SymbolHash(symtab, "tab1"); warn("Concat symbol tables\n"); symtab = OBJ_NEW(SymbolHash); assert( symtab ); _define_sym(S("Var1"), 1, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Var2"), 2, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Var3"), -3, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); dump_SymbolHash(symtab, "tab1"); symtab2 = OBJ_NEW(SymbolHash); assert( symtab2 ); _define_sym(S("Var3"), 3, TYPE_CONSTANT, 0, NULL, NULL, &symtab2); inc_page_nr(); _define_sym(S("Var4"), 4, TYPE_CONSTANT, 0, NULL, NULL, &symtab2); inc_page_nr(); _define_sym(S("Var5"), 5, TYPE_CONSTANT, 0, NULL, NULL, &symtab2); inc_page_nr(); dump_SymbolHash(symtab2, "tab2"); SymbolHash_cat( &symtab, symtab2 ); dump_SymbolHash(symtab, "merged_tab"); OBJ_DELETE( symtab ); OBJ_DELETE( symtab2 ); warn("Sort\n"); symtab = OBJ_NEW(SymbolHash); assert( symtab ); _define_sym(S("One"), 1, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Two"), 2, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Three"), 3, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Four"), 4, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); dump_SymbolHash(symtab, "tab"); SymbolHash_sort(symtab, SymbolHash_by_name); dump_SymbolHash(symtab, "tab by name"); SymbolHash_sort(symtab, SymbolHash_by_value); dump_SymbolHash(symtab, "tab by value"); OBJ_DELETE( symtab ); warn("Use local symbol before definition\n"); _define_sym(S("WIN32"), 1, TYPE_CONSTANT, 0, NULL, NULL, &static_symtab); inc_page_nr(); SymbolHash_cat( & CURRENTMODULE->local_symtab, static_symtab ); inc_page_nr(); _define_sym(S("PC"), 0, TYPE_CONSTANT, 0, NULL, NULL, &global_symtab); inc_page_nr(); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); sym = get_used_symbol(S("NN")); inc_page_nr(); assert( sym != NULL ); assert( ! sym->is_defined ); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); sym = get_used_symbol(S("NN")); inc_page_nr(); assert( sym != NULL ); assert( ! sym->is_defined ); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); sym = define_symbol(S("NN"), find_symbol( "PC", global_symtab )->value, TYPE_ADDRESS); sym->is_touched = TRUE; sym = get_used_symbol(S("NN")); inc_page_nr(); assert( sym != NULL ); dump_Symbol(sym); assert( sym->is_defined ); dump_symtab(); warn("Delete Local\n"); remove_all_local_syms(); dump_symtab(); warn("Delete Static\n"); remove_all_static_syms(); dump_symtab(); warn("Delete Global\n"); remove_all_global_syms(); dump_symtab(); warn("End\n"); }
static int dump_sections(pgcore_t *pgc) { struct ps_prochandle *P = pgc->P; file_info_t *fptr; uint_t cnt; uint_t index = 1; if (!(pgc->pgc_content & (CC_CONTENT_CTF | CC_CONTENT_SYMTAB))) return (0); fptr = list_next(&P->file_head); for (cnt = P->num_files; cnt > 0; cnt--, fptr = list_next(fptr)) { int hit_symtab = 0; Pbuild_file_symtab(P, fptr); if ((pgc->pgc_content & CC_CONTENT_CTF) && Pbuild_file_ctf(P, fptr) != NULL) { sym_tbl_t *sym; uint_t dynsym; uint_t symindex = 0; /* * Write the symtab out first so we can correctly * set the sh_link field in the CTF section header. * symindex will be 0 if there is no corresponding * symbol table section. */ if (fptr->file_ctf_dyn) { sym = &fptr->file_dynsym; dynsym = 1; } else { sym = &fptr->file_symtab; dynsym = 0; hit_symtab = 1; } if (sym->sym_data_pri != NULL && sym->sym_symn != 0 && sym->sym_strs != NULL) { symindex = index; if (dump_symtab(pgc, fptr, index, dynsym) != 0) return (-1); index += 2; } /* * Write the CTF data that we've read out of the * file itself into the core file. */ if (gc_pwrite64(pgc->pgc_fd, fptr->file_ctf_buf, fptr->file_ctf_size, *pgc->pgc_doff) != 0) return (-1); if (write_shdr(pgc, STR_CTF, SHT_PROGBITS, 0, fptr->file_map->map_pmap.pr_vaddr, *pgc->pgc_doff, fptr->file_ctf_size, symindex, 0, 4, 0) != 0) return (-1); index++; *pgc->pgc_doff += roundup(fptr->file_ctf_size, 8); } if ((pgc->pgc_content & CC_CONTENT_SYMTAB) && !hit_symtab && fptr->file_symtab.sym_data_pri != NULL && fptr->file_symtab.sym_symn != 0 && fptr->file_symtab.sym_strs != NULL) { if (dump_symtab(pgc, fptr, index, 0) != 0) return (-1); index += 2; } } return (0); }