| @@ -383,8 +383,8 @@ ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name) · 382 unmodified lines |
| 383 | | 383 | |
| 384 | /* add an elf symbol : check if it is already defined and patch | 384 | /* add an elf symbol : check if it is already defined and patch |
| 385 | it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */ | 385 | 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, | 386 | ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, |
| 387 | int info, int other, int sh_num, const char *name) | 387 | int info, int other, int shndx, const char *name) |
| 388 | { | 388 | { |
| 389 | ElfW(Sym) *esym; | 389 | ElfW(Sym) *esym; |
| 390 | int sym_bind, sym_index, sym_type, esym_bind; | 390 | 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 |
| 398 | esym = &((ElfW(Sym) *)s->data)[sym_index]; | 398 | esym = &((ElfW(Sym) *)s->data)[sym_index]; |
| 399 | if (sym_index && esym->st_value == value && esym->st_size == size | 399 | if (sym_index && esym->st_value == value && esym->st_size == size |
| 400 | && esym->st_info == info && esym->st_other == other | 400 | && esym->st_info == info && esym->st_other == other |
| 401 | && esym->st_shndx == sh_num) | 401 | && esym->st_shndx == shndx) |
| 402 | return sym_index; | 402 | return sym_index; |
| 403 | | 403 | |
| 404 | if (sym_bind != STB_LOCAL) { | 404 | 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 |
| 420 | esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1)) | 420 | esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1)) |
| 421 | | new_vis; | 421 | | new_vis; |
| 422 | other = esym->st_other; /* in case we have to patch esym */ | 422 | other = esym->st_other; /* in case we have to patch esym */ |
| 423 | if (sh_num == SHN_UNDEF) { | 423 | if (shndx == SHN_UNDEF) { |
| 424 | /* ignore adding of undefined symbol if the | 424 | /* ignore adding of undefined symbol if the |
| 425 | corresponding symbol is already defined */ | 425 | corresponding symbol is already defined */ |
| 426 | } else if (sym_bind == STB_GLOBAL && esym_bind == STB_WEAK) { | 426 | } 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 |
| 434 | /* ignore hidden symbols after */ | 434 | /* ignore hidden symbols after */ |
| 435 | } else if ((esym->st_shndx == SHN_COMMON | 435 | } else if ((esym->st_shndx == SHN_COMMON |
| 436 | || esym->st_shndx == bss_section->sh_num) | 436 | || esym->st_shndx == bss_section->sh_num) |
| 437 | && (sh_num < SHN_LORESERVE | 437 | && (shndx < SHN_LORESERVE |
| 438 | && sh_num != bss_section->sh_num)) { | 438 | && shndx != bss_section->sh_num)) { |
| 439 | /* data symbol gets precedence over common/bss */ | 439 | /* data symbol gets precedence over common/bss */ |
| 440 | goto do_patch; | 440 | 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) { |
| 442 | /* data symbol keeps precedence over common/bss */ | 442 | /* data symbol keeps precedence over common/bss */ |
| 443 | } else if (s == tcc_state->dynsymtab_section) { | 443 | } else if (s == tcc_state->dynsymtab_section) { |
| 444 | /* we accept that two DLL define the same symbol */ | 444 | /* we accept that two DLL define the same symbol */ |
| 445 | } else { | 445 | } else { |
| 446 | #if 0 | 446 | #if 0 |
| 447 | printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n", | 447 | 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); |
| 449 | #endif | 449 | #endif |
| 450 | tcc_error_noabort("'%s' defined twice", name); | 450 | tcc_error_noabort("'%s' defined twice", name); |
| 451 | } | 451 | } |
| 452 | } else { | 452 | } else { |
| 453 | do_patch: | 453 | do_patch: |
| 454 | esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type); | 454 | esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type); |
| 455 | esym->st_shndx = sh_num; | 455 | esym->st_shndx = shndx; |
| 456 | new_undef_sym = 1; | 456 | new_undef_sym = 1; |
| 457 | esym->st_value = value; | 457 | esym->st_value = value; |
| 458 | esym->st_size = size; | 458 | 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 |
| 462 | do_def: | 462 | do_def: |
| 463 | sym_index = put_elf_sym(s, value, size, | 463 | sym_index = put_elf_sym(s, value, size, |
| 464 | ELFW(ST_INFO)(sym_bind, sym_type), other, | 464 | ELFW(ST_INFO)(sym_bind, sym_type), other, |
| 465 | sh_num, name); | 465 | shndx, name); |
| 466 | } | 466 | } |
| 467 | return sym_index; | 467 | return sym_index; |
| 468 | } | 468 | } |
| @@ -1274,7 +1274,7 @@ static void build_got(TCCState *s1) · 805 unmodified lines |
| 1274 | /* if no got, then create it */ | 1274 | /* if no got, then create it */ |
| 1275 | s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); | 1275 | s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); |
| 1276 | s1->got->sh_entsize = 4; | 1276 | 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), |
| 1278 | 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); | 1278 | 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); |
| 1279 | ptr = section_ptr_add(s1->got, 3 * PTR_SIZE); | 1279 | ptr = section_ptr_add(s1->got, 3 * PTR_SIZE); |
| 1280 | #if PTR_SIZE == 4 | 1280 | #if PTR_SIZE == 4 |
| @@ -1760,11 +1760,11 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 479 unmodified lines |
| 1760 | end_offset = s->data_offset; | 1760 | end_offset = s->data_offset; |
| 1761 | } | 1761 | } |
| 1762 | | 1762 | |
| 1763 | add_elf_sym(symtab_section, | 1763 | set_elf_sym(symtab_section, |
| 1764 | 0, 0, | 1764 | 0, 0, |
| 1765 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1765 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1766 | s->sh_num, sym_start); | 1766 | s->sh_num, sym_start); |
| 1767 | add_elf_sym(symtab_section, | 1767 | set_elf_sym(symtab_section, |
| 1768 | end_offset, 0, | 1768 | end_offset, 0, |
| 1769 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1769 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1770 | s->sh_num, sym_end); | 1770 | s->sh_num, sym_end); |
| @@ -1789,11 +1789,11 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 18 unmodified lines |
| 1789 | /* XXX: add an object file to do that */ | 1789 | /* XXX: add an object file to do that */ |
| 1790 | ptr = section_ptr_add(bounds_section, sizeof(*ptr)); | 1790 | ptr = section_ptr_add(bounds_section, sizeof(*ptr)); |
| 1791 | *ptr = 0; | 1791 | *ptr = 0; |
| 1792 | add_elf_sym(symtab_section, 0, 0, | 1792 | set_elf_sym(symtab_section, 0, 0, |
| 1793 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1793 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1794 | bounds_section->sh_num, "__bounds_start"); | 1794 | bounds_section->sh_num, "__bounds_start"); |
| 1795 | /* pull bcheck.o from libtcc1.a */ | 1795 | /* 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, |
| 1797 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1797 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1798 | SHN_UNDEF, "__bound_init"); | 1798 | SHN_UNDEF, "__bound_init"); |
| 1799 | if (s1->output_type != TCC_OUTPUT_MEMORY) { | 1799 | if (s1->output_type != TCC_OUTPUT_MEMORY) { |
| @@ -1838,15 +1838,15 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1) · 38 unmodified lines |
| 1838 | int i; | 1838 | int i; |
| 1839 | Section *s; | 1839 | Section *s; |
| 1840 | | 1840 | |
| 1841 | add_elf_sym(symtab_section, | 1841 | set_elf_sym(symtab_section, |
| 1842 | text_section->data_offset, 0, | 1842 | text_section->data_offset, 0, |
| 1843 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1843 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1844 | text_section->sh_num, "_etext"); | 1844 | text_section->sh_num, "_etext"); |
| 1845 | add_elf_sym(symtab_section, | 1845 | set_elf_sym(symtab_section, |
| 1846 | data_section->data_offset, 0, | 1846 | data_section->data_offset, 0, |
| 1847 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1847 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1848 | data_section->sh_num, "_edata"); | 1848 | data_section->sh_num, "_edata"); |
| 1849 | add_elf_sym(symtab_section, | 1849 | set_elf_sym(symtab_section, |
| 1850 | bss_section->data_offset, 0, | 1850 | bss_section->data_offset, 0, |
| 1851 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1851 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1852 | bss_section->sh_num, "_end"); | 1852 | bss_section->sh_num, "_end"); |
| @@ -1877,12 +1877,12 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1) · 24 unmodified lines |
| 1877 | p++; | 1877 | p++; |
| 1878 | } | 1878 | } |
| 1879 | snprintf(buf, sizeof(buf), "__start_%s", s->name); | 1879 | snprintf(buf, sizeof(buf), "__start_%s", s->name); |
| 1880 | add_elf_sym(symtab_section, | 1880 | set_elf_sym(symtab_section, |
| 1881 | 0, 0, | 1881 | 0, 0, |
| 1882 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1882 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1883 | s->sh_num, buf); | 1883 | s->sh_num, buf); |
| 1884 | snprintf(buf, sizeof(buf), "__stop_%s", s->name); | 1884 | snprintf(buf, sizeof(buf), "__stop_%s", s->name); |
| 1885 | add_elf_sym(symtab_section, | 1885 | set_elf_sym(symtab_section, |
| 1886 | s->data_offset, 0, | 1886 | s->data_offset, 0, |
| 1887 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, | 1887 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1888 | s->sh_num, buf); | 1888 | s->sh_num, buf); |
| @@ -2063,7 +2063,7 @@ static void bind_exe_dynsyms(TCCState *s1) · 174 unmodified lines |
| 2063 | } else if (s1->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { | 2063 | } else if (s1->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { |
| 2064 | /* if -rdynamic option, then export all non local symbols */ | 2064 | /* if -rdynamic option, then export all non local symbols */ |
| 2065 | name = (char *) symtab_section->link->data + sym->st_name; | 2065 | 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, |
| 2067 | 0, sym->st_shndx, name); | 2067 | 0, sym->st_shndx, name); |
| 2068 | } | 2068 | } |
| 2069 | } | 2069 | } |
| @@ -2087,7 +2087,7 @@ static void bind_libs_dynsyms(TCCState *s1) · 17 unmodified lines |
| 2087 | -rdynamic ? */ | 2087 | -rdynamic ? */ |
| 2088 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; | 2088 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 2089 | if (sym_index && sym->st_shndx != SHN_UNDEF) | 2089 | 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, |
| 2091 | 0, sym->st_shndx, name); | 2091 | 0, sym->st_shndx, name); |
| 2092 | else if (esym->st_shndx == SHN_UNDEF) { | 2092 | else if (esym->st_shndx == SHN_UNDEF) { |
| 2093 | /* weak symbols can stay undefined */ | 2093 | /* weak symbols can stay undefined */ |
| @@ -3159,7 +3159,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 1065 unmodified lines |
| 3159 | } | 3159 | } |
| 3160 | /* add symbol */ | 3160 | /* add symbol */ |
| 3161 | name = (char *) strtab + sym->st_name; | 3161 | 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, |
| 3163 | sym->st_info, sym->st_other, | 3163 | sym->st_info, sym->st_other, |
| 3164 | sym->st_shndx, name); | 3164 | sym->st_shndx, name); |
| 3165 | old_to_new_syms[i] = sym_index; | 3165 | 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 |
| 3430 | if (sym_bind == STB_LOCAL) | 3430 | if (sym_bind == STB_LOCAL) |
| 3431 | continue; | 3431 | continue; |
| 3432 | name = (char *) dynstr + sym->st_name; | 3432 | 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, |
| 3434 | sym->st_info, sym->st_other, sym->st_shndx, name); | 3434 | sym->st_info, sym->st_other, sym->st_shndx, name); |
| 3435 | } | 3435 | } |
| 3436 | | 3436 | |