<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - clang emitting RIP-relative relocation for weak external on Windows x86-64"
   href="https://bugs.llvm.org/show_bug.cgi?id=37598">37598</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang emitting RIP-relative relocation for weak external on Windows x86-64
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>smeenai@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>compnerd@compnerd.org, llvm-bugs@lists.llvm.org, rnk@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>% cat reduced.ll
@Weak = extern_weak global i32
define i32* @getWeak() {
  ret i32* @Weak
}

% clang -target x86_64-windows-msvc -S -o - reduced.ll
        .text
        .def     getWeak;
        .scl    2;
        .type   32;
        .endef
        .globl  getWeak                 # -- Begin function getWeak
        .p2align        4, 0x90
getWeak:                                # @getWeak
# %bb.0:
        leaq    Weak(%rip), %rax
        retq
                                        # -- End function
        .weak   Weak

The issue is that LLVM implements weak symbols for COFF through the weak
external mechanism, and it emits an absolute symbol with the value of 0 to
serve as the fallback symbol. We'll therefore end up with a RIP-relative
relocation against an absolute symbol in the case where Weak isn't defined.

link errors out for this:
error LNK2016: absolute symbol 'Weak' used as target of REL32 relocation in
section 1

LLD accepts it silently; I'll file a separate bug for that.</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>