[llvm-bugs] [Bug 41575] New: r7 not saved/restored around inline asm blocks that kill it

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 23 18:31:55 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41575

            Bug ID: 41575
           Summary: r7 not saved/restored around inline asm blocks that
                    kill it
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: george.burgess.iv at gmail.com
                CC: llvm-bugs at lists.llvm.org, peter.smith at linaro.org,
                    Ties.Stuij at arm.com

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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190424/5d51c9d3/attachment.html>


More information about the llvm-bugs mailing list