<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 --- - RuntimeDyldELF on ARM does not correctly handle repeated relocations (by MCJIT)"
   href="http://llvm.org/bugs/show_bug.cgi?id=16013">16013</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>RuntimeDyldELF on ARM does not correctly handle repeated relocations (by MCJIT)
          </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>Linux
          </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>david.tweed@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>Andrew Kaylor has noted that, unlike some other platforms' relocation routines,
RuntimeDyldELF::resolveARMRelocation is one of the ones which does not
correctly handle repeated relocations on a section, which amongst other
problems causes a segfault with MCJITTest's multiple_functions unittest on ARM
when the correct finalizeObject() call is used. (This appears linked to PR
15357, although that's about avoid repeated relocations to solve the problem
that way.) Quoting Andrew's original email:

[snipped] RuntimeDyldELF's failure to properly handle multiple applications of
relocation information in the case of ARM (and also MIPS, if I recall
correctly).  I think you could verify this by commenting out the call to
Dyld.resolveRelocations in MCJIT::loadObject.  (It really shouldn't be there
anyway.)

I'd prefer to have that test case disabled for ARM rather than have it use the
alternate implementation.  The alternate implementation passes for the wrong
reasons.  Even better would be to have the underlying problem fixed.

The thing that needs to change in RuntimeDyldELF to allow multiple relocations
on ARM is to use Section.ObjAddress to read any values that need to be
retrieved from the original object image.  For instance, the handler for
R_ARM_ABS32 and R_ARM_TARGET1 currently looks like this:

  case ELF::R_ARM_TARGET1 :
  case ELF::R_ARM_ABS32 :
    *TargetPtr += Value;
    break;

(where TargetPtr = Section.Address + Offset).  You can see how that ends up
with a wrong result the second time relocations are applied.

It should be doing something like this instead:

  case ELF::R_ARM_TARGET1 :
  case ELF::R_ARM_ABS32 :
    {
    uint32_t *Placeholder = reinterpret_cast<uint32_t*>(Section.ObjAddress +
Offset);
    *TargetPtr = *Placeholder + Value;
    }
    break;</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>