History

Rename add_elf_sym to set_elf_sym

add_elf_sym is a confusing name because it is not clear what the function does compared to put_elf_sym. As a matter of fact, put_elf_sym also adds a symbol in a symbol table. Besides, "add_elf_sym" fails to convey that the function can be used to update a symbol (for instance its value). "set_elf_sym" seems like a more appropriate name: it will set a symbol to a given set of properties (value, size, etc.) and create a new one if non exist for that name as one would expect.

Thomas Preud'homme committed 10 years ago

Commit 64b5ee21 parent 9e6610b5 files · +29 −29Browse files

Unified · Split

5 files
  1. libtcc.c +1 −1
  2. tcc.h +1 −1
  3. tccelf.c +24 −24
  4. tccgen.c +1 −1
  5. tccpe.c +2 −2
libtcc.c+1−1
@@ -1199,7 +1199,7 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) · 1198 unmodified lines
11991199 So it is handled here as if it were in a DLL. */
12001200 pe_putimport(s, 0, name, (uintptr_t)val);
12011201 #else
1202− add_elf_sym(symtab_section, (uintptr_t)val, 0,
1202+ set_elf_sym(symtab_section, (uintptr_t)val, 0,
12031203 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
12041204 SHN_ABS, name);
12051205 #endif
tcc.h+1−1
@@ -1339,7 +1339,7 @@ ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_ · 1338 unmodified lines
13391339
13401340 ST_FUNC int put_elf_str(Section *s, const char *sym);
13411341 ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1342−ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int sh_num, const char *name);
1342+ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
13431343 ST_FUNC int find_elf_sym(Section *s, const char *name);
13441344 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
13451345 ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
tccelf.c+24−24
@@ -383,8 +383,8 @@ ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name) · 382 unmodified lines
383383
384384 /* add an elf symbol : check if it is already defined and patch
385385 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
386−ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size,
387− int info, int other, int sh_num, const char *name)
386+ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
387+ int info, int other, int shndx, const char *name)
388388 {
389389 ElfW(Sym) *esym;
390390 int sym_bind, sym_index, sym_type, esym_bind;
@@ -398,7 +398,7 @@ ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, · 7 unmodified lines
398398 esym = &((ElfW(Sym) *)s->data)[sym_index];
399399 if (sym_index && esym->st_value == value && esym->st_size == size
400400 && esym->st_info == info && esym->st_other == other
401− && esym->st_shndx == sh_num)
401+ && esym->st_shndx == shndx)
402402 return sym_index;
403403
404404 if (sym_bind != STB_LOCAL) {
@@ -420,7 +420,7 @@ ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, · 15 unmodified lines
420420 esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1))
421421 | new_vis;
422422 other = esym->st_other; /* in case we have to patch esym */
423− if (sh_num == SHN_UNDEF) {
423+ if (shndx == SHN_UNDEF) {
424424 /* ignore adding of undefined symbol if the
425425 corresponding symbol is already defined */
426426 } else if (sym_bind == STB_GLOBAL && esym_bind == STB_WEAK) {
@@ -434,25 +434,25 @@ ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, · 7 unmodified lines
434434 /* ignore hidden symbols after */
435435 } else if ((esym->st_shndx == SHN_COMMON
436436 || esym->st_shndx == bss_section->sh_num)
437− && (sh_num < SHN_LORESERVE
438− && sh_num != bss_section->sh_num)) {
437+ && (shndx < SHN_LORESERVE
438+ && shndx != bss_section->sh_num)) {
439439 /* data symbol gets precedence over common/bss */
440440 goto do_patch;
441− } else if (sh_num == SHN_COMMON || sh_num == bss_section->sh_num) {
441+ } else if (shndx == SHN_COMMON || shndx == bss_section->sh_num) {
442442 /* data symbol keeps precedence over common/bss */
443443 } else if (s == tcc_state->dynsymtab_section) {
444444 /* we accept that two DLL define the same symbol */
445445 } else {
446446 #if 0
447447 printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n",
448− sym_bind, sh_num, new_vis, esym_bind, esym->st_shndx, esym_vis);
448+ sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis);
449449 #endif
450450 tcc_error_noabort("'%s' defined twice", name);
451451 }
452452 } else {
453453 do_patch:
454454 esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type);
455− esym->st_shndx = sh_num;
455+ esym->st_shndx = shndx;
456456 new_undef_sym = 1;
457457 esym->st_value = value;
458458 esym->st_size = size;
@@ -462,7 +462,7 @@ ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, · 3 unmodified lines
462462 do_def:
463463 sym_index = put_elf_sym(s, value, size,
464464 ELFW(ST_INFO)(sym_bind, sym_type), other,
465− sh_num, name);
465+ shndx, name);
466466 }
467467 return sym_index;
468468 }
@@ -1274,7 +1274,7 @@ static void build_got(TCCState *s1) · 805 unmodified lines
12741274 /* if no got, then create it */
12751275 s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
12761276 s1->got->sh_entsize = 4;
1277− add_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
1277+ set_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
12781278 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_");
12791279 ptr = section_ptr_add(s1->got, 3 * PTR_SIZE);
12801280 #if PTR_SIZE == 4
@@ -1760,11 +1760,11 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 479 unmodified lines
17601760 end_offset = s->data_offset;
17611761 }
17621762
1763− add_elf_sym(symtab_section,
1763+ set_elf_sym(symtab_section,
17641764 0, 0,
17651765 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
17661766 s->sh_num, sym_start);
1767− add_elf_sym(symtab_section,
1767+ set_elf_sym(symtab_section,
17681768 end_offset, 0,
17691769 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
17701770 s->sh_num, sym_end);
@@ -1789,11 +1789,11 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 18 unmodified lines
17891789 /* XXX: add an object file to do that */
17901790 ptr = section_ptr_add(bounds_section, sizeof(*ptr));
17911791 *ptr = 0;
1792− add_elf_sym(symtab_section, 0, 0,
1792+ set_elf_sym(symtab_section, 0, 0,
17931793 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
17941794 bounds_section->sh_num, "__bounds_start");
17951795 /* pull bcheck.o from libtcc1.a */
1796− sym_index = add_elf_sym(symtab_section, 0, 0,
1796+ sym_index = set_elf_sym(symtab_section, 0, 0,
17971797 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
17981798 SHN_UNDEF, "__bound_init");
17991799 if (s1->output_type != TCC_OUTPUT_MEMORY) {
@@ -1838,15 +1838,15 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1) · 38 unmodified lines
18381838 int i;
18391839 Section *s;
18401840
1841− add_elf_sym(symtab_section,
1841+ set_elf_sym(symtab_section,
18421842 text_section->data_offset, 0,
18431843 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
18441844 text_section->sh_num, "_etext");
1845− add_elf_sym(symtab_section,
1845+ set_elf_sym(symtab_section,
18461846 data_section->data_offset, 0,
18471847 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
18481848 data_section->sh_num, "_edata");
1849− add_elf_sym(symtab_section,
1849+ set_elf_sym(symtab_section,
18501850 bss_section->data_offset, 0,
18511851 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
18521852 bss_section->sh_num, "_end");
@@ -1877,12 +1877,12 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1) · 24 unmodified lines
18771877 p++;
18781878 }
18791879 snprintf(buf, sizeof(buf), "__start_%s", s->name);
1880− add_elf_sym(symtab_section,
1880+ set_elf_sym(symtab_section,
18811881 0, 0,
18821882 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
18831883 s->sh_num, buf);
18841884 snprintf(buf, sizeof(buf), "__stop_%s", s->name);
1885− add_elf_sym(symtab_section,
1885+ set_elf_sym(symtab_section,
18861886 s->data_offset, 0,
18871887 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
18881888 s->sh_num, buf);
@@ -2063,7 +2063,7 @@ static void bind_exe_dynsyms(TCCState *s1) · 174 unmodified lines
20632063 } else if (s1->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
20642064 /* if -rdynamic option, then export all non local symbols */
20652065 name = (char *) symtab_section->link->data + sym->st_name;
2066− add_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
2066+ set_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
20672067 0, sym->st_shndx, name);
20682068 }
20692069 }
@@ -2087,7 +2087,7 @@ static void bind_libs_dynsyms(TCCState *s1) · 17 unmodified lines
20872087 -rdynamic ? */
20882088 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
20892089 if (sym_index && sym->st_shndx != SHN_UNDEF)
2090− add_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
2090+ set_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
20912091 0, sym->st_shndx, name);
20922092 else if (esym->st_shndx == SHN_UNDEF) {
20932093 /* weak symbols can stay undefined */
@@ -3159,7 +3159,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 1065 unmodified lines
31593159 }
31603160 /* add symbol */
31613161 name = (char *) strtab + sym->st_name;
3162− sym_index = add_elf_sym(symtab_section, sym->st_value, sym->st_size,
3162+ sym_index = set_elf_sym(symtab_section, sym->st_value, sym->st_size,
31633163 sym->st_info, sym->st_other,
31643164 sym->st_shndx, name);
31653165 old_to_new_syms[i] = sym_index;
@@ -3430,7 +3430,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 264 unmodified lines
34303430 if (sym_bind == STB_LOCAL)
34313431 continue;
34323432 name = (char *) dynstr + sym->st_name;
3433− add_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size,
3433+ set_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size,
34343434 sym->st_info, sym->st_other, sym->st_shndx, name);
34353435 }
34363436
tccgen.c+1−1
@@ -300,7 +300,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 299 unmodified lines
300300 name = get_tok_str(sym->asm_label, NULL);
301301 }
302302 info = ELFW(ST_INFO)(sym_bind, sym_type);
303− sym->c = add_elf_sym(symtab_section, value, size, info, other, sh_num, name);
303+ sym->c = set_elf_sym(symtab_section, value, size, info, other, sh_num, name);
304304 } else {
305305 esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
306306 esym->st_value = value;
tccpe.c+2−2
@@ -1494,7 +1494,7 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2) · 1493 unmodified lines
14941494
14951495 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value)
14961496 {
1497− return add_elf_sym(
1497+ return set_elf_sym(
14981498 s1->dynsymtab_section,
14991499 value,
15001500 dllindex, /* st_size */
@@ -1770,7 +1770,7 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) · 269 unmodified lines
17701770
17711771 /* grab the startup code from libtcc1 */
17721772 if (TCC_OUTPUT_MEMORY != s1->output_type || PE_GUI == pe_type)
1773− add_elf_sym(symtab_section,
1773+ set_elf_sym(symtab_section,
17741774 0, 0,
17751775 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
17761776 SHN_UNDEF, start_symbol);

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