]> granicus.if.org Git - yasm/commitdiff
macho32: Correctly output pc-relative non-external intersegment.
authorPeter Johnson <peter@tortall.net>
Sun, 1 Aug 2010 01:27:40 +0000 (01:27 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 1 Aug 2010 01:27:40 +0000 (01:27 -0000)
Reported by: Justin Lebar <justin.lebar@gmail.com>

svn path=/trunk/yasm/; revision=2345

modules/objfmts/macho/macho-objfmt.c
modules/objfmts/macho/tests/nasm32/Makefile.inc
modules/objfmts/macho/tests/nasm32/macho32-pic.asm [new file with mode: 0644]
modules/objfmts/macho/tests/nasm32/macho32-pic.hex [new file with mode: 0644]

index a3caae177e4a56ee24a7db3618d535d826967f11..c80e315aa27b9ffbe7a733c672ecf5c4a63b863e 100644 (file)
@@ -532,7 +532,7 @@ macho_objfmt_output_value(yasm_value *value, unsigned char *buf,
         if ((vis & YASM_SYM_EXTERN) || (vis & YASM_SYM_COMMON)) {
             reloc->ext = 1;
             info->msd->extreloc = 1;    /* section has external relocations */
-        } else if (!value->curpos_rel && !info->is_64) {
+        } else if (!info->is_64) {
             /*@dependent@*/ /*@null@*/ yasm_bytecode *sym_precbc;
 
             /* Local symbols need valued to their actual address */
index f850eceb6b1e7b2d7931fc588a13685df96d215e..d93e7ecf5c22eaabc18067b94592957861affcf4 100644 (file)
@@ -8,6 +8,8 @@ EXTRA_DIST += modules/objfmts/macho/tests/nasm32/machotest.asm
 EXTRA_DIST += modules/objfmts/macho/tests/nasm32/machotest.hex
 EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho-reloc.asm
 EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho-reloc.hex
+EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho32-pic.asm
+EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho32-pic.hex
 EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho32-sect.asm
 EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho32-sect.errwarn
 EXTRA_DIST += modules/objfmts/macho/tests/nasm32/macho32-sect.hex
diff --git a/modules/objfmts/macho/tests/nasm32/macho32-pic.asm b/modules/objfmts/macho/tests/nasm32/macho32-pic.asm
new file mode 100644 (file)
index 0000000..438923d
--- /dev/null
@@ -0,0 +1,46 @@
+; At present, nasm doesn't seem to support PIC generation for Mach-O.
+; The PIC support code below is a little tricky.
+[extern func]
+        SECTION .rodata
+const_base:
+
+%define GOTOFF(got,sym) (got) + (sym) - const_base
+
+%imacro get_GOT 1
+        ; NOTE: this macro destroys ecx resister.
+        call    %%geteip
+        add     ecx, byte (%%ref - $)
+        jmp     short %%adjust
+%%geteip:
+        mov     ecx, [esp]
+        ret
+%%adjust:
+        push    ebp
+        xor     ebp,ebp         ; ebp = 0
+%ifidni %1,ebx  ; (%1 == ebx)
+        ; db 0x8D,0x9C + jmp near const_base =
+        ;   lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32)
+        db      0x8D,0x9C               ; 8D,9C
+        jmp     near const_base         ; E9,(const_base-%%ref)
+%%ref:
+%else  ; (%1 != ebx)
+        ; db 0x8D,0x8C + jmp near const_base =
+        ;   lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32)
+        db      0x8D,0x8C               ; 8D,8C
+        jmp     strict near const_base          ; E9,(const_base-%%ref)
+%%ref:  mov     %1, ecx
+%endif ; (%1 == ebx)
+        pop     ebp
+%endmacro
+
+SECTION .text
+
+jmp const_base
+
+get_GOT ebx
+
+jmp const_base
+
+call func
+
+ret
diff --git a/modules/objfmts/macho/tests/nasm32/macho32-pic.hex b/modules/objfmts/macho/tests/nasm32/macho32-pic.hex
new file mode 100644 (file)
index 0000000..f81f708
--- /dev/null
@@ -0,0 +1,338 @@
+ce 
+fa 
+ed 
+fe 
+07 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+d8 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+c0 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+29 
+00 
+00 
+00 
+f4 
+00 
+00 
+00 
+29 
+00 
+00 
+00 
+07 
+00 
+00 
+00 
+07 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+5f 
+5f 
+74 
+65 
+78 
+74 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+5f 
+5f 
+54 
+45 
+58 
+54 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+29 
+00 
+00 
+00 
+f4 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+20 
+01 
+00 
+00 
+04 
+00 
+00 
+00 
+00 
+03 
+00 
+80 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+5f 
+5f 
+63 
+6f 
+6e 
+73 
+74 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+5f 
+5f 
+44 
+41 
+54 
+41 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+29 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+1d 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+18 
+00 
+00 
+00 
+40 
+01 
+00 
+00 
+01 
+00 
+00 
+00 
+4c 
+01 
+00 
+00 
+06 
+00 
+00 
+00 
+e9 
+24 
+00 
+00 
+00 
+e8 
+05 
+00 
+00 
+00 
+83 
+c1 
+13 
+eb 
+04 
+8b 
+0c 
+24 
+c3 
+55 
+31 
+ed 
+8d 
+9c 
+e9 
+0c 
+00 
+00 
+00 
+5d 
+e9 
+06 
+00 
+00 
+00 
+e8 
+d8 
+ff 
+ff 
+ff 
+c3 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+02 
+00 
+00 
+05 
+19 
+00 
+00 
+00 
+02 
+00 
+00 
+05 
+1f 
+00 
+00 
+00 
+02 
+00 
+00 
+05 
+24 
+00 
+00 
+00 
+00 
+00 
+00 
+0d 
+01 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+66 
+75 
+6e 
+63 
+00