From: nasm-bot f. C. G. <gor...@gm...> - 2015-11-04 21:45:20
|
Commit-ID: 8aa9c2eb91b700a9dfdd587457d651f29499e816 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=8aa9c2eb91b700a9dfdd587457d651f29499e816 Author: Cyrill Gorcunov <gor...@gm...> AuthorDate: Thu, 5 Nov 2015 00:43:29 +0300 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Thu, 5 Nov 2015 00:43:29 +0300 output: macho64 -- Fix OUT_REL4ADR on bigendians We're converting address value into bigendian (on BE machine) and then continue doing arithmetics on top, which is of course incorrect. Instead do all operations first then convert to BE and write it into image. Reported-by: "H. Peter Anvin" <hp...@zy...> Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- output/outmac64.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/output/outmac64.c b/output/outmac64.c index d4ddeaa..b4a46d8 100644 --- a/output/outmac64.c +++ b/output/outmac64.c @@ -590,7 +590,7 @@ static void macho_output(int32_t secto, const void *data, case OUT_REL4ADR: p = mydata; - WRITELONG(p, *(int64_t *)data + 4 - size); + addr = *(int64_t *)data + 4 - size; if (section == secto) nasm_error(ERR_PANIC, "intra-section OUT_REL4ADR"); @@ -600,7 +600,7 @@ static void macho_output(int32_t secto, const void *data, " section base references"); } else { if (wrt == NO_SEG) { - *(int64_t *)mydata -= add_reloc(s, section, 1, 4, *(int64_t *)mydata); // X86_64_RELOC_SIGNED/BRANCH + addr -= add_reloc(s, section, 1, 4, addr); // X86_64_RELOC_SIGNED/BRANCH } else if (wrt == macho_gotpcrel_sect) { if (s->data->datalen > 1) { saa_fread(s->data, s->data->datalen-2, &gotload, 1); // Retrieve Instruction Opcode @@ -608,9 +608,9 @@ static void macho_output(int32_t secto, const void *data, gotload = 0; } if (gotload == 0x8B) { // Check for MOVQ Opcode - *(int64_t *)mydata -= add_reloc(s, section, 4, 4, *(int64_t *)mydata); // X86_64_GOT_LOAD (MOVQ load) + addr -= add_reloc(s, section, 4, 4, addr); // X86_64_GOT_LOAD (MOVQ load) } else { - *(int64_t *)mydata -= add_reloc(s, section, 3, 4, *(int64_t *)mydata); // X86_64_GOT + addr -= add_reloc(s, section, 3, 4, addr); // X86_64_GOT } } else { nasm_error(ERR_NONFATAL, "Mach-O format does not support" @@ -619,6 +619,7 @@ static void macho_output(int32_t secto, const void *data, } } + WRITELONG(p, addr); sect_write(s, mydata, 4L); break; |