<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - [ARM] instrumentation code injection has user visible side-effects"
   href="http://llvm.org/bugs/show_bug.cgi?id=19317">19317</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[ARM] instrumentation code injection has user visible side-effects
          </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>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </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>compnerd@compnerd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When compiling with -pg, the instrumentation code injection appears to cause
user-visible side-effects.  This, in particular, breaks compiling Linux via
clang.

Consider the following minimal test case:

// RUN: %clang_cc1 -triple=armv7-linux -S %s -o - | FileCheck %s

void function(int i) {
  __asm__ __volatile__ (".ifnc %0, r0 ; .error \"ABI mismatch\" ; .endif" : :
"r"(i));
}

This translates to:

define void arm_aapcscc @function(i32 %i) {
entry:
  tail call void asm sideeffect ".ifnc $0, r0 ; .error \22ABI mismatch\22 ;
.endif", "r"(i32 %i)
  ret void
}

Awesome: argument i is being passed along to the function, which is going to be
in register r0 as per the AAPCS CC.

However, compiling this with profiling (-pg) does a slightly different thing
which is mostly correct:

declare void @mcount()

define void arm_aapcscc @function(i32 %i) {
entry:
  tail call void @mcount()
  tail call void asm sideeffect ".ifnc $0, r0 ; .error \22ABI mismatch\22 ;
.endif", "r"(i32 %i)
  ret void
}

This looks reasonable: the inserted mcount is what you would expect due to the
profiling.  And the argument is still passed along.

However, when target lowering: you end up with the following:

  push {r4, r11, lr}
  add r11, sp, #4
  mov r4, r0
  bl mcount
  @APP
  .ifnc r4, r0 ; .error "ABI mismatch" ; endif
  @NO_APP
  pop {r4, r11, pc}

So, we adjust the stack, save the parameters (since we have no idea what mcount
will do) and call mcount.  Now, we use the saved register (r4 is callee saved,
so we know it has the right value at this point) and pass it along to the side
effect (inline asm).  This is now visible to the user.</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>