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: unassignedclangb...@nondot.org
          Reporter: r...@google.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to