Hi Richard,<br><br>My belief is that we don't fully support this syntax. I believe, and I'm sure Renato on CC will tell me if I'm wrong as he implemented it, that we only support this for non-allocatable registers, such as SP or FP. <br><br>Cheers,<br><br>James<br><div class="gmail_quote">On Tue, 10 Feb 2015 at 21:29, Richard Pennington <<a href="mailto:rich@pennware.com">rich@pennware.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm porting the musl C library to ARM Thumb. It looks like inline asm is<br>
failing in some cases. Here's one:<br>
<br>
The lseek system call looks like this:<br>
...<br>
off_t result;<br>
return syscall(SYS__llseek, fd, offset>>32, offset, &result,<br>
whence) ? -1 : result;<br>
...<br>
<br>
Which eventually goes through this macro:<br>
<br>
static inline long __syscall5(long n, long a, long b, long c, long d,<br>
long e)<br>
{<br>
register long r7 __asm__("r7") = n;<br>
register long r0 __asm__("r0") = a;<br>
register long r1 __asm__("r1") = b;<br>
register long r2 __asm__("r2") = c;<br>
register long r3 __asm__("r3") = d;<br>
register long r4 __asm__("r4") = e;<br>
__asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3),<br>
"r"(r4));<br>
}<br>
<br>
And then this macro:<br>
#define __asm_syscall(...) do { \<br>
__asm__ __volatile__ ( "svc 0" \<br>
: "=r"(r0) : __VA_ARGS__ : "memory"); \<br>
return r0; \<br>
} while (0)<br>
<br>
Gives:<br>
Disassembly of section .text:<br>
<br>
00000000 <lseek>:<br>
0: b590 push {r4, r7, lr}<br>
2: af01 add r7, sp, #4<br>
4: b083 sub sp, #12<br>
6: 278c movs r7, #140 ; 0x8c<br>
8: 46ec mov ip, sp<br>
a: 4619 mov r1, r3<br>
c: 68bc ldr r4, [r7, #8] ; XXX r7 is clobbered here.<br>
e: 4663 mov r3, ip<br>
10: df00 svc 0<br>
12: f7ff fffe bl 0 <__syscall_ret><br>
16: 9a00 ldr r2, [sp, #0]<br>
18: 9901 ldr r1, [sp, #4]<br>
1a: 2800 cmp r0, #0<br>
1c: bf1c itt ne<br>
1e: f04f 32ff movne.w r2, #4294967295 ; 0xffffffff<br>
22: f04f 31ff movne.w r1, #4294967295 ; 0xffffffff<br>
26: 4610 mov r0, r2<br>
28: b003 add sp, #12<br>
2a: bd90 pop {r4, r7, pc}<br>
<br>
The question is, does the line<br>
<br>
register long r7 __asm__("r7") = n;<br>
<br>
make any guarantee about the value of r7 in the asm block?<br>
<br>
Adding the -fomit-frame-pointer flag fixes it, but is the bug in the<br>
code or in the compiler?<br>
<br>
-Rich<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>