diff options
author | Peter Johnson <peter@tortall.net> | 2010-08-01 01:27:40 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2010-08-01 01:27:40 +0000 |
commit | abaf3f7d492962bf624cc16b306cde6758ca9557 (patch) | |
tree | 8fb2c30b26043a7d4f34656dc332ad3a810fe0d2 | |
parent | a4024ab0ca1707b35e5c16822594627d15e53e53 (diff) | |
download | yasm-abaf3f7d492962bf624cc16b306cde6758ca9557.tar.gz |
macho32: Correctly output pc-relative non-external intersegment.
Reported by: Justin Lebar <justin.lebar@gmail.com>
svn path=/trunk/yasm/; revision=2345
-rw-r--r-- | modules/objfmts/macho/macho-objfmt.c | 2 | ||||
-rw-r--r-- | modules/objfmts/macho/tests/nasm32/Makefile.inc | 2 | ||||
-rw-r--r-- | modules/objfmts/macho/tests/nasm32/macho32-pic.asm | 46 | ||||
-rw-r--r-- | modules/objfmts/macho/tests/nasm32/macho32-pic.hex | 338 |
4 files changed, 387 insertions, 1 deletions
diff --git a/modules/objfmts/macho/macho-objfmt.c b/modules/objfmts/macho/macho-objfmt.c index a3caae17..c80e315a 100644 --- a/modules/objfmts/macho/macho-objfmt.c +++ b/modules/objfmts/macho/macho-objfmt.c @@ -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 */ diff --git a/modules/objfmts/macho/tests/nasm32/Makefile.inc b/modules/objfmts/macho/tests/nasm32/Makefile.inc index f850eceb..d93e7ecf 100644 --- a/modules/objfmts/macho/tests/nasm32/Makefile.inc +++ b/modules/objfmts/macho/tests/nasm32/Makefile.inc @@ -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 index 00000000..438923d1 --- /dev/null +++ b/modules/objfmts/macho/tests/nasm32/macho32-pic.asm @@ -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 index 00000000..f81f708c --- /dev/null +++ b/modules/objfmts/macho/tests/nasm32/macho32-pic.hex @@ -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 |