<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - r7 not saved/restored around inline asm blocks that kill it"
href="https://bugs.llvm.org/show_bug.cgi?id=41575">41575</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>r7 not saved/restored around inline asm blocks that kill it
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: ARM
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>george.burgess.iv@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org, Ties.Stuij@arm.com
</td>
</tr></table>
<p>
<div>
<pre>With clang trunk:
$ cat /tmp/repro.c
void escape(void *);
void Bar(int p0, int p1, int p2, int p3, int p4, int p5) {
register unsigned magic asm("r7") = 0x000f0002;
asm volatile("svc 0\n" : : "r"(magic) : "memory");
int local = p5;
escape(&local);
}
$ clang --target=arm-linux-gnueabihf -march=armv7-a -mthumb /tmp/repro.c -S -o
- -O2 -emit-llvm
<< snip >>
; Function Attrs: nounwind
define dso_local void @Bar(i32 %p0, i32 %p1, i32 %p2, i32 %p3, i32 %p4, i32
%p5) local_unnamed_addr #0 {
entry:
%local = alloca i32, align 4
tail call void asm sideeffect "svc 0\0A", "{r7},~{memory}"(i32 983042) #3,
!srcloc !3
%0 = bitcast i32* %local to i8*
call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #3
store i32 %p5, i32* %local, align 4, !tbaa !4
call void @escape(i8* nonnull %0) #3
call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #3
ret void
}
$ clang --target=arm-linux-gnueabihf -march=armv7-a -mthumb /tmp/repro.c -S -o
- -O2
<< snip >>
Bar:
.fnstart
@ %bb.0: @ %entry
.save {r6, r7, lr}
push {r6, r7, lr}
.setfp r7, sp, #4
add r7, sp, #4
.pad #4
sub sp, #4
movs r7, #2
movt r7, #15
@APP
svc #0
@NO_APP
ldr r0, [r7, #12]
str r0, [sp]
mov r0, sp
bl escape
add sp, #4
pop {r6, r7, pc}
So, we set up r7 as our fp, it gets clobbered by `magic` for inline asm to do
stuff with, and we proceed to use the `magic` value as though it was still our
pc in a later ldr.
As one who's not super familiar with our rules around inline asm, I'd assume
that `tail call void asm sideeffect "svc 0\0A", "{r7},~{memory}"(i32 983042)
#3, !srcloc !3` should emit code to save/restore r7, instead of leaving it in a
clobbered state.
FWIW, we have code that looks very similar to the non-reduced repro in
compiler-rt's clear_cache.c. That appears to work because r7 is a callee-saved
register, so I presume we save/restore everything properly there (and don't use
r7 as a fp).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>