1; At present, nasm doesn't seem to support PIC generation for Mach-O.
2; The PIC support code below is a little tricky.
3[extern func]
4        SECTION .rodata
5const_base:
6
7%define GOTOFF(got,sym) (got) + (sym) - const_base
8
9%imacro get_GOT 1
10        ; NOTE: this macro destroys ecx resister.
11        call    %%geteip
12        add     ecx, byte (%%ref - $)
13        jmp     short %%adjust
14%%geteip:
15        mov     ecx, [esp]
16        ret
17%%adjust:
18        push    ebp
19        xor     ebp,ebp         ; ebp = 0
20%ifidni %1,ebx  ; (%1 == ebx)
21        ; db 0x8D,0x9C + jmp near const_base =
22        ;   lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32)
23        db      0x8D,0x9C               ; 8D,9C
24        jmp     near const_base         ; E9,(const_base-%%ref)
25%%ref:
26%else  ; (%1 != ebx)
27        ; db 0x8D,0x8C + jmp near const_base =
28        ;   lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32)
29        db      0x8D,0x8C               ; 8D,8C
30        jmp     strict near const_base          ; E9,(const_base-%%ref)
31%%ref:  mov     %1, ecx
32%endif ; (%1 == ebx)
33        pop     ebp
34%endmacro
35
36SECTION .text
37
38jmp const_base
39
40get_GOT ebx
41
42jmp const_base
43
44call func
45
46ret
47