[llvm-bugs] [Bug 48924] New: Clang emits an extra entry in llvm.global_ctors when init_priority is used

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 28 11:53:53 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48924

            Bug ID: 48924
           Summary: Clang emits an extra entry in llvm.global_ctors when
                    init_priority is used
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210128/04fb4ba6/attachment.html>


More information about the llvm-bugs mailing list