[Nasm-bugs] [Bug 3392497] New: macho64: X86_64_RELOC_SIGNED used instead of X86_64_RELOC_BRANCH when converting internal reloc to external relic

noreply-nasm at gorcunov.org noreply-nasm at gorcunov.org
Sun Jul 8 14:29:57 PDT 2018


https://bugzilla.nasm.us/show_bug.cgi?id=3392497

            Bug ID: 3392497
           Summary: macho64: X86_64_RELOC_SIGNED used instead of
                    X86_64_RELOC_BRANCH when converting internal reloc to
                    external relic
           Product: NASM
           Version: 2.14 (development)
          Hardware: Macintosh
                OS: Mac OS
            Status: OPEN
          Severity: major
          Priority: Medium
         Component: Assembler
          Assignee: nobody at nasm.us
          Reporter: zenith432 at users.sourceforge.net
                CC: gorcunov at gmail.com, hpa at zytor.com, nasm-bugs at nasm.us
     Obtained from: Binary from nasm.us

NASM version 2.14rc15 compiled on Jul  6 2018

testcase to demonstrate bug
=========== demo.nasm
        section .text
        call sym
        ret

        section __TEXT,__moretext code align=16
sym:
        ret
===========

nasm -f macho64 demo.nasm
objdump -d -r -t demo.o
==========
demo.o: file format Mach-O 64-bit x86-64

Disassembly of section __TEXT,__text:
__text:
       0:       e8 00 00 00 00  callq   0 <__text+0x5>
                0000000000000001:  X86_64_RELOC_SIGNED  sym
       5:       c3      retq
Disassembly of section __TEXT,__moretext:
sym:
      10:       c3      retq
SYMBOL TABLE:
0000000000000010 l     F __TEXT,__moretext      sym
==========

The relocation X86_64_RELOC_SIGNED is used instead of X86_64_RELOC_BRANCH.

X86_64_RELOC_BRANCH is the correct one and is the one emitted by clang for such
code.

This is important because the new subsections_via_symbols feature causes such
conversions to be done regularly within a source file.

Here's a patch to fix it
==========
--- nasm-2.14rc15_orig/output/outmacho.c
+++ nasm-2.14rc15_work/output/outmacho.c
@@ -606,6 +606,8 @@ static int64_t add_reloc(struct section 
            adjust = bytes - sym->symv[0].key;
            r->snum = sym->initial_snum;
            r->ext = 1;
+           if (reltype == RL_BRANCH)
+               r->type = X86_64_RELOC_BRANCH;
        }
     }

==========
The patch is relative to the source for nasm-2.14rc15 in nasm.us download
section.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are watching all bug changes.


More information about the Nasm-bugs mailing list