| @@ -813,28 +813,24 @@ static void pe_build_imports(struct pe_info *pe) · 812 unmodified lines |
| 813 | 813 | hdr->Name = v + rva_base; |
| 814 | 814 | |
| 815 | 815 | for (k = 0, n = p->sym_count; k <= n; ++k) { |
| 816 | | − int ordinal = 0; |
| 817 | 816 | if (k < n) { |
| 818 | 817 | int iat_index = p->symbols[k]->iat_index; |
| 819 | 818 | int sym_index = p->symbols[k]->sym_index; |
| 820 | 819 | ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index; |
| 821 | 820 | ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index; |
| 822 | 821 | const char *name = pe->s1->dynsymtab_section->link->data + imp_sym->st_name; |
| 822 | + int ordinal; |
| 823 | 823 | |
| 824 | 824 | org_sym->st_value = thk_ptr; |
| 825 | 825 | org_sym->st_shndx = pe->thunk->sh_num; |
| 826 | | − v = pe->thunk->data_offset + rva_base; |
| 827 | | − |
| 828 | | − /* ordinal or name */ |
| 829 | | − ordinal = imp_sym->st_value; /* from pe_load_def, temperary use */ |
| 830 | | − //if (ordinal) printf("ordinal: %d\n", ordinal); |
| 831 | | − if (!ordinal) { |
| 832 | | − section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */ |
| 833 | | − put_elf_str(pe->thunk, name); |
| 834 | | − } |
| 826 | + |
| 827 | + if (dllref) |
| 828 | + v = 0, ordinal = imp_sym->st_value; /* ordinal from pe_load_def */ |
| 829 | + else |
| 830 | + ordinal = 0, v = imp_sym->st_value; /* address from tcc_add_symbol() */ |
| 831 | + |
| 835 | 832 | #ifdef TCC_IS_NATIVE |
| 836 | 833 | if (pe->type == PE_RUN) { |
| 837 | | − v = imp_sym->st_value; |
| 838 | 834 | if (dllref) { |
| 839 | 835 | if ( !dllref->handle ) |
| 840 | 836 | dllref->handle = LoadLibrary(dllref->name); |
| @@ -842,13 +838,22 @@ static void pe_build_imports(struct pe_info *pe) · 1 unmodified line |
| 842 | 838 | } |
| 843 | 839 | if (!v) |
| 844 | 840 | tcc_error_noabort("can't build symbol '%s'", name); |
| 845 | | − } |
| 841 | + } else |
| 846 | 842 | #endif |
| 843 | + if (ordinal) { |
| 844 | + v = ordinal | (ADDR3264)1 << (sizeof(ADDR3264)*8 - 1); |
| 845 | + } else { |
| 846 | + v = pe->thunk->data_offset + rva_base; |
| 847 | + section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */ |
| 848 | + put_elf_str(pe->thunk, name); |
| 849 | + } |
| 850 | + |
| 847 | 851 | } else { |
| 848 | 852 | v = 0; /* last entry is zero */ |
| 849 | 853 | } |
| 854 | + |
| 850 | 855 | *(ADDR3264*)(pe->thunk->data+thk_ptr) = |
| 851 | | − *(ADDR3264*)(pe->thunk->data+ent_ptr) = (ordinal && pe->type != PE_RUN)?(ADDR3264)1<<(sizeof(ADDR3264)*8-1)|ordinal:v; |
| 856 | + *(ADDR3264*)(pe->thunk->data+ent_ptr) = v; |
| 852 | 857 | thk_ptr += sizeof (ADDR3264); |
| 853 | 858 | ent_ptr += sizeof (ADDR3264); |
| 854 | 859 | } |
| @@ -1593,12 +1598,11 @@ static char *get_line(char *line, int size, int fd) · 738 unmodified lines |
| 1593 | 1598 | /* ------------------------------------------------------------- */ |
| 1594 | 1599 | static int pe_load_def(TCCState *s1, int fd) |
| 1595 | 1600 | { |
| 1596 | | − int state = 0, ret = -1, dllindex = 0; |
| 1597 | | − char line[400], dllname[80], *p; |
| 1601 | + int state = 0, ret = -1, dllindex = 0, ord; |
| 1602 | + char line[400], dllname[80], *p, *x; |
| 1598 | 1603 | |
| 1599 | 1604 | for (;;) { |
| 1600 | | − int ord = 0; |
| 1601 | | − char *x, *d, idxstr[8]; |
| 1605 | + |
| 1602 | 1606 | p = get_line(line, sizeof line, fd); |
| 1603 | 1607 | if (NULL == p) |
| 1604 | 1608 | break; |
| @@ -1621,24 +1625,19 @@ static int pe_load_def(TCCState *s1, int fd) · 16 unmodified lines |
| 1621 | 1625 | case 2: |
| 1622 | 1626 | dllindex = add_dllref(s1, dllname); |
| 1623 | 1627 | ++state; |
| 1624 | | − |
| 1628 | + /* fall through */ |
| 1625 | 1629 | default: |
| 1626 | | − /* get ordianl and will store in sym->st_value */ |
| 1627 | | − d = NULL; |
| 1628 | | − x = strchr(line, ' '); |
| 1629 | | − if (x) x = strchr(line, '@'); |
| 1630 | | − while (x != NULL) { |
| 1631 | | − d =x; |
| 1632 | | − x = strchr(x+1, '@'); |
| 1633 | | − } |
| 1634 | | − if (d) { |
| 1635 | | − ord = atoi(d+1); |
| 1636 | | − itoa(ord, idxstr, 10); |
| 1637 | | − if (strcmp(idxstr, d+1) == 0) { |
| 1638 | | − memset(d, 0, 1); |
| 1639 | | − trimback(p, d); |
| 1640 | | − } else |
| 1641 | | − ord = 0; |
| 1630 | + /* get ordinal and will store in sym->st_value */ |
| 1631 | + ord = 0; |
| 1632 | + x = strchr(p, ' '); |
| 1633 | + if (x) { |
| 1634 | + *x = 0, x = strrchr(x + 1, '@'); |
| 1635 | + if (x) { |
| 1636 | + char *d; |
| 1637 | + ord = (int)strtol(x + 1, &d, 10); |
| 1638 | + if (*d) |
| 1639 | + ord = 0; |
| 1640 | + } |
| 1642 | 1641 | } |
| 1643 | 1642 | pe_putimport(s1, dllindex, p, ord); |
| 1644 | 1643 | continue; |