From 84f6860ed53492976c9d79e9a8a0bdc60da78bc6 Mon Sep 17 00:00:00 2001 From: Zenith432 Date: Mon, 9 May 2016 11:16:10 -0700 Subject: [PATCH] outmacho: Fix relative relocations for 32-bit Mach-O IP-relative relocations were broken for 32-bit Mach-O when referencing external symbols after the Mach-O backends were merged. This fixes bug reports 3392348, 3392352, and 3392346. Signed-off-by: H. Peter Anvin --- output/outmacho.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/output/outmacho.c b/output/outmacho.c index 26a62ea6..70936ecb 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -465,6 +465,8 @@ static int64_t add_reloc(struct section *sect, int32_t section, r->snum = raa_read(extsyms, section); if (reltype == RL_BRANCH) r->type = X86_64_RELOC_BRANCH; + else if (reltype == GENERIC_RELOC_VANILLA) + adjust = -sect->size; } else { /* local */ r->ext = 0; @@ -1321,6 +1323,8 @@ static void macho_write_section (void) l += sectstab[r->snum]->addr; if (r->pcrel) l -= s->addr; + } else if (r->pcrel && r->type == GENERIC_RELOC_VANILLA) + l -= s->addr; } /* write new offset back */