History

versym cleanup

get rid of some globals, in the first place. Also, for the PE target, ifdef out ELF executable creation.

grischka committed 6 years ago

Commit df349dd1 parent 4d297d39 files · +187 −168Browse files

Unified · Split

9 files
  1. arm-link.c +0 −3
  2. arm64-link.c +0 −3
  3. c67-link.c +0 −3
  4. i386-link.c +2 −11
  5. riscv64-link.c +0 −6
  6. tcc.h +19 −2
  7. tccelf.c +162 −129
  8. tccrun.c +2 −0
  9. x86_64-link.c +2 −11
arm-link.c+0−3
@@ -165,9 +165,6 @@ ST_FUNC void relocate_plt(TCCState *s1) · 164 unmodified lines
165165 }
166166 }
167167
168−void relocate_init(Section *sr) {}
169−void relocate_fini(Section *sr) {}
170−
171168 void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
172169 {
173170 ElfW(Sym) *sym;
arm64-link.c+0−3
@@ -152,9 +152,6 @@ ST_FUNC void relocate_plt(TCCState *s1) · 151 unmodified lines
152152 }
153153 }
154154
155−void relocate_init(Section *sr) {}
156−void relocate_fini(Section *sr) {}
157−
158155 void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
159156 {
160157 int sym_index = ELFW(R_SYM)(rel->r_info);
c67-link.c+0−3
@@ -95,9 +95,6 @@ ST_FUNC void relocate_plt(TCCState *s1) · 94 unmodified lines
9595 }
9696 }
9797
98−void relocate_init(Section *sr) {}
99−void relocate_fini(Section *sr) {}
100−
10198 void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
10299 {
103100 switch(type) {
i386-link.c+2−11
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222
2323 #include "tcc.h"
2424
25+#ifndef ELF_OBJ_ONLY
2526 /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
2627 relocations, returns -1. */
2728 int code_reloc (int reloc_type)
@@ -152,17 +153,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 124 unmodified lines
152153 }
153154 }
154155 }
155−
156−static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
157−
158−void relocate_init(Section *sr)
159−{
160− qrel = (ElfW_Rel *) sr->data;
161−}
162−
163−void relocate_fini(Section *sr)
164−{
165−}
156+#endif
166157
167158 void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
168159 {
riscv64-link.c+0−6
@@ -161,12 +161,6 @@ ST_FUNC void relocate_plt(TCCState *s1) · 160 unmodified lines
161161 }
162162 }
163163
164−void relocate_init(Section *sr) {}
165−
166−void relocate_fini(Section *sr)
167−{
168−}
169−
170164 struct pcrel_hi {
171165 addr_t addr, val;
172166 };
tcc.h+19−2
@@ -824,6 +824,9 @@ struct TCCState { · 823 unmodified lines
824824 /* extra attributes (eg. GOT/PLT value) for symtab symbols */
825825 struct sym_attr *sym_attrs;
826826 int nb_sym_attrs;
827+ /* ptr to next reloc entry reused */
828+ ElfW_Rel *qrel;
829+# define qrel s1->qrel
827830
828831 #ifdef TCC_TARGET_PE
829832 /* PE info */
@@ -837,6 +840,17 @@ struct TCCState { · 7 unmodified lines
837840 int uw_sym;
838841 unsigned uw_offs;
839842 # endif
843+# define ELF_OBJ_ONLY
844+#endif
845+
846+#ifndef ELF_OBJ_ONLY
847+ int nb_sym_versions;
848+ struct sym_version *sym_versions;
849+ int nb_sym_to_version;
850+ int *sym_to_version;
851+ int dt_verneednum;
852+ Section *versym_section;
853+ Section *verneed_section;
840854 #endif
841855
842856 #ifdef TCC_IS_NATIVE
@@ -1475,7 +1489,9 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset · 632 unmodified lines
14751489 ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte);
14761490 ST_FUNC void tcc_add_runtime(TCCState *s1);
14771491
1492+#ifndef ELF_OBJ_ONLY
14781493 ST_FUNC void build_got_entries(TCCState *s1);
1494+#endif
14791495 ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
14801496 ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
14811497
@@ -1506,12 +1522,13 @@ enum gotplt_entry { · 24 unmodified lines
15061522 ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
15071523 };
15081524
1525+#ifndef ELF_OBJ_ONLY
15091526 ST_FUNC int code_reloc (int reloc_type);
15101527 ST_FUNC int gotplt_entry_type (int reloc_type);
15111528 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
1512−ST_FUNC void relocate_init(Section *sr);
1513−ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
15141529 ST_FUNC void relocate_plt(TCCState *s1);
1530+#endif
1531+ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
15151532
15161533 /* ------------ xxx-gen.c ------------ */
15171534
tccelf.c+162−129
@@ -49,13 +49,14 @@ struct sym_version { · 48 unmodified lines
4949 int out_index;
5050 int prev_same_lib;
5151 };
52−static int nb_sym_versions;
53−static struct sym_version *sym_versions;
54−static int nb_sym_to_version;
55−static int *sym_to_version;
56−static int dt_verneednum;
57−static Section *versym_section;
58−static Section *verneed_section;
52+
53+#define nb_sym_versions s1->nb_sym_versions
54+#define sym_versions s1->sym_versions
55+#define nb_sym_to_version s1->nb_sym_to_version
56+#define sym_to_version s1->sym_to_version
57+#define dt_verneednum s1->dt_verneednum
58+#define versym_section s1->versym_section
59+#define verneed_section s1->verneed_section
5960
6061 /* XXX: avoid static variable */
6162 static int new_undef_sym = 0; /* Is there a new undefined sym since last new_undef_sym() */
@@ -76,9 +77,6 @@ ST_FUNC void tccelf_new(TCCState *s) · 14 unmodified lines
7677 text_section = new_section(s, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
7778 data_section = new_section(s, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
7879 bss_section = new_section(s, ".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
79− versym_section = new_section(s, ".gnu.version", SHT_GNU_versym, SHF_ALLOC);
80− versym_section->sh_entsize = sizeof(ElfW(Half));
81− verneed_section = new_section(s, ".gnu.version_r", SHT_GNU_verneed, SHF_ALLOC);
8280 common_section = new_section(s, ".common", SHT_NOBITS, SHF_PRIVATE);
8381 common_section->sh_num = SHN_COMMON;
8482
@@ -126,17 +124,15 @@ ST_FUNC void tccelf_delete(TCCState *s1) · 41 unmodified lines
126124 {
127125 int i;
128126
127+#ifndef ELF_OBJ_ONLY
129128 /* free symbol versions */
130129 for (i = 0; i < nb_sym_versions; i++) {
131130 tcc_free(sym_versions[i].version);
132131 tcc_free(sym_versions[i].lib);
133132 }
134133 tcc_free(sym_versions);
135− sym_versions = NULL;
136− nb_sym_versions = 0;
137134 tcc_free(sym_to_version);
138− sym_to_version = NULL;
139− nb_sym_to_version = 0;
135+#endif
140136
141137 /* free all sections */
142138 for(i = 1; i < s1->nb_sections; i++)
@@ -556,6 +552,7 @@ ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name) · 413 unmodified lines
556552 }
557553 #endif
558554
555+#ifndef ELF_OBJ_ONLY
559556 static void
560557 version_add (TCCState *s)
561558 {
@@ -566,6 +563,15 @@ version_add (TCCState *s) · 4 unmodified lines
566563 int sym_index, end_sym, nb_versions = 2, nb_entries = 0;
567564 ElfW(Half) *versym;
568565 const char *name;
566+ TCCState *s1 = s;
567+
568+ if (0 == nb_sym_versions)
569+ return;
570+ versym_section = new_section(s1, ".gnu.version", SHT_GNU_versym, SHF_ALLOC);
571+ versym_section->sh_entsize = sizeof(ElfW(Half));
572+ verneed_section = new_section(s1, ".gnu.version_r", SHT_GNU_verneed, SHF_ALLOC);
573+ versym_section->link = s1->dynsym;
574+ verneed_section->link = s1->dynsym->link;
569575
570576 /* add needed symbols */
571577 symtab = s->dynsym;
@@ -590,7 +596,7 @@ version_add (TCCState *s) · 18 unmodified lines
590596 struct sym_version *sv = &sym_versions[i];
591597 int n_same_libs = 0, prev;
592598 size_t vnofs;
593− ElfW(Vernaux) *vna = vna;
599+ ElfW(Vernaux) *vna = 0;
594600 if (sv->out_index < 1)
595601 continue;
596602 vnofs = section_add(verneed_section, sizeof(*vn), 1);
@@ -623,6 +629,7 @@ version_add (TCCState *s) · 26 unmodified lines
623629 verneed_section->sh_info = nb_entries;
624630 dt_verneednum = nb_entries;
625631 }
632+#endif
626633
627634 /* add an elf symbol : check if it is already defined and patch
628635 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
@@ -970,7 +977,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 341 unmodified lines
970977 unsigned char *ptr;
971978 addr_t tgt, addr;
972979
973− relocate_init(sr);
980+ qrel = (ElfW_Rel *)sr->data;
974981
975982 for_each_elem(sr, 0, rel, ElfW_Rel) {
976983 ptr = s->data + rel->r_offset;
@@ -989,6 +996,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 12 unmodified lines
989996 sr->link = s1->dynsym;
990997 }
991998
999+#ifndef ELF_OBJ_ONLY
9921000 /* relocate relocation table in 'sr' */
9931001 static void relocate_rel(TCCState *s1, Section *sr)
9941002 {
@@ -1255,6 +1263,7 @@ static void put_dt(Section *dynamic, int dt, addr_t val) · 260 unmodified lines
12551263 dyn->d_tag = dt;
12561264 dyn->d_un.d_val = val;
12571265 }
1266+#endif
12581267
12591268 static void add_init_array_defines(TCCState *s1, const char *section_name)
12601269 {
@@ -1459,6 +1468,7 @@ static void tcc_output_binary(TCCState *s1, FILE *f, · 198 unmodified lines
14591468 }
14601469 }
14611470
1471+#ifndef ELF_OBJ_ONLY
14621472 ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel)
14631473 {
14641474 int sym_index = ELFW(R_SYM) (rel->r_info);
@@ -1661,6 +1671,7 @@ static void export_global_syms(TCCState *s1) · 196 unmodified lines
16611671 }
16621672 }
16631673 }
1674+#endif
16641675
16651676 /* Allocate strings for section names and decide if an unallocated section
16661677 should be output.
@@ -1676,6 +1687,7 @@ static int alloc_sec_names(TCCState *s1, int file_type, Section *strsec) · 9 unmodified lines
16761687 s = s1->sections[i];
16771688 /* when generating a DLL, we include relocations but we may
16781689 patch them */
1690+#ifndef ELF_OBJ_ONLY
16791691 if (file_type == TCC_OUTPUT_DLL &&
16801692 s->sh_type == SHT_RELX &&
16811693 !(s->sh_flags & SHF_ALLOC) &&
@@ -1683,7 +1695,9 @@ static int alloc_sec_names(TCCState *s1, int file_type, Section *strsec) · 1 unmodified line
16831695 prepare_dynamic_rel(s1, s)) {
16841696 if (s1->sections[s->sh_info]->sh_flags & SHF_EXECINSTR)
16851697 textrel = 1;
1686− } else if ((s1->do_debug && s->sh_type != SHT_RELX) ||
1698+ } else
1699+#endif
1700+ if ((s1->do_debug && s->sh_type != SHT_RELX) ||
16871701 file_type == TCC_OUTPUT_OBJ ||
16881702 (s->sh_flags & SHF_ALLOC) ||
16891703 i == (s1->nb_sections - 1)) {
@@ -1890,6 +1904,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 200 unmodified lines
18901904 return file_offset;
18911905 }
18921906
1907+#ifndef ELF_OBJ_ONLY
18931908 static void fill_unloadable_phdr(ElfW(Phdr) *phdr, int phnum, Section *interp,
18941909 Section *dynamic)
18951910 {
@@ -1964,9 +1979,11 @@ static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf) · 68 unmodified lines
19641979 put_dt(dynamic, DT_RELENT, sizeof(ElfW_Rel));
19651980 #endif
19661981 #endif
1967− put_dt(dynamic, DT_VERNEED, verneed_section->sh_addr);
1968− put_dt(dynamic, DT_VERNEEDNUM, dt_verneednum);
1969− put_dt(dynamic, DT_VERSYM, versym_section->sh_addr);
1982+ if (versym_section) {
1983+ put_dt(dynamic, DT_VERNEED, verneed_section->sh_addr);
1984+ put_dt(dynamic, DT_VERNEEDNUM, dt_verneednum);
1985+ put_dt(dynamic, DT_VERSYM, versym_section->sh_addr);
1986+ }
19701987 s = find_section_create (s1, ".preinit_array", 0);
19711988 if (s && s->data_offset) {
19721989 put_dt(dynamic, DT_PREINIT_ARRAY, s->sh_addr);
@@ -2026,6 +2043,7 @@ static int final_sections_reloc(TCCState *s1) · 53 unmodified lines
20262043 }
20272044 return 0;
20282045 }
2046+#endif
20292047
20302048 /* Create an ELF file on disk.
20312049 This function handle ELF specific layout requirements */
@@ -2183,6 +2201,7 @@ static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum, · 151 unmodified lines
21832201 return 0;
21842202 }
21852203
2204+#ifndef ELF_OBJ_ONLY
21862205 /* Sort section headers by assigned sh_addr, remove sections
21872206 that we aren't going to output. */
21882207 static void tidy_section_headers(TCCState *s1, int *sec_order)
@@ -2228,17 +2247,16 @@ static void tidy_section_headers(TCCState *s1, int *sec_order) · 39 unmodified lines
22282247 s1->nb_sections = nnew;
22292248 tcc_free(backmap);
22302249 }
2250+#endif
22312251
22322252 /* Output an elf, coff or binary file */
22332253 /* XXX: suppress unneeded sections */
22342254 static int elf_output_file(TCCState *s1, const char *filename)
22352255 {
2236− int i, ret, phnum, shnum, file_type, file_offset, *sec_order;
2256+ int ret, phnum, shnum, file_type, file_offset, *sec_order;
22372257 struct dyn_inf dyninf = {0};
22382258 ElfW(Phdr) *phdr;
2239− ElfW(Sym) *sym;
22402259 Section *strsec, *interp, *dynamic, *dynstr;
2241− int textrel;
22422260
22432261 file_type = s1->output_type;
22442262 s1->nb_errors = 0;
@@ -2246,8 +2264,8 @@ static int elf_output_file(TCCState *s1, const char *filename) · 1 unmodified line
22462264 phdr = NULL;
22472265 sec_order = NULL;
22482266 interp = dynamic = dynstr = NULL; /* avoid warning */
2249− textrel = 0;
22502267
2268+#ifndef ELF_OBJ_ONLY
22512269 if (file_type != TCC_OUTPUT_OBJ) {
22522270 /* if linking, also link in runtime libraries (libc, libgcc, etc.) */
22532271 tcc_add_runtime(s1);
@@ -2272,9 +2290,6 @@ static int elf_output_file(TCCState *s1, const char *filename) · 18 unmodified lines
22722290 ".dynstr",
22732291 ".hash", SHF_ALLOC);
22742292 dynstr = s1->dynsym->link;
2275− versym_section->link = s1->dynsym;
2276− verneed_section->link = dynstr;
2277−
22782293 /* add dynamic section */
22792294 dynamic = new_section(s1, ".dynamic", SHT_DYNAMIC,
22802295 SHF_ALLOC | SHF_WRITE);
@@ -2296,15 +2311,18 @@ static int elf_output_file(TCCState *s1, const char *filename) · 15 unmodified lines
22962311 build_got_entries(s1);
22972312 version_add (s1);
22982313 }
2314+#endif
22992315
23002316 /* we add a section for symbols */
23012317 strsec = new_section(s1, ".shstrtab", SHT_STRTAB, 0);
23022318 put_elf_str(strsec, "");
23032319
23042320 /* Allocate strings for section names */
2305− textrel = alloc_sec_names(s1, file_type, strsec);
2321+ ret = alloc_sec_names(s1, file_type, strsec);
23062322
2323+#ifndef ELF_OBJ_ONLY
23072324 if (dynamic) {
2325+ int i;
23082326 /* add a list of needed dlls */
23092327 for(i = 0; i < s1->nb_loaded_dlls; i++) {
23102328 DLLReference *dllref = s1->loaded_dlls[i];
@@ -2321,7 +2339,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 10 unmodified lines
23212339 put_dt(dynamic, DT_SONAME, put_elf_str(dynstr, s1->soname));
23222340 /* XXX: currently, since we do not handle PIC code, we
23232341 must relocate the readonly segments */
2324− if (textrel)
2342+ if (ret)
23252343 put_dt(dynamic, DT_TEXTREL, 0);
23262344 }
23272345
@@ -2336,6 +2354,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 8 unmodified lines
23362354 dynamic->sh_size = dynamic->data_offset;
23372355 dynstr->sh_size = dynstr->data_offset;
23382356 }
2357+#endif
23392358
23402359 /* compute number of program headers */
23412360 if (file_type == TCC_OUTPUT_OBJ)
@@ -2361,11 +2380,13 @@ static int elf_output_file(TCCState *s1, const char *filename) · 19 unmodified lines
23612380 file_offset = layout_sections(s1, phdr, phnum, interp, strsec, &dyninf,
23622381 sec_order);
23632382
2383+#ifndef ELF_OBJ_ONLY
23642384 /* Fill remaining program header and finalize relocation related to dynamic
23652385 linking. */
23662386 if (file_type != TCC_OUTPUT_OBJ) {
23672387 fill_unloadable_phdr(phdr, phnum, interp, dynamic);
23682388 if (dynamic) {
2389+ ElfW(Sym) *sym;
23692390 dynamic->data_offset = dyninf.data_offset;
23702391 fill_dynamic(s1, &dyninf);
23712392
@@ -2397,10 +2418,12 @@ static int elf_output_file(TCCState *s1, const char *filename) · 25 unmodified lines
23972418 else if (s1->got)
23982419 fill_local_got_entries(s1);
23992420 }
2421+#endif
24002422
24012423 /* Create the ELF file with name 'filename' */
24022424 ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order);
24032425 s1->nb_sections = shnum;
2426+ goto the_end;
24042427 the_end:
24052428 tcc_free(sec_order);
24062429 tcc_free(phdr);
@@ -2885,10 +2908,10 @@ ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte) · 478 unmodified lines
28852908 return 0;
28862909 }
28872910
2888−#ifndef TCC_TARGET_PE
2911+#ifndef ELF_OBJ_ONLY
28892912 /* Set LV[I] to the global index of sym-version (LIB,VERSION). Maybe resizes
28902913 LV, maybe create a new entry for (LIB,VERSION). */
2891−static void set_ver_to_ver(int *n, int **lv, int i, char *lib, char *version)
2914+static void set_ver_to_ver(TCCState *s1, int *n, int **lv, int i, char *lib, char *version)
28922915 {
28932916 while (i >= *n) {
28942917 *lv = tcc_realloc(*lv, (*n + 1) * sizeof(**lv));
@@ -2919,7 +2942,7 @@ static void set_ver_to_ver(int *n, int **lv, int i, char *lib, char *version) · 24 unmodified lines
29192942 /* Associates symbol SYM_INDEX (in dynsymtab) with sym-version index
29202943 VERNDX. */
29212944 static void
2922−set_sym_version(int sym_index, int verndx)
2945+set_sym_version(TCCState *s1, int sym_index, int verndx)
29232946 {
29242947 if (sym_index >= nb_sym_to_version) {
29252948 int newelems = sym_index ? sym_index * 2 : 1;
@@ -2933,6 +2956,90 @@ set_sym_version(int sym_index, int verndx) · 7 unmodified lines
29332956 sym_to_version[sym_index] = verndx;
29342957 }
29352958
2959+struct versym_info {
2960+ int nb_versyms;
2961+ ElfW(Verdef) *verdef;
2962+ ElfW(Verneed) *verneed;
2963+ ElfW(Half) *versym;
2964+ int nb_local_ver, *local_ver;
2965+};
2966+
2967+
2968+static void store_version(TCCState *s1, struct versym_info *v, char *dynstr)
2969+{
2970+ char *lib, *version;
2971+ uint32_t next;
2972+ int i;
2973+
2974+#define DEBUG_VERSION 0
2975+
2976+ if (v->versym && v->verdef) {
2977+ ElfW(Verdef) *vdef = v->verdef;
2978+ lib = NULL;
2979+ do {
2980+ ElfW(Verdaux) *verdaux =
2981+ (ElfW(Verdaux) *) (((char *) vdef) + vdef->vd_aux);
2982+
2983+#if DEBUG_VERSION
2984+ printf ("verdef: version:%u flags:%u index:%u, hash:%u\n",
2985+ vdef->vd_version, vdef->vd_flags, vdef->vd_ndx,
2986+ vdef->vd_hash);
2987+#endif
2988+ if (vdef->vd_cnt) {
2989+ version = dynstr + verdaux->vda_name;
2990+
2991+ if (lib == NULL)
2992+ lib = version;
2993+ else
2994+ set_ver_to_ver(s1, &v->nb_local_ver, &v->local_ver, vdef->vd_ndx,
2995+ lib, version);
2996+#if DEBUG_VERSION
2997+ printf (" verdaux(%u): %s\n", vdef->vd_ndx, version);
2998+#endif
2999+ }
3000+ next = vdef->vd_next;
3001+ vdef = (ElfW(Verdef) *) (((char *) vdef) + next);
3002+ } while (next);
3003+ }
3004+ if (v->versym && v->verneed) {
3005+ ElfW(Verneed) *vneed = v->verneed;
3006+ do {
3007+ ElfW(Vernaux) *vernaux =
3008+ (ElfW(Vernaux) *) (((char *) vneed) + vneed->vn_aux);
3009+
3010+ lib = dynstr + vneed->vn_file;
3011+#if DEBUG_VERSION
3012+ printf ("verneed: %u %s\n", vneed->vn_version, lib);
3013+#endif
3014+ for (i = 0; i < vneed->vn_cnt; i++) {
3015+ if ((vernaux->vna_other & 0x8000) == 0) { /* hidden */
3016+ version = dynstr + vernaux->vna_name;
3017+ set_ver_to_ver(s1, &v->nb_local_ver, &v->local_ver, vernaux->vna_other,
3018+ lib, version);
3019+#if DEBUG_VERSION
3020+ printf (" vernaux(%u): %u %u %s\n",
3021+ vernaux->vna_other, vernaux->vna_hash,
3022+ vernaux->vna_flags, version);
3023+#endif
3024+ }
3025+ vernaux = (ElfW(Vernaux) *) (((char *) vernaux) + vernaux->vna_next);
3026+ }
3027+ next = vneed->vn_next;
3028+ vneed = (ElfW(Verneed) *) (((char *) vneed) + next);
3029+ } while (next);
3030+ }
3031+
3032+#if DEBUG_VERSION
3033+ for (i = 0; i < v->nb_local_ver; i++) {
3034+ if (v->local_ver[i] > 0) {
3035+ printf ("%d: lib: %s, version %s\n",
3036+ i, sym_versions[v->local_ver[i]].lib,
3037+ sym_versions[v->local_ver[i]].version);
3038+ }
3039+ }
3040+#endif
3041+}
3042+
29363043 /* load a DLL and all referenced DLLs. 'level = 0' means that the DLL
29373044 is referenced by the user (so it should be added as DT_NEEDED in
29383045 the generated ELF file) */
@@ -2943,17 +3050,12 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 4 unmodified lines
29433050 int i, j, nb_syms, nb_dts, sym_bind, ret;
29443051 ElfW(Sym) *sym, *dynsym;
29453052 ElfW(Dyn) *dt, *dynamic;
2946− int nb_versyms;
2947− ElfW(Verdef) *verdef, *vdef;
2948− ElfW(Verneed) *verneed, *vneed;
2949− ElfW(Half) *versym, *vsym;
3053+
29503054 char *dynstr;
2951− uint32_t next;
29523055 int sym_index;
2953− char *lib, *version;
2954− int nb_local_ver = 0, *local_ver = NULL;
29553056 const char *name, *soname;
29563057 DLLReference *dllref;
3058+ struct versym_info v;
29573059
29583060 full_read(fd, &ehdr, sizeof(ehdr));
29593061
@@ -2973,10 +3075,8 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 13 unmodified lines
29733075 dynamic = NULL;
29743076 dynsym = NULL; /* avoid warning */
29753077 dynstr = NULL; /* avoid warning */
2976− nb_versyms = 0;
2977− verdef = NULL;
2978− verneed = NULL;
2979− versym = NULL;
3078+ memset(&v, 0, sizeof v);
3079+
29803080 for(i = 0, sh = shdr; i < ehdr.e_shnum; i++, sh++) {
29813081 switch(sh->sh_type) {
29823082 case SHT_DYNAMIC:
@@ -2990,14 +3090,14 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 7 unmodified lines
29903090 dynstr = load_data(fd, sh1->sh_offset, sh1->sh_size);
29913091 break;
29923092 case SHT_GNU_verdef:
2993− verdef = load_data(fd, sh->sh_offset, sh->sh_size);
3093+ v.verdef = load_data(fd, sh->sh_offset, sh->sh_size);
29943094 break;
29953095 case SHT_GNU_verneed:
2996− verneed = load_data(fd, sh->sh_offset, sh->sh_size);
3096+ v.verneed = load_data(fd, sh->sh_offset, sh->sh_size);
29973097 break;
29983098 case SHT_GNU_versym:
2999− nb_versyms = sh->sh_size / sizeof(ElfW(Half));
3000− versym = load_data(fd, sh->sh_offset, sh->sh_size);
3099+ v.nb_versyms = sh->sh_size / sizeof(ElfW(Half));
3100+ v.versym = load_data(fd, sh->sh_offset, sh->sh_size);
30013101 break;
30023102 default:
30033103 break;
@@ -3025,78 +3125,10 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 21 unmodified lines
30253125 }
30263126 }
30273127
3028− if (nb_versyms != nb_syms) {
3029− tcc_free (versym);
3030− versym = NULL;
3031− }
3032−
3033−#define DEBUG_VERSION 0
3034−
3035− if (versym && verdef) {
3036− lib = NULL;
3037− vdef = verdef;
3038− do {
3039− ElfW(Verdaux) *verdaux =
3040− (ElfW(Verdaux) *) (((char *) vdef) + vdef->vd_aux);
3041−
3042−#if DEBUG_VERSION
3043− printf ("verdef: version:%u flags:%u index:%u, hash:%u\n",
3044− vdef->vd_version, vdef->vd_flags, vdef->vd_ndx,
3045− vdef->vd_hash);
3046−#endif
3047− if (vdef->vd_cnt) {
3048− version = dynstr + verdaux->vda_name;
3049−
3050− if (lib == NULL)
3051− lib = version;
3052− else
3053− set_ver_to_ver(&nb_local_ver, &local_ver, vdef->vd_ndx,
3054− lib, version);
3055−#if DEBUG_VERSION
3056− printf (" verdaux(%u): %s\n", vdef->vd_ndx, version);
3057−#endif
3058− }
3059− next = vdef->vd_next;
3060− vdef = (ElfW(Verdef) *) (((char *) vdef) + next);
3061− } while (next);
3062− }
3063− if (versym && verneed) {
3064− vneed = verneed;
3065− do {
3066− ElfW(Vernaux) *vernaux =
3067− (ElfW(Vernaux) *) (((char *) vneed) + vneed->vn_aux);
3068−
3069− lib = dynstr + vneed->vn_file;
3070−#if DEBUG_VERSION
3071− printf ("verneed: %u %s\n", vneed->vn_version, lib);
3072−#endif
3073− for (i = 0; i < vneed->vn_cnt; i++) {
3074− if ((vernaux->vna_other & 0x8000) == 0) { /* hidden */
3075− version = dynstr + vernaux->vna_name;
3076− set_ver_to_ver(&nb_local_ver, &local_ver, vernaux->vna_other,
3077− lib, version);
3078−#if DEBUG_VERSION
3079− printf (" vernaux(%u): %u %u %s\n",
3080− vernaux->vna_other, vernaux->vna_hash,
3081− vernaux->vna_flags, version);
3082−#endif
3083− }
3084− vernaux = (ElfW(Vernaux) *) (((char *) vernaux) + vernaux->vna_next);
3085− }
3086− next = vneed->vn_next;
3087− vneed = (ElfW(Verneed) *) (((char *) vneed) + next);
3088− } while (next);
3089− }
3090−
3091−#if DEBUG_VERSION
3092− for (i = 0; i < nb_local_ver; i++) {
3093− if (local_ver[i] > 0) {
3094− printf ("%d: lib: %s, version %s\n",
3095− i, sym_versions[local_ver[i]].lib,
3096− sym_version[local_ver[i]].version);
3097− }
3098− }
3099−#endif
3128+ if (v.nb_versyms != nb_syms)
3129+ tcc_free (v.versym), v.versym = NULL;
3130+ else
3131+ store_version(s1, &v, dynstr);
31003132
31013133 /* add the dll and its level */
31023134 dllref = tcc_mallocz(sizeof(DLLReference) + strlen(soname));
@@ -3105,17 +3137,18 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 2 unmodified lines
31053137 dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);
31063138
31073139 /* add dynamic symbols in dynsym_section */
3108− for(i = 1, sym = dynsym + 1, vsym = versym + 1; i < nb_syms; i++, sym++, vsym++) {
3140+ for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) {
31093141 sym_bind = ELFW(ST_BIND)(sym->st_info);
31103142 if (sym_bind == STB_LOCAL)
31113143 continue;
31123144 name = dynstr + sym->st_name;
31133145 sym_index = set_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size,
31143146 sym->st_info, sym->st_other, sym->st_shndx, name);
3115− if (versym && (*vsym & 0x8000) == 0 &&
3116− *vsym > 0 && *vsym < nb_local_ver) {
3117− set_sym_version(sym_index, local_ver[*vsym]);
3118− }
3147+ if (v.versym) {
3148+ ElfW(Half) vsym = v.versym[i];
3149+ if ((vsym & 0x8000) == 0 && vsym > 0 && vsym < v.nb_local_ver)
3150+ set_sym_version(s1, sym_index, v.local_ver[vsym]);
3151+ }
31193152 }
31203153
31213154 /* load all referenced DLLs */
@@ -3139,14 +3172,14 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 17 unmodified lines
31393172 }
31403173 ret = 0;
31413174 the_end:
3142− tcc_free(local_ver);
31433175 tcc_free(dynstr);
31443176 tcc_free(dynsym);
31453177 tcc_free(dynamic);
3146− tcc_free(verdef);
3147− tcc_free(verneed);
3148− tcc_free(versym);
31493178 tcc_free(shdr);
3179+ tcc_free(v.local_ver);
3180+ tcc_free(v.verdef);
3181+ tcc_free(v.verneed);
3182+ tcc_free(v.versym);
31503183 return ret;
31513184 }
31523185
@@ -3406,4 +3439,4 @@ ST_FUNC int tcc_load_ldscript(TCCState *s1) · 253 unmodified lines
34063439 }
34073440 return 0;
34083441 }
3409−#endif /* !TCC_TARGET_PE */
3442+#endif /* !ELF_OBJ_ONLY */
tccrun.c+2−0
@@ -237,7 +237,9 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff) · 236 unmodified lines
237237 if (s->reloc)
238238 relocate_section(s1, s);
239239 }
240+#ifndef TCC_TARGET_PE
240241 relocate_plt(s1);
242+#endif
241243
242244 for(i = 1; i < s1->nb_sections; i++) {
243245 s = s1->sections[i];
x86_64-link.c+2−11
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222
2323 #include "tcc.h"
2424
25+#ifndef ELF_OBJ_ONLY
2526 /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
2627 relocations, returns -1. */
2728 int code_reloc (int reloc_type)
@@ -162,17 +163,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 134 unmodified lines
162163 }
163164 }
164165 }
165−
166−static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
167−
168−void relocate_init(Section *sr)
169−{
170− qrel = (ElfW_Rel *) sr->data;
171−}
172−
173−void relocate_fini(Section *sr)
174−{
175−}
166+#endif
176167
177168 void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
178169 {

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