History

Add function to list all symbols, for purpose of linking separate in-memory compilations

Jan Boon committed 7 years ago

Commit 944c4001 parent c6635503 files · +37 −0Browse files

Unified · Split

3 files
  1. libtcc.h +4 −0
  2. tcc.h +2 −0
  3. tccelf.c +31 −0
libtcc.h+4−0
@@ -93,6 +93,10 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr); · 92 unmodified lines
93/* return symbol value or NULL if not found */93/* return symbol value or NULL if not found */
94LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);94LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
95 95
96/* return symbol value or NULL if not found */
97LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
98 void (*symbol_cb)(void *ctx, const char *name, const void *val));
99
96#ifdef __cplusplus100#ifdef __cplusplus
97}101}
98#endif102#endif
tcc.h+2−0
@@ -1470,6 +1470,8 @@ ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc); · 1469 unmodified lines
1470ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);1470ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
1471 1471
1472ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);1472ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);
1473ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
1474 void (*symbol_cb)(void *ctx, const char *name, const void *val));
1473#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE1475#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
1474ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);1476ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1475#endif1477#endif
tccelf.c+31−0
@@ -471,12 +471,43 @@ ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err) · 470 unmodified lines
471 return sym->st_value;471 return sym->st_value;
472}472}
473 473
474/* list elf symbol names and values */
475ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
476 void (*symbol_cb)(void *ctx, const char *name, const void *val))
477{
478 ElfW(Sym) *sym;
479 Section *symtab;
480 int sym_index, end_sym;
481 const char *name;
482 unsigned char sym_vis, sym_bind;
483
484 symtab = s->symtab;
485 end_sym = symtab->data_offset / sizeof (ElfSym);
486 for (sym_index = 0; sym_index < end_sym; ++sym_index) {
487 sym = &((ElfW(Sym) *)symtab->data)[sym_index];
488 if (sym->st_value) {
489 name = (char *) symtab->link->data + sym->st_name;
490 sym_bind = ELFW(ST_BIND)(sym->st_info);
491 sym_vis = ELFW(ST_VISIBILITY)(sym->st_other);
492 if (sym_bind == STB_GLOBAL && sym_vis == STV_DEFAULT)
493 symbol_cb(ctx, name, (void*)(uintptr_t)sym->st_value);
494 }
495 }
496}
497
474/* return elf symbol value */498/* return elf symbol value */
475LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name)499LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name)
476{500{
477 return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0);501 return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0);
478}502}
479 503
504/* list elf symbol names and values */
505LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
506 void (*symbol_cb)(void *ctx, const char *name, const void *val))
507{
508 list_elf_symbols(s, ctx, symbol_cb);
509}
510
480#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE511#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
481/* return elf symbol value or error */512/* return elf symbol value or error */
482ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name)513ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t