[llvm-bugs] [Bug 51100] New: ESI not preserved on clobber if used as base register
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Wed Jul 14 20:03:23 PDT 2021
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=51100
            Bug ID: 51100
           Summary: ESI not preserved on clobber if used as base register
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: klrehm123 at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, pengfei.wang at intel.com,
                    spatel+llvm at rotateright.com
If esi is used as a base pointer (i.e. in the case of dynamically sized allocas
on Windows x86), it won't properly be preserved even if marked as clobbered in
inline assembly. 
A practical example of this being an issue is with `rep movsb` (and by
extension the __movsb intrinsic): 
int test() {
    // fake dynamic alloca
    volatile auto size = 4;
    auto x = (int*)__builtin_alloca(size);
    *x = 1;
    int g;
    void *ptr = &g;
    int c = 4;
    // replicate __movsb intrinsic
    asm("rep movsb" : "+D"(ptr), "+S"(x), "+c"(c)::"memory");
    // miscompile here as esi is modified
    return g;
}  
https://godbolt.org/z/v3zqh8E96
This caused problems when LTO was used across different libraries that caused
two unrelated functions to be inlined.
`-mllvm -x86-use-base-pointer=false` fixes this by not using esi at all.
-- 
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/20210715/9a8c000b/attachment-0001.html>
    
    
More information about the llvm-bugs
mailing list