<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 emits an extra entry in llvm.global_ctors when init_priority is used"
   href="https://bugs.llvm.org/show_bug.cgi?id=48924">48924</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang emits an extra entry in llvm.global_ctors when init_priority is used
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>LLVM Codegen
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider:

$ cat t.cpp
struct Foo {
  Foo();
  ~Foo();
};
Foo init_me __attribute__((init_priority(101)));

$ clang -cc1 -emit-llvm t.cpp -o - | grep -A2 GLOBAL_
@llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void
()*, i8* } { i32 101, void ()* @_GLOBAL__I_000101, i8* null }, { i32, void ()*,
i8* } { i32 65535, void ()* @_GLOBAL__sub_I_t.cpp, i8* null }]

; Function Attrs: noinline nounwind
--
define internal void @_GLOBAL__I_000101() #0 section ".text.startup" {
entry:
  call void @__cxx_global_var_init()
--
define internal void @_GLOBAL__sub_I_t.cpp() #0 section ".text.startup" {
entry:
  ret void


This file only needs a single entry in llvm.global_ctors and then .init_array /
.ctors / .CRT$XCU in the object file, but it has two.

We should probably fix this at the clang level. GlobalOpt could fix this, but
it runs away if it can't fold the higher priority initializer first.

This was reduced from libc++, which uses init_priority for std::cout et al
initialization.</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>