From: Peter Johnson Date: Wed, 28 Sep 2005 03:23:24 +0000 (-0000) Subject: * coff-objfmt.c (coff_objfmt_output_expr): Change relocations output for X-Git-Tag: v0.5.0rc1~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=253056c994bdb3c82ee6820678e52101885255b9;p=yasm * coff-objfmt.c (coff_objfmt_output_expr): Change relocations output for instructions in Win64 to always be REL32 regardless of whether they're RIP relative or not. I don't understand this behavior, but it matches how ML64 generates relocs and unbreaks linking. The handling of this case must be handled at a higher level somehow (either at the linker or the compiler). Note that this REL32 generation behavior of ML64 happens only with the latest version (VC8); the 2003 SP1 SDK ML64 doesn't do this. * bytecode.c (yasm_bc_is_data): New supporting function. * bytecode.h (yasm_bc_is_data): Prototype. Testcase pending. Reported by and much debugging support contributed by: Brian Gladman . Thanks! svn path=/trunk/yasm/; revision=1251 --- diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 2c212b04..d2e658de 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -432,6 +432,12 @@ yasm_bc_create_data(yasm_datavalhead *datahead, unsigned int size, return yasm_bc_create_common(&bc_data_callback, data, line); } +int +yasm_bc_is_data(const yasm_bytecode *bc) +{ + return (bc->callback == &bc_data_callback); +} + static void bc_reserve_destroy(void *contents) { diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 79d940b9..daf56e8a 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -141,6 +141,12 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); /*@only@*/ yasm_bytecode *yasm_bc_create_data (yasm_datavalhead *datahead, unsigned int size, unsigned long line); +/** Find out if a bytecode is a data bytecode. + * \param bc bytecode + * \return Nonzero if bytecode is a data bytecode, otherwise 0. + */ +int yasm_bc_is_data(const yasm_bytecode *bc); + /** Create a bytecode reserving space. * \param numitems number of reserve "items" (kept, do not free) * \param itemsize reserved size (in bytes) for each item diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 178417ed..48504739 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -435,8 +435,16 @@ coff_objfmt_output_expr(yasm_expr **ep, unsigned char *buf, size_t destsize, if (valsize == 32) { if (info->csd->flags2 & COFF_FLAG_NOBASE) reloc->type = COFF_RELOC_AMD64_ADDR32NB; - else + else if (yasm_bc_is_data(bc)) reloc->type = COFF_RELOC_AMD64_ADDR32; + else { + /* I don't understand this, but ML64 generates REL32 + * for all instructions, regardless of whether they + * are RIP relative. Obviously this is either handled + * by the linker or by the compiler at a higher level! + */ + reloc->type = COFF_RELOC_AMD64_REL32; + } } else if (valsize == 64) reloc->type = COFF_RELOC_AMD64_ADDR64; else {