[LLVMbugs] [Bug 20889] New: Global initializers for selectany objects are not comdat associative

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Sep 9 15:25:24 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20889

            Bug ID: 20889
           Summary: Global initializers for selectany objects are not
                    comdat associative
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hans at chromium.org
                CC: david.majnemer at gmail.com, llvmbugs at cs.uiuc.edu,
                    rnk at google.com
            Blocks: 18887
    Classification: Unclassified

Consider the following code:

a.cc:

  #include <stdio.h>

  struct S {
    S() { printf("Hello!\n"); x = 42; }
    int x;
  };

  __declspec(selectany) S s;

  int main() {
    return s.x;
  }

b.cc:

  #include <stdio.h>

  struct S {
    S() { printf("Hello!\n"); x = 42; }
    int x;
  };

  __declspec(selectany) S s;

When compiled with clang-cl, this will run the global initializer for s twice.
With MSVC, it runs once.

This is because MSVC emits the initializer in a section that's associative with
s, but Clang uses a different approach.

We already have the code to do this in Clang, when using #pragma init_seg with
a non-default segment name. E.g., adding #pragma init_seg(".CRT$XCV") before
the declarations of s in the code above makes it work.

Maybe we should switch to always emit global initializers like this for win32.
Or mabye we should put InitSegAttr on selectany globals?

-- 
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/20140909/b1f1f3d2/attachment.html>


More information about the llvm-bugs mailing list