History

win64: fix resource file support

grischka committed 12 years ago

Commit 12f43951 parent 73a7dd72 files · +33 −31Browse files

Unified · Split

2 files
  1. tccpe.c +24 −28
  2. win32/tools/tiny_impdef.c +9 −3
tccpe.c+24−28
@@ -34,8 +34,28 @@ · 33 unmodified lines
34 34
35#ifdef TCC_TARGET_X86_6435#ifdef TCC_TARGET_X86_64
36# define ADDR3264 ULONGLONG36# define ADDR3264 ULONGLONG
37#else37# define REL_TYPE_DIRECT R_X86_64_64
38# define R_XXX_THUNKFIX R_X86_64_PC32
39# define R_XXX_RELATIVE R_X86_64_RELATIVE
40# define IMAGE_FILE_MACHINE 0x8664
41# define RSRC_RELTYPE 3
42
43#elif defined TCC_TARGET_ARM
44# define ADDR3264 DWORD
45# define REL_TYPE_DIRECT R_ARM_ABS32
46# define R_XXX_THUNKFIX R_ARM_ABS32
47# define R_XXX_RELATIVE R_ARM_RELATIVE
48# define IMAGE_FILE_MACHINE 0x01C0
49# define RSRC_RELTYPE 7 /* ??? (not tested) */
50
51#elif defined TCC_TARGET_I386
38# define ADDR3264 DWORD52# define ADDR3264 DWORD
53# define REL_TYPE_DIRECT R_386_32
54# define R_XXX_THUNKFIX R_386_32
55# define R_XXX_RELATIVE R_386_RELATIVE
56# define IMAGE_FILE_MACHINE 0x014C
57# define RSRC_RELTYPE 7 /* DIR32NB */
58
39#endif59#endif
40 60
41#ifdef _WIN3261#ifdef _WIN32
@@ -507,13 +527,7 @@ static int pe_write(struct pe_info *pe) · 465 unmodified lines
507 0x00004550, /* DWORD nt_sig = IMAGE_NT_SIGNATURE */527 0x00004550, /* DWORD nt_sig = IMAGE_NT_SIGNATURE */
508 {528 {
509 /* IMAGE_FILE_HEADER filehdr */529 /* IMAGE_FILE_HEADER filehdr */
510#if defined(TCC_TARGET_I386)530 IMAGE_FILE_MACHINE, /*WORD Machine; */
511 0x014C, /*WORD Machine; */
512#elif defined(TCC_TARGET_X86_64)
513 0x8664, /*WORD Machine; */
514#elif defined(TCC_TARGET_ARM)
515 0x01C0, /*WORD Machine; */
516#endif
517 0x0003, /*WORD NumberOfSections; */531 0x0003, /*WORD NumberOfSections; */
518 0x00000000, /*DWORD TimeDateStamp; */532 0x00000000, /*DWORD TimeDateStamp; */
519 0x00000000, /*DWORD PointerToSymbolTable; */533 0x00000000, /*DWORD PointerToSymbolTable; */
@@ -718,24 +732,6 @@ static int pe_write(struct pe_info *pe) · 198 unmodified lines
718 732
719/*----------------------------------------------------------------------------*/733/*----------------------------------------------------------------------------*/
720 734
721#if defined(TCC_TARGET_X86_64)
722#define REL_TYPE_DIRECT R_X86_64_64
723#define R_XXX_THUNKFIX R_X86_64_PC32
724#define R_XXX_RELATIVE R_X86_64_RELATIVE
725
726#elif defined(TCC_TARGET_I386)
727#define REL_TYPE_DIRECT R_386_32
728#define R_XXX_THUNKFIX R_386_32
729#define R_XXX_RELATIVE R_386_RELATIVE
730
731#elif defined(TCC_TARGET_ARM)
732#define REL_TYPE_DIRECT R_ARM_ABS32
733#define R_XXX_THUNKFIX R_ARM_ABS32
734#define R_XXX_RELATIVE R_ARM_RELATIVE
735
736#endif
737/*----------------------------------------------------------------------------*/
738
739static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)735static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
740{736{
741 int i;737 int i;
@@ -1539,7 +1535,7 @@ static int pe_load_res(TCCState *s1, int fd) · 797 unmodified lines
1539 if (!read_mem(fd, 0, &hdr, sizeof hdr))1535 if (!read_mem(fd, 0, &hdr, sizeof hdr))
1540 goto quit;1536 goto quit;
1541 1537
1542 if (hdr.filehdr.Machine != 0x014C1538 if (hdr.filehdr.Machine != IMAGE_FILE_MACHINE
1543 || hdr.filehdr.NumberOfSections != 11539 || hdr.filehdr.NumberOfSections != 1
1544 || strcmp(hdr.sectionhdr.Name, ".rsrc") != 0)1540 || strcmp(hdr.sectionhdr.Name, ".rsrc") != 0)
1545 goto quit;1541 goto quit;
@@ -1556,7 +1552,7 @@ static int pe_load_res(TCCState *s1, int fd) · 10 unmodified lines
1556 if (!read_mem(fd, offs, &rel, sizeof rel))1552 if (!read_mem(fd, offs, &rel, sizeof rel))
1557 goto quit;1553 goto quit;
1558 // printf("rsrc_reloc: %x %x %x\n", rel.offset, rel.size, rel.type);1554 // printf("rsrc_reloc: %x %x %x\n", rel.offset, rel.size, rel.type);
1559 if (rel.type != 7) /* DIR32NB */1555 if (rel.type != RSRC_RELTYPE)
1560 goto quit;1556 goto quit;
1561 put_elf_reloc(symtab_section, rsrc_section,1557 put_elf_reloc(symtab_section, rsrc_section,
1562 rel.offset, R_XXX_RELATIVE, 0);1558 rel.offset, R_XXX_RELATIVE, 0);
win32/tools/tiny_impdef.c+9−3
@@ -158,6 +158,14 @@ int read_mem(int fd, unsigned offset, void *buffer, unsigned len) · 157 unmodified lines
158 158
159/* -------------------------------------------------------------- */159/* -------------------------------------------------------------- */
160 160
161#if defined TCC_TARGET_X86_64
162# define IMAGE_FILE_MACHINE 0x8664
163#elif defined TCC_TARGET_ARM
164# define IMAGE_FILE_MACHINE 0x01C0
165#elif 1 /* defined TCC_TARGET_I386 */
166# define IMAGE_FILE_MACHINE 0x014C
167#endif
168
161/* -------------------------------------------------------------- */169/* -------------------------------------------------------------- */
162#endif170#endif
163 171
@@ -173,10 +181,8 @@ char *get_export_names(int fd) · 9 unmodified lines
173 DWORD sig, ref, addr, ptr, namep;181 DWORD sig, ref, addr, ptr, namep;
174#ifdef TCC_TARGET_X86_64182#ifdef TCC_TARGET_X86_64
175 IMAGE_OPTIONAL_HEADER64 oh;183 IMAGE_OPTIONAL_HEADER64 oh;
176 const int MACHINE = 0x8664;
177#else184#else
178 IMAGE_OPTIONAL_HEADER32 oh;185 IMAGE_OPTIONAL_HEADER32 oh;
179 const int MACHINE = 0x014C;
180#endif186#endif
181 int pef_hdroffset, opt_hdroffset, sec_hdroffset;187 int pef_hdroffset, opt_hdroffset, sec_hdroffset;
182 188
@@ -192,7 +198,7 @@ char *get_export_names(int fd) · 9 unmodified lines
192 pef_hdroffset = dh.e_lfanew + sizeof sig;198 pef_hdroffset = dh.e_lfanew + sizeof sig;
193 if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))199 if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
194 goto the_end;200 goto the_end;
195 if (MACHINE != ih.Machine)201 if (IMAGE_FILE_MACHINE != ih.Machine)
196 goto the_end;202 goto the_end;
197 opt_hdroffset = pef_hdroffset + sizeof ih;203 opt_hdroffset = pef_hdroffset + sizeof ih;
198 sec_hdroffset = opt_hdroffset + sizeof oh;204 sec_hdroffset = opt_hdroffset + sizeof oh;

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