<html>
    <head>
      <base href="https://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 --- - RuntimeDyldCOFFI386 error on IMAGE_REL_I386_REL32 for global function address mapping"
   href="https://llvm.org/bugs/show_bug.cgi?id=26116">26116</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>RuntimeDyldCOFFI386 error on IMAGE_REL_I386_REL32 for global function address mapping
          </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>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Generic Execution Engine Support
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vivien.millet@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In RuntimeDyldCOFFI386.h
After Line: 151
We have : 
uint64_t Result = Sections[RE.Sections.SectionA].getLoadAddress() -
              Section.getLoadAddress() + RE.Addend - 4 - RE.Offset;

BUT
In case of global native C++ function mapping
(ExecutionEngine::addGlobalMapping(...)), RE.Sections.SectionA equals -1
(0xffffffff) which triggers a bad index assertion. 

Analysing and comparing to the In RuntimeDyldCOFFX86_64, we should treat a
special case when SectionA == -1 

I propose that code which works fine for me and retrieves on code generation
the good global address (i put the whole switch case)

 case COFF::IMAGE_REL_I386_REL32: {
      // 32-bit relative displacement to the target.
      uint64_t Result;
      if(RE.Sections.SectionA == static_cast<uint32_t>(-1))
      {
          uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.Offset);
          Value -= FinalAddress + 4;
          Result = Value + RE.Addend;
      }
      else
      {
          Result = Sections[RE.Sections.SectionA].getLoadAddress() -
              Section.getLoadAddress() + RE.Addend - 4 - RE.Offset;
      }
      assert(static_cast<int32_t>(Result) <= INT32_MAX &&
             "relocation overflow");
      assert(static_cast<int32_t>(Result) >= INT32_MIN &&
             "relocation underflow");
      DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
                   << " RelType: IMAGE_REL_I386_REL32"
                   << " TargetSection: " << RE.Sections.SectionA
                   << " Value: " << format("0x%08" PRIx32, Result) << '\n');
      writeBytesUnaligned(Result, Target, 4);
      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>