<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 --- - RuntimeDyld generates incorrect Stub Functions on Arm"
   href="http://llvm.org/bugs/show_bug.cgi?id=16002">16002</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>RuntimeDyld generates incorrect Stub Functions on Arm
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </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>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>andrew.woloszyn@gmail.com
          </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>On arm (tested on android) when generating stub functions for relocation.
RuntimeDyldImpl::createStubFunction the ldr instruction is generated, and then
the next instruction is designed to be the address in question.

So the intent is to have something like this (if my debugging is correct)
ldr [pc, pc+4]
0xdeadbeef //Address in question

So that we jump to the location

But when we actually go to resolve that address "resolveARMRelocation" we get
into ELF::R_ARM_ABS32 and simple Add Value to  this address.

Since it was never initialized (unless your memory allocator did it), we are
just adding Value to some unknown value

I think this is the correct solution, although you could also have
resolveARMRelocation just set the value (since I do not think there are any
valid ARM instructions that you could add a 32-bit value to, and get a
legitimate instruction)

Index: RuntimeDyld.cpp
===================================================================
--- RuntimeDyld.cpp     (revision 181708)
+++ RuntimeDyld.cpp     (working copy)
@@ -363,7 +363,9 @@
     // and stubs for branches Thumb - ARM and ARM - Thumb.
     uint32_t *StubAddr = (uint32_t*)Addr;
     *StubAddr = 0xe51ff004; // ldr pc,<label>
-    return (uint8_t*)++StubAddr;
+    StubAddr++;
+    *StubAddr=0;
+    return (uint8_t*)StubAddr;
   } else if (Arch == Triple::mipsel || Arch == Triple::mips) {
     uint32_t *StubAddr = (uint32_t*)Addr;
     // 0:   3c190000        lui     t9,%hi(addr).</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>