mirror of
https://github.com/mirror/tinycc.git
synced 2025-04-01 12:30:08 +08:00
win64: fix resource file support
This commit is contained in:
parent
73a7dd79af
commit
12f43953ed
52
tccpe.c
52
tccpe.c
@ -34,8 +34,28 @@
|
|||||||
|
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
# define ADDR3264 ULONGLONG
|
# 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 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
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -507,13 +527,7 @@ static int pe_write(struct pe_info *pe)
|
|||||||
0x00004550, /* DWORD nt_sig = IMAGE_NT_SIGNATURE */
|
0x00004550, /* DWORD nt_sig = IMAGE_NT_SIGNATURE */
|
||||||
{
|
{
|
||||||
/* IMAGE_FILE_HEADER filehdr */
|
/* IMAGE_FILE_HEADER filehdr */
|
||||||
#if defined(TCC_TARGET_I386)
|
IMAGE_FILE_MACHINE, /*WORD Machine; */
|
||||||
0x014C, /*WORD Machine; */
|
|
||||||
#elif defined(TCC_TARGET_X86_64)
|
|
||||||
0x8664, /*WORD Machine; */
|
|
||||||
#elif defined(TCC_TARGET_ARM)
|
|
||||||
0x01C0, /*WORD Machine; */
|
|
||||||
#endif
|
|
||||||
0x0003, /*WORD NumberOfSections; */
|
0x0003, /*WORD NumberOfSections; */
|
||||||
0x00000000, /*DWORD TimeDateStamp; */
|
0x00000000, /*DWORD TimeDateStamp; */
|
||||||
0x00000000, /*DWORD PointerToSymbolTable; */
|
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)
|
static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -1539,7 +1535,7 @@ static int pe_load_res(TCCState *s1, int fd)
|
|||||||
if (!read_mem(fd, 0, &hdr, sizeof hdr))
|
if (!read_mem(fd, 0, &hdr, sizeof hdr))
|
||||||
goto quit;
|
goto quit;
|
||||||
|
|
||||||
if (hdr.filehdr.Machine != 0x014C
|
if (hdr.filehdr.Machine != IMAGE_FILE_MACHINE
|
||||||
|| hdr.filehdr.NumberOfSections != 1
|
|| hdr.filehdr.NumberOfSections != 1
|
||||||
|| strcmp(hdr.sectionhdr.Name, ".rsrc") != 0)
|
|| strcmp(hdr.sectionhdr.Name, ".rsrc") != 0)
|
||||||
goto quit;
|
goto quit;
|
||||||
@ -1556,7 +1552,7 @@ static int pe_load_res(TCCState *s1, int fd)
|
|||||||
if (!read_mem(fd, offs, &rel, sizeof rel))
|
if (!read_mem(fd, offs, &rel, sizeof rel))
|
||||||
goto quit;
|
goto quit;
|
||||||
// printf("rsrc_reloc: %x %x %x\n", rel.offset, rel.size, rel.type);
|
// 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;
|
goto quit;
|
||||||
put_elf_reloc(symtab_section, rsrc_section,
|
put_elf_reloc(symtab_section, rsrc_section,
|
||||||
rel.offset, R_XXX_RELATIVE, 0);
|
rel.offset, R_XXX_RELATIVE, 0);
|
||||||
|
@ -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
|
#endif
|
||||||
|
|
||||||
@ -173,10 +181,8 @@ char *get_export_names(int fd)
|
|||||||
DWORD sig, ref, addr, ptr, namep;
|
DWORD sig, ref, addr, ptr, namep;
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
IMAGE_OPTIONAL_HEADER64 oh;
|
IMAGE_OPTIONAL_HEADER64 oh;
|
||||||
const int MACHINE = 0x8664;
|
|
||||||
#else
|
#else
|
||||||
IMAGE_OPTIONAL_HEADER32 oh;
|
IMAGE_OPTIONAL_HEADER32 oh;
|
||||||
const int MACHINE = 0x014C;
|
|
||||||
#endif
|
#endif
|
||||||
int pef_hdroffset, opt_hdroffset, sec_hdroffset;
|
int pef_hdroffset, opt_hdroffset, sec_hdroffset;
|
||||||
|
|
||||||
@ -192,7 +198,7 @@ char *get_export_names(int fd)
|
|||||||
pef_hdroffset = dh.e_lfanew + sizeof sig;
|
pef_hdroffset = dh.e_lfanew + sizeof sig;
|
||||||
if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
|
if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
|
||||||
goto the_end;
|
goto the_end;
|
||||||
if (MACHINE != ih.Machine)
|
if (IMAGE_FILE_MACHINE != ih.Machine)
|
||||||
goto the_end;
|
goto the_end;
|
||||||
opt_hdroffset = pef_hdroffset + sizeof ih;
|
opt_hdroffset = pef_hdroffset + sizeof ih;
|
||||||
sec_hdroffset = opt_hdroffset + sizeof oh;
|
sec_hdroffset = opt_hdroffset + sizeof oh;
|
||||||
|
Loading…
Reference in New Issue
Block a user