| @@ -178,7 +178,7 @@ void *tcc_get_symbol_err(TCCState *s, const char *name) · 177 unmodified lines |
| 178 | 178 | /* add an elf symbol : check if it is already defined and patch |
| 179 | 179 | it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */ |
| 180 | 180 | static int add_elf_sym(Section *s, unsigned long value, unsigned long size, |
| 181 | | − int info, int sh_num, const char *name) |
| 181 | + int info, int other, int sh_num, const char *name) |
| 182 | 182 | { |
| 183 | 183 | Elf32_Sym *esym; |
| 184 | 184 | int sym_bind, sym_index, sym_type, esym_bind; |
| @@ -217,11 +217,12 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 32 unmodified lines |
| 217 | 217 | esym->st_shndx = sh_num; |
| 218 | 218 | esym->st_value = value; |
| 219 | 219 | esym->st_size = size; |
| 220 | + esym->st_other = other; |
| 220 | 221 | } |
| 221 | 222 | } else { |
| 222 | 223 | do_def: |
| 223 | 224 | sym_index = put_elf_sym(s, value, size, |
| 224 | | − ELF32_ST_INFO(sym_bind, sym_type), 0, |
| 225 | + ELF32_ST_INFO(sym_bind, sym_type), other, |
| 225 | 226 | sh_num, name); |
| 226 | 227 | } |
| 227 | 228 | return sym_index; |
| @@ -675,7 +676,7 @@ static void build_got(TCCState *s1) · 447 unmodified lines |
| 675 | 676 | s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); |
| 676 | 677 | s1->got->sh_entsize = 4; |
| 677 | 678 | add_elf_sym(symtab_section, 0, 4, ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), |
| 678 | | − s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); |
| 679 | + 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); |
| 679 | 680 | ptr = section_ptr_add(s1->got, 3 * sizeof(int)); |
| 680 | 681 | /* keep space for _DYNAMIC pointer, if present */ |
| 681 | 682 | put32(ptr, 0); |
| @@ -943,11 +944,11 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 261 unmodified lines |
| 943 | 944 | |
| 944 | 945 | add_elf_sym(symtab_section, |
| 945 | 946 | 0, 0, |
| 946 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 947 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 947 | 948 | s->sh_num, sym_start); |
| 948 | 949 | add_elf_sym(symtab_section, |
| 949 | 950 | end_offset, 0, |
| 950 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 951 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 951 | 952 | s->sh_num, sym_end); |
| 952 | 953 | } |
| 953 | 954 | |
| @@ -967,7 +968,7 @@ static void tcc_add_runtime(TCCState *s1) · 13 unmodified lines |
| 967 | 968 | ptr = section_ptr_add(bounds_section, sizeof(unsigned long)); |
| 968 | 969 | *ptr = 0; |
| 969 | 970 | add_elf_sym(symtab_section, 0, 0, |
| 970 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 971 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 971 | 972 | bounds_section->sh_num, "__bounds_start"); |
| 972 | 973 | /* add bound check code */ |
| 973 | 974 | snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "bcheck.o"); |
| @@ -1010,15 +1011,15 @@ static void tcc_add_linker_symbols(TCCState *s1) · 36 unmodified lines |
| 1010 | 1011 | |
| 1011 | 1012 | add_elf_sym(symtab_section, |
| 1012 | 1013 | text_section->data_offset, 0, |
| 1013 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 1014 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 1014 | 1015 | text_section->sh_num, "_etext"); |
| 1015 | 1016 | add_elf_sym(symtab_section, |
| 1016 | 1017 | data_section->data_offset, 0, |
| 1017 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 1018 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 1018 | 1019 | data_section->sh_num, "_edata"); |
| 1019 | 1020 | add_elf_sym(symtab_section, |
| 1020 | 1021 | bss_section->data_offset, 0, |
| 1021 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 1022 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 1022 | 1023 | bss_section->sh_num, "_end"); |
| 1023 | 1024 | /* horrible new standard ldscript defines */ |
| 1024 | 1025 | add_init_array_defines(s1, ".preinit_array"); |
| @@ -1047,12 +1048,12 @@ static void tcc_add_linker_symbols(TCCState *s1) · 22 unmodified lines |
| 1047 | 1048 | snprintf(buf, sizeof(buf), "__start_%s", s->name); |
| 1048 | 1049 | add_elf_sym(symtab_section, |
| 1049 | 1050 | 0, 0, |
| 1050 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 1051 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 1051 | 1052 | s->sh_num, buf); |
| 1052 | 1053 | snprintf(buf, sizeof(buf), "__stop_%s", s->name); |
| 1053 | 1054 | add_elf_sym(symtab_section, |
| 1054 | 1055 | s->data_offset, 0, |
| 1055 | | − ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 1056 | + ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, |
| 1056 | 1057 | s->sh_num, buf); |
| 1057 | 1058 | } |
| 1058 | 1059 | next_sec: ; |
| @@ -1919,7 +1920,8 @@ static int tcc_load_object_file(TCCState *s1, · 860 unmodified lines |
| 1919 | 1920 | /* add symbol */ |
| 1920 | 1921 | name = strtab + sym->st_name; |
| 1921 | 1922 | sym_index = add_elf_sym(symtab_section, sym->st_value, sym->st_size, |
| 1922 | | − sym->st_info, sym->st_shndx, name); |
| 1923 | + sym->st_info, sym->st_other, |
| 1924 | + sym->st_shndx, name); |
| 1923 | 1925 | old_to_new_syms[i] = sym_index; |
| 1924 | 1926 | } |
| 1925 | 1927 | |
| @@ -2093,7 +2095,7 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 167 unmodified lines |
| 2093 | 2095 | { |
| 2094 | 2096 | Elf32_Ehdr ehdr; |
| 2095 | 2097 | Elf32_Shdr *shdr, *sh, *sh1; |
| 2096 | | − int i, nb_syms, nb_dts, sym_bind, ret; |
| 2098 | + int i, nb_syms, nb_dts, sym_bind, ret, other; |
| 2097 | 2099 | Elf32_Sym *sym, *dynsym; |
| 2098 | 2100 | Elf32_Dyn *dt, *dynamic; |
| 2099 | 2101 | unsigned char *dynstr; |
| @@ -2173,8 +2175,15 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 73 unmodified lines |
| 2173 | 2175 | if (sym_bind == STB_LOCAL) |
| 2174 | 2176 | continue; |
| 2175 | 2177 | name = dynstr + sym->st_name; |
| 2178 | +#ifdef TCC_TARGET_PE |
| 2179 | + /* in the PE format we need to know the DLL from which the |
| 2180 | + symbol comes. XXX: add a new array for that ? */ |
| 2181 | + other = s1->nb_loaded_dlls - 1; |
| 2182 | +#else |
| 2183 | + other = sym->st_other; |
| 2184 | +#endif |
| 2176 | 2185 | add_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size, |
| 2177 | | − sym->st_info, sym->st_shndx, name); |
| 2186 | + sym->st_info, other, sym->st_shndx, name); |
| 2178 | 2187 | } |
| 2179 | 2188 | |
| 2180 | 2189 | /* load all referenced DLLs */ |