Author Topic: issue about nasm2.11.08  (Read 12989 times)

Offline zhiliang

  • New Member
  • Posts: 1
issue about nasm2.11.08
« on: March 30, 2015, 07:51:23 AM »
When I use nasm2.11.08 to build RIP-relative addresses in MAC OSX 64bit , it will get error, but nasm2.11.06 will work well.
The code is as following
Code: [Select]
SECTION .rodata align=16
align 16
sse2_plane_inc_minus dw -7, -6, -5, -4, -3, -2, -1, 0
align 16
sse2_plane_inc dw 1, 2, 3, 4, 5, 6, 7, 8

;using of sse2_plane_inc_minus, sse2_plane_inc
movdqa xmm5, [sse2_plane_inc_minus]
movdqa xmm6, [sse2_plane_inc]

And I find There is one statement "Fix segmentation failure when rip addressing is used in macho64 backend" in the nasm release note of Version 2.11.08, is it related with this?
« Last Edit: March 30, 2015, 08:57:00 AM by zhiliang »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: issue about nasm2.11.08
« Reply #1 on: March 31, 2015, 04:11:58 PM »
I'm not familiar with OSX. You say "RIP-relative", but you don't seem to ask Nasm to do so (default is "abs").
Code: [Select]
SECTION .rodata align=16
align 16
sse2_plane_inc_minus dw -7, -6, -5, -4, -3, -2, -1, 0
align 16
sse2_plane_inc dw 1, 2, 3, 4, 5, 6, 7, 8

;using of sse2_plane_inc_minus, sse2_plane_inc
movdqa xmm5, [rel sse2_plane_inc_minus]
movdqa xmm6, [rel sse2_plane_inc]
... seems to fix it. Or "default rel". I don't know why we need to do that in "-f macho64", but we do. Does that solve your problem?

Thanks for the feedback on this, zhiliang! I don't think we have too many OSX users, so we need to hear from you if there's a problem.

Best,
Frank


Offline mstorsjo

  • Jr. Member
  • *
  • Posts: 2
Re: issue about nasm2.11.08
« Reply #2 on: April 02, 2015, 09:42:23 AM »
The code that zhiliang quoted wasn't the complete code, it does set "default rel" at the start of the file.

A full example that shows the issue is this:

Code: [Select]
default rel
bits 64

section .rodata
data dq 42
; comment out otherdata to make it work
otherdata dw 100

section .text

global _testFunc
_testFunc:
    mov rax, [data]
    ret

When run, this returns 0, not 42 as intended (when assesmbled with nasm 2.11.08). When assembled with an older version of nasm (such as 2.11.06) or with yasm, it works as intended.

The disassembly of this snippet, when assembled with 2.11.08, looks like this:

Code: [Select]
test.o:
(__TEXT,__text) section
_testFunc:
0000000000000000        movq    0xf8(%rip), %rax
0000000000000007        retq

With the earlier, working versions, it looks like this:

Code: [Select]
test.o:
(__TEXT,__text) section
_testFunc:
0000000000000000        movq    (%rip), %rax
0000000000000007        retq

Offline mstorsjo

  • Jr. Member
  • *
  • Posts: 2
Re: issue about nasm2.11.08
« Reply #3 on: April 04, 2015, 08:22:23 AM »
It seems like this is the same issue as was reported in http://bugzilla.nasm.us/show_bug.cgi?id=3392306.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: issue about nasm2.11.08
« Reply #4 on: April 05, 2015, 02:35:02 PM »
Thanks for the update, mstorsjo. I agree that it looks like the same bug - which means(?) that it has come to the attention of the development team. I just dropped 'em a note to be sure.

This is my attempt to disassemble the two files with ndisasm (-b64 -e0x120):
Code: [Select]
this is with 2.11.06

00000000  488B0500000000    mov rax,[rel 0x7]
00000007  C3                ret

I guess it's "right"?


this is with 2.11.08

00000000  488B05F8000000    mov rax,[rel 0xff]
00000007  C3                ret

Apparently not right.

Since I don't imagine the fix will be immediate, I can only suggest using 2.11.06 until 2.11.09 comes along (and then close your eyes and wish really really hard...).

Again, thanks to both of you for your feedback!

Best,
Frank