<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 - Using a private global as a global_ctor key fails when emitting a COFF object"
   href="https://bugs.llvm.org/show_bug.cgi?id=38607">38607</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Using a private global as a global_ctor key fails when emitting a COFF object
          </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>Windows NT
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rnk@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>david.majnemer@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this LLVM IR:

@x = private global i32 0
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }]
  [{ i32, void ()*, i8* }
   { i32 65535,
     void ()* @register_x,
     i8* bitcast (i32* @x to i8*) }]
define internal void @register_x() {
  ret void
}

We can generate asm for it, but we cannot assemble it to an object. We emit:

$ llc t.ll -o t.o -filetype=obj
LLVM ERROR: Missing associated COMDAT section for section .CRT$XCU

Mechanically, what happens is we try to look up a private label (.Lx) in the
COFF symbol table that we're making, we use GetOrCreate on it, but we don't
have a section for it, so we issue this diagnostic.

However, the input LLVM IR makes some sense. We should run the initializer if
and only if @x is included in the final link, and it's not comdat, so it will
be included, and we can just ignore it and always put @register_x in the main
.CRT$XCU section.

The question is, should we accept the assembly that we generate today?

        .section        .rdata,"dr"
        .p2align        2               # @x
.Lx:
        .long   0                       # 0x0

        .section        .CRT$XCU,"dr",associative,.Lx
        .p2align        3
        .quad   register_x

Does that assembly make sense, i.e. make this .CRT$XCU section associative with
the non-comdat .rdata section?</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>