Community
cancel
Showing results for 
Search instead for 
Did you mean: 
srimks
New Contributor II
63 Views

RBX: Segmentation Error.

Hello,

I have a section of GNU-syntax Inline ASM executed on Intel Xeon 5345 Linux x86_64 as below -

------
__asm__{
"pushq %rbp \n\t"
"movq %rsp, %rbp \n\t"

"subq $88, %rsp \n\t"
"movq %rdi, %r9 \n\t"
"movq %rdx, %r8 \n\t"
"movslq %ecx, %r10 \n\t"
"xorl %edi, %edi \n\t"
"xorl %ecx, %ecx \n\t"
"xorl %eax, %eax \n\t"
"testq %r10,%r10 \n\t"

"jle B9\n\t"

"movq %r10, 48(%rsp) \n\t"
"movq %rdx, 56(%rsp) \n\t"
"movq %rbx, 40(%rsp) \n\t"
"movq %rax,%rbx \n\t"
"movq %r12, 32(%rsp) \n\t"
"movq %r13, 24(%rsp) \n\t"
"movq %r14, (%rsp) \n\t"
"movq %r15, 8(%rsp) \n\t"
"movq%rsi, %r15 \n\t"
"movq %rbp, 16(%rsp) \n\t"
"movq %rcx, %rbp \n\t"
"movq %rdi, %r12 \n\t"
"movq %r8, %r13 \n\t"
"movq %r9, %r14 \n\t"

"B3: \n\t"
"movsd192(%rsp,%r12,8), %xmm0 \n\t"
"movsd (%rip), %xmm1 \n\t"
"call fmod \n\t"

"call __libm_sse2_sincos\n\t"

"movsd (%rip), %xmm15 \n\t"
"movslq (%r13), %r10 \n\t"
"movss(%rbx,%r15),%xmm4 \n\t"
...
...
"B9 \n\t"
"addq $88, %rsp \n\t"
"popq %rbp \n\t"
);
}
--

If I comment above block asm code in black "movq%rax,%rbx" and "movss(%rbx,%r15),%xmm4", I don't get Segmentation Error on GDB debugging. The compilation using ICC-v11.0 and linking on x86_64 is fine, but while debugging the generated exe., it gives SEGV ERROR.

How do I replace above SEGV ERROR?

~BR

0 Kudos
3 Replies
SHIH_K_Intel
Employee
63 Views

Quoting - srimks
Hello,

I have a section of GNU-syntax Inline ASM executed on Intel Xeon 5345 Linux x86_64 as below -

------
__asm__{
"pushq %rbp nt"
"movq %rsp, %rbp nt"

"subq $88, %rsp nt"
"movq %rdi, %r9 nt"
"movq %rdx, %r8 nt"
"movslq %ecx, %r10 nt"
"xorl %edi, %edi nt"
"xorl %ecx, %ecx nt"
"xorl %eax, %eax nt"
"testq %r10,%r10 nt"

"jle B9nt"

"movq %r10, 48(%rsp) nt"
"movq %rdx, 56(%rsp) nt"
"movq %rbx, 40(%rsp) nt"
"movq %rax,%rbx nt"
"movq %r12, 32(%rsp) nt"
"movq %r13, 24(%rsp) nt"
"movq %r14, (%rsp) nt"
"movq %r15, 8(%rsp) nt"
"movq%rsi, %r15 nt"
"movq %rbp, 16(%rsp) nt"
"movq %rcx, %rbp nt"
"movq %rdi, %r12 nt"
"movq %r8, %r13 nt"
"movq %r9, %r14 nt"

"B3: nt"
"movsd192(%rsp,%r12,8), %xmm0 nt"
"movsd (%rip), %xmm1 nt"
"call fmod nt"

"call __libm_sse2_sincosnt"

"movsd (%rip), %xmm15 nt"
"movslq (%r13), %r10 nt"
"movss(%rbx,%r15),%xmm4 nt"
...
...
"B9 nt"
"addq $88, %rsp nt"
"popq %rbp nt"
);
}
--

If I comment above block asm code in black "movq%rax,%rbx" and "movss(%rbx,%r15),%xmm4", I don't get Segmentation Error on GDB debugging. The compilation using ICC-v11.0 and linking on x86_64 is fine, but while debugging the generated exe., it gives SEGV ERROR.

How do I replace above SEGV ERROR?

~BR


Look to me like,"xorl on eax", leaves the high bits of RAX uninitialized, depending on runtime murphy's law, it's probably memory referencing non-canonical address.
srimks
New Contributor II
63 Views


Look to me like,"xorl on eax", leaves the high bits of RAX uninitialized, depending on runtime murphy's law, it's probably memory referencing non-canonical address.
Appreciate your reply.

Could you suggest some effective debugging techniques for debugging GNU-syntax Inline Asm code as above on Linux x86_64 for Intel Xeon 5345 specially SSE XMM registers.

I am fimilar with GDB & IDB which I am using right now.

~BR

SHIH_K_Intel
Employee
63 Views

Quoting - srimks
Appreciate your reply.

Could you suggest some effective debugging techniques for debugging GNU-syntax Inline Asm code as above on Linux x86_64 for Intel Xeon 5345 specially SSE XMM registers.

I am fimilar with GDB & IDB which I am using right now.

~BR


My compiler friend reminded me I forgot about the xorl special idiom. Despite that, the cause for non-canonical memory reference might be due to pasting compiler generated asm listing. In 64-bit mode, compiler would use RIP-relative addressing to reference static data, whereas hand coding asm usually would declare them. Neglecting these differences could be frequent causes of non-cononical references.

I think it's better to write code with correct syntax instead of trying to debug it. ButI admit I didn't practice that all the time, and let debugger be my teacher sometimes. But seriously, for gnu style asm, look at open source library, such as glibc, there arelots of asm stuff to look at and not too difficult to imitate and adapt.