Mac OS X 64-bit build for errors: "dyld: no recordable segments" and "Trace / BPT trap"

When trying to run the following build program:

.globl start

start:
    pushq $0x0 
    movq $0x1, %rax
    subq $0x8, %rsp
    int $0x80

I get the following errors:

dyld: no writable segment
Trace/BPT trap

Any idea what could be causing this? A similar program works fine in a 32-bit build.

+5
source share
2 answers

OSX now requires your executable to have a writable data segment with content, so it can dynamically move and link your code. I don’t know why, perhaps for security reasons, perhaps because of the new RIP register. If you place the .data segment there (with some dummy content), you will avoid the "no write" error. IMO this is ld error.

64- syscall, . GCC-, _syscall PROCEDURE libSystem.dylib raw. Raw syscall, int 0x80. "int 0x80" 64- .

" GCC" , syscall , 32- , sys/syscall.h. , , syscall , ORing . . , ! ( NASM, )

; assemble with
; nasm -f macho64 -o syscall64.o syscall64.asm && ld -lc -ldylib1.o -e start -o syscall64 syscall64.o
extern _syscall
global start

[section .text align=16]
start:
    ; do it gcc-style
    mov rdi, 0x4 ; sys_write
    mov rsi, 1 ; file descriptor
    mov rdx, hello
    mov rcx, size
    call _syscall ; we're calling a procedure, not trapping.

    ;now let do it raw
    mov rax, 0x2000001 ; SYS_exit = 1 and is type 2 (bsd call)
    mov rdi, 0 ; Exit success = 0
    syscall ; faster than int 0x80, and legal!


[section .data align=16]
hello: db "hello 64-bit syscall!", 0x0a
size: equ $-hello

http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/mach/i386/syscall_sw.h , .

+9

32 64 . -, int $80 syscall, . 64- . - , 64- .

+2

All Articles