History

tccpe: cleanup "imports per ordinal"

- tccpe.c: avoid conflict with imp_sym->st_value, cleanup - _parseLibs.bat, _tcc.bat: no instructions for usage, removed. from commit 642b6d0f50c6b6a842c9239a102fe34d5619e931

grischka committed 12 years ago

Commit d4436441 parent 4ad186c3 files · +33 −143Browse files

Unified · Split

3 files
  1. tccpe.c +33 −34
  2. win32/_parseLibs.bat +0 −79
  3. win32/_tcc.bat +0 −30
tccpe.c+33−34
@@ -813,28 +813,24 @@ static void pe_build_imports(struct pe_info *pe) · 812 unmodified lines
813 hdr->Name = v + rva_base;813 hdr->Name = v + rva_base;
814 814
815 for (k = 0, n = p->sym_count; k <= n; ++k) {815 for (k = 0, n = p->sym_count; k <= n; ++k) {
816 int ordinal = 0;
817 if (k < n) {816 if (k < n) {
818 int iat_index = p->symbols[k]->iat_index;817 int iat_index = p->symbols[k]->iat_index;
819 int sym_index = p->symbols[k]->sym_index;818 int sym_index = p->symbols[k]->sym_index;
820 ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index;819 ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index;
821 ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index;820 ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index;
822 const char *name = pe->s1->dynsymtab_section->link->data + imp_sym->st_name;821 const char *name = pe->s1->dynsymtab_section->link->data + imp_sym->st_name;
822 int ordinal;
823 823
824 org_sym->st_value = thk_ptr;824 org_sym->st_value = thk_ptr;
825 org_sym->st_shndx = pe->thunk->sh_num;825 org_sym->st_shndx = pe->thunk->sh_num;
826 v = pe->thunk->data_offset + rva_base;826
827 827 if (dllref)
828 /* ordinal or name */828 v = 0, ordinal = imp_sym->st_value; /* ordinal from pe_load_def */
829 ordinal = imp_sym->st_value; /* from pe_load_def, temperary use */829 else
830 //if (ordinal) printf("ordinal: %d\n", ordinal);830 ordinal = 0, v = imp_sym->st_value; /* address from tcc_add_symbol() */
831 if (!ordinal) {831
832 section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */
833 put_elf_str(pe->thunk, name);
834 }
835#ifdef TCC_IS_NATIVE832#ifdef TCC_IS_NATIVE
836 if (pe->type == PE_RUN) {833 if (pe->type == PE_RUN) {
837 v = imp_sym->st_value;
838 if (dllref) {834 if (dllref) {
839 if ( !dllref->handle )835 if ( !dllref->handle )
840 dllref->handle = LoadLibrary(dllref->name);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 if (!v)839 if (!v)
844 tcc_error_noabort("can't build symbol '%s'", name);840 tcc_error_noabort("can't build symbol '%s'", name);
845 }841 } else
846#endif842#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 } else {851 } else {
848 v = 0; /* last entry is zero */852 v = 0; /* last entry is zero */
849 }853 }
854
850 *(ADDR3264*)(pe->thunk->data+thk_ptr) =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 thk_ptr += sizeof (ADDR3264);857 thk_ptr += sizeof (ADDR3264);
853 ent_ptr += sizeof (ADDR3264);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/* ------------------------------------------------------------- */
1594static int pe_load_def(TCCState *s1, int fd)1599static int pe_load_def(TCCState *s1, int fd)
1595{1600{
1596 int state = 0, ret = -1, dllindex = 0;1601 int state = 0, ret = -1, dllindex = 0, ord;
1597 char line[400], dllname[80], *p;1602 char line[400], dllname[80], *p, *x;
1598 1603
1599 for (;;) {1604 for (;;) {
1600 int ord = 0;1605
1601 char *x, *d, idxstr[8];
1602 p = get_line(line, sizeof line, fd);1606 p = get_line(line, sizeof line, fd);
1603 if (NULL == p)1607 if (NULL == p)
1604 break;1608 break;
@@ -1621,24 +1625,19 @@ static int pe_load_def(TCCState *s1, int fd) · 16 unmodified lines
1621 case 2:1625 case 2:
1622 dllindex = add_dllref(s1, dllname);1626 dllindex = add_dllref(s1, dllname);
1623 ++state;1627 ++state;
1624 1628 /* fall through */
1625 default:1629 default:
1626 /* get ordianl and will store in sym->st_value */1630 /* get ordinal and will store in sym->st_value */
1627 d = NULL;1631 ord = 0;
1628 x = strchr(line, ' ');1632 x = strchr(p, ' ');
1629 if (x) x = strchr(line, '@');1633 if (x) {
1630 while (x != NULL) {1634 *x = 0, x = strrchr(x + 1, '@');
1631 d =x;1635 if (x) {
1632 x = strchr(x+1, '@');1636 char *d;
1633 }1637 ord = (int)strtol(x + 1, &d, 10);
1634 if (d) {1638 if (*d)
1635 ord = atoi(d+1);1639 ord = 0;
1636 itoa(ord, idxstr, 10);1640 }
1637 if (strcmp(idxstr, d+1) == 0) {
1638 memset(d, 0, 1);
1639 trimback(p, d);
1640 } else
1641 ord = 0;
1642 }1641 }
1643 pe_putimport(s1, dllindex, p, ord);1642 pe_putimport(s1, dllindex, p, ord);
1644 continue;1643 continue;
win32/_parseLibs.bat+0−79
@@ -1,79 +0,0 @@
1@echo off
2setlocal enabledelayedexpansion
3
4pushd %~dp0
5
6::Define as main parameters
7set _Args_=
8set _LIBs_=
9set LIBi=
10
11set ARGSO=-IExt\include -LExt\lib %*
12
13::This is for the .def file also have a similar name .c file
14::.a file will be larger than .def + .c
15::*-uuid.c files are suitable to form libuuid.a
16::w32api-3.17.2
17:GetRLib
18for %%i in (%ARGSO%) do (
19 set ARG=%%i
20 set OPT=!ARG:~0,2!
21 if "!OPT!"=="-l" (
22 set LIB=!ARG:~2!
23 set LIBi=
24 if "!LIB!"=="uuid" (
25 set LIBi= lib\*uid.c
26 ) else (
27 if "!LIB!"=="vfw32" (
28 set LIBi= lib\msvfw32.def lib\avifil32.def lib\avicap32.def
29 ) else (
30 call :GetLibS
31 )
32 )
33 if "!LIBi!"=="" (
34 set _Args_=!_Args_! %%i
35 ) else (
36 set LIBi=!LIBi:%~dp0=!
37 set _LIBs_=!_LIBs_! !LIBi!
38 echo For lib !LIB! will use:
39 echo !LIBi!
40 echo.
41 )
42 ) else (
43 set _Args_=!_Args_! %%i
44 )
45)
46
47::GetRLib End
48popd
49
50tcc.exe !_Args_! !_LIBs_!
51
52exit /b
53
54::::::::::
55
56:GetLibS
57for %%D in (-Llib %ARGSO%) do (
58 set ARG_=%%D
59 set OPT_=!ARG_:~0,2!
60 set LIBD=
61 if "!OPT_!"=="-L" (
62 set LIBD=!ARG_:~2!
63 if exist "!LIBD!" call :GetDLib
64 )
65)
66set LIBD=
67set OPT_=
68set ARG_=
69exit /b
70::GetLibD End
71
72:GetDLib
73pushd !LIBD!
74for /f "usebackq delims=" %%I in (`"dir /b /s !LIB!.c !LIB!_*.c !LIB!.def !LIB!_*.def 2>nul"`) do (
75 set LIBi=!LIBi! "%%I"
76)
77popd
78exit /b
79::GetDLib End
win32/_tcc.bat+0−30
@@ -1,30 +0,0 @@
1@echo off
2setlocal enabledelayedexpansion
3
4pushd %~dp0
5
6path %~dp0;%path%
7
8set EXT=.exe
9echo %*|findstr /R /C:"\<-c\>" >nul &&set EXT=.o
10echo %*|findstr /R /C:"\<-shared\>" >nul &&set EXT=.dll
11
12::1st file found must be the main c file to get output file name
13set OUTF=
14call :FINDFN %*
15
16if "%OUTF%"=="" goto :EXIT
17
18call _parseLibs -vv -o "%OUTF%" %*
19
20:EXIT
21popd
22pause
23exit /b
24
25:FINDFN
26for %%i in (%*) do (
27 if exist %%i set OUTF=%%~dpni%EXT%&goto :ENDFDF
28)
29:ENDFDF
30exit /b

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