win64: fix resource file support

This commit is contained in:
grischka 2014-08-01 10:51:28 +02:00
parent 73a7dd79af
commit 12f43953ed
2 changed files with 33 additions and 31 deletions

52
tccpe.c
View File

@ -34,8 +34,28 @@
#ifdef TCC_TARGET_X86_64
# define ADDR3264 ULONGLONG
#else
# define REL_TYPE_DIRECT R_X86_64_64
# define R_XXX_THUNKFIX R_X86_64_PC32
# define R_XXX_RELATIVE R_X86_64_RELATIVE
# define IMAGE_FILE_MACHINE 0x8664
# define RSRC_RELTYPE 3
#elif defined TCC_TARGET_ARM
# define ADDR3264 DWORD
# define REL_TYPE_DIRECT R_ARM_ABS32
# define R_XXX_THUNKFIX R_ARM_ABS32
# define R_XXX_RELATIVE R_ARM_RELATIVE
# define IMAGE_FILE_MACHINE 0x01C0
# define RSRC_RELTYPE 7 /* ??? (not tested) */
#elif defined TCC_TARGET_I386
# define ADDR3264 DWORD
# define REL_TYPE_DIRECT R_386_32
# define R_XXX_THUNKFIX R_386_32
# define R_XXX_RELATIVE R_386_RELATIVE
# define IMAGE_FILE_MACHINE 0x014C
# define RSRC_RELTYPE 7 /* DIR32NB */
#endif
#ifdef _WIN32
@ -507,13 +527,7 @@ static int pe_write(struct pe_info *pe)
0x00004550, /* DWORD nt_sig = IMAGE_NT_SIGNATURE */
{
/* IMAGE_FILE_HEADER filehdr */
#if defined(TCC_TARGET_I386)
0x014C, /*WORD Machine; */
#elif defined(TCC_TARGET_X86_64)
0x8664, /*WORD Machine; */
#elif defined(TCC_TARGET_ARM)
0x01C0, /*WORD Machine; */
#endif
IMAGE_FILE_MACHINE, /*WORD Machine; */
0x0003, /*WORD NumberOfSections; */
0x00000000, /*DWORD TimeDateStamp; */
0x00000000, /*DWORD PointerToSymbolTable; */
@ -718,24 +732,6 @@ static int pe_write(struct pe_info *pe)
/*----------------------------------------------------------------------------*/
#if defined(TCC_TARGET_X86_64)
#define REL_TYPE_DIRECT R_X86_64_64
#define R_XXX_THUNKFIX R_X86_64_PC32
#define R_XXX_RELATIVE R_X86_64_RELATIVE
#elif defined(TCC_TARGET_I386)
#define REL_TYPE_DIRECT R_386_32
#define R_XXX_THUNKFIX R_386_32
#define R_XXX_RELATIVE R_386_RELATIVE
#elif defined(TCC_TARGET_ARM)
#define REL_TYPE_DIRECT R_ARM_ABS32
#define R_XXX_THUNKFIX R_ARM_ABS32
#define R_XXX_RELATIVE R_ARM_RELATIVE
#endif
/*----------------------------------------------------------------------------*/
static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
{
int i;
@ -1539,7 +1535,7 @@ static int pe_load_res(TCCState *s1, int fd)
if (!read_mem(fd, 0, &hdr, sizeof hdr))
goto quit;
if (hdr.filehdr.Machine != 0x014C
if (hdr.filehdr.Machine != IMAGE_FILE_MACHINE
|| hdr.filehdr.NumberOfSections != 1
|| strcmp(hdr.sectionhdr.Name, ".rsrc") != 0)
goto quit;
@ -1556,7 +1552,7 @@ static int pe_load_res(TCCState *s1, int fd)
if (!read_mem(fd, offs, &rel, sizeof rel))
goto quit;
// printf("rsrc_reloc: %x %x %x\n", rel.offset, rel.size, rel.type);
if (rel.type != 7) /* DIR32NB */
if (rel.type != RSRC_RELTYPE)
goto quit;
put_elf_reloc(symtab_section, rsrc_section,
rel.offset, R_XXX_RELATIVE, 0);

View File

@ -158,6 +158,14 @@ int read_mem(int fd, unsigned offset, void *buffer, unsigned len)
/* -------------------------------------------------------------- */
#if defined TCC_TARGET_X86_64
# define IMAGE_FILE_MACHINE 0x8664
#elif defined TCC_TARGET_ARM
# define IMAGE_FILE_MACHINE 0x01C0
#elif 1 /* defined TCC_TARGET_I386 */
# define IMAGE_FILE_MACHINE 0x014C
#endif
/* -------------------------------------------------------------- */
#endif
@ -173,10 +181,8 @@ char *get_export_names(int fd)
DWORD sig, ref, addr, ptr, namep;
#ifdef TCC_TARGET_X86_64
IMAGE_OPTIONAL_HEADER64 oh;
const int MACHINE = 0x8664;
#else
IMAGE_OPTIONAL_HEADER32 oh;
const int MACHINE = 0x014C;
#endif
int pef_hdroffset, opt_hdroffset, sec_hdroffset;
@ -192,7 +198,7 @@ char *get_export_names(int fd)
pef_hdroffset = dh.e_lfanew + sizeof sig;
if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
goto the_end;
if (MACHINE != ih.Machine)
if (IMAGE_FILE_MACHINE != ih.Machine)
goto the_end;
opt_hdroffset = pef_hdroffset + sizeof ih;
sec_hdroffset = opt_hdroffset + sizeof oh;