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
813813 hdr->Name = v + rva_base;
814814
815815 for (k = 0, n = p->sym_count; k <= n; ++k) {
816− int ordinal = 0;
817816 if (k < n) {
818817 int iat_index = p->symbols[k]->iat_index;
819818 int sym_index = p->symbols[k]->sym_index;
820819 ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index;
821820 ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index;
822821 const char *name = pe->s1->dynsymtab_section->link->data + imp_sym->st_name;
822+ int ordinal;
823823
824824 org_sym->st_value = thk_ptr;
825825 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+
835832 #ifdef TCC_IS_NATIVE
836833 if (pe->type == PE_RUN) {
837− v = imp_sym->st_value;
838834 if (dllref) {
839835 if ( !dllref->handle )
840836 dllref->handle = LoadLibrary(dllref->name);
@@ -842,13 +838,22 @@ static void pe_build_imports(struct pe_info *pe) · 1 unmodified line
842838 }
843839 if (!v)
844840 tcc_error_noabort("can't build symbol '%s'", name);
845− }
841+ } else
846842 #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+
847851 } else {
848852 v = 0; /* last entry is zero */
849853 }
854+
850855 *(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;
852857 thk_ptr += sizeof (ADDR3264);
853858 ent_ptr += sizeof (ADDR3264);
854859 }
@@ -1593,12 +1598,11 @@ static char *get_line(char *line, int size, int fd) · 738 unmodified lines
15931598 /* ------------------------------------------------------------- */
15941599 static int pe_load_def(TCCState *s1, int fd)
15951600 {
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;
15981603
15991604 for (;;) {
1600− int ord = 0;
1601− char *x, *d, idxstr[8];
1605+
16021606 p = get_line(line, sizeof line, fd);
16031607 if (NULL == p)
16041608 break;
@@ -1621,24 +1625,19 @@ static int pe_load_def(TCCState *s1, int fd) · 16 unmodified lines
16211625 case 2:
16221626 dllindex = add_dllref(s1, dllname);
16231627 ++state;
1624−
1628+ /* fall through */
16251629 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+ }
16421641 }
16431642 pe_putimport(s1, dllindex, p, ord);
16441643 continue;
win32/_parseLibs.bat+0−79
@@ -1,79 +0,0 @@
1−@echo off
2−setlocal enabledelayedexpansion
3−
4−pushd %~dp0
5−
6−::Define as main parameters
7−set _Args_=
8−set _LIBs_=
9−set LIBi=
10−
11−set 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
18−for %%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
48−popd
49−
50−tcc.exe !_Args_! !_LIBs_!
51−
52−exit /b
53−
54−::::::::::
55−
56−:GetLibS
57−for %%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−)
66−set LIBD=
67−set OPT_=
68−set ARG_=
69−exit /b
70−::GetLibD End
71−
72−:GetDLib
73−pushd !LIBD!
74−for /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−)
77−popd
78−exit /b
79−::GetDLib End
win32/_tcc.bat+0−30
@@ -1,30 +0,0 @@
1−@echo off
2−setlocal enabledelayedexpansion
3−
4−pushd %~dp0
5−
6−path %~dp0;%path%
7−
8−set EXT=.exe
9−echo %*|findstr /R /C:"\<-c\>" >nul &&set EXT=.o
10−echo %*|findstr /R /C:"\<-shared\>" >nul &&set EXT=.dll
11−
12−::1st file found must be the main c file to get output file name
13−set OUTF=
14−call :FINDFN %*
15−
16−if "%OUTF%"=="" goto :EXIT
17−
18−call _parseLibs -vv -o "%OUTF%" %*
19−
20−:EXIT
21−popd
22−pause
23−exit /b
24−
25−:FINDFN
26−for %%i in (%*) do (
27− if exist %%i set OUTF=%%~dpni%EXT%&goto :ENDFDF
28−)
29−:ENDFDF
30−exit /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