[Nasm-bugs] [Bug 3392401] macho64: ld: illegal text-relocation to ...for architecture x86_64

no-reply at bugzilla-nasm.gorcunov.org no-reply at bugzilla-nasm.gorcunov.org
Fri Apr 21 14:14:47 PDT 2017


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

--- Comment #2 from H. Peter Anvin <hpa at zytor.com> ---
OK, digging into it a bit more... the code in the two files is simply not
identical.

The clang code has:

ASM_GLOBAL ASM_PFX(CommonExceptionHandler)
    call    ASM_PFX(CommonExceptionHandler)

[which I believe is wrong -- declaring a symbol global should be done at the
point of defintion -- but it appears harmless in this case.]

The NASM code has:

extern ASM_PFX(CommonExceptionHandler)
    mov     rax, ASM_PFX(CommonExceptionHandler)

... which is a very different kind of relocation, for which the clang Mach-O
linker requires the linker option "-read_only_relocs suppress".

I have no idea why you changed the call to a mov and a call.  The plain call
should work, unless the target is more than 2^32-1 bytes away.  The mov creates
an absolute relocation, which requires the code to be patched at link time (for
an absolute executable) or runtime (for a position-independent executable); as
stated before, this is disabled in the Mach-O linker by default.

I see a number of other equally suspicious pieces of code, like:

    mov rax, HookAfterStubHeaderEnd
    jmp rax
HookAfterStubHeaderEnd:

Why?

    mov rax, HookAfterStubHeaderBegin

Should almost certainly be:

    lea rax, [HookAfterStubHeaderBegin]

... which is, in fact, what the clang code does:

    leaq         HookAfterStubHeaderBegin(%rip), %rax

In 64-bit mode, unlike in 32-bit mode, MOV and LEA (without a register) are not
equivalent, as LEA can use relative addresses, whereas MOV can use a full
64-bit immediate.

Now, NASM does generate relocations slightly differently from clang as, but I
think the first task needs to be to actually make the code match; until then I
fear we can't help you with this one.

-- 
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