[llvm-bugs] [Bug 25477] New: Clang forms weak external COFF aliases to base class destructors which fail to link

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 10 10:23:53 PST 2015


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

            Bug ID: 25477
           Summary: Clang forms weak external COFF aliases to base class
                    destructors which fail to link
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: david.majnemer at gmail.com, llvm-bugs at lists.llvm.org,
                    rafael.espindola at gmail.com
    Classification: Unclassified

Consider:

$ cat t.cpp
struct A {
  virtual ~A();
};
template <typename T> struct B : A {
  virtual ~B() {}
};
#ifdef CONFIG1
A::~A() {}
template struct B<int>;
#else
extern template struct B<int>;
int main() { B<int> b; }
#endif

$ clang-cl -O1 t.cpp -DCONFIG1 -c -Fot1.obj

$ clang-cl t.cpp -Fot2.obj -c

$ link t1.obj t2.obj -out:t.exe
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

t1.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl
B<int>::~B<int>(void)" (??1?$B at H@@UEAA at XZ)
t2.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl
B<int>::~B<int>(void)" (??1?$B at H@@UEAA at XZ)
t.exe : fatal error LNK1120: 1 unresolved externals

So, the Microsoft linker does not appear to work the way we think it does with
regard to weak externals. I reduced this from STLPort, which uses extern
template instantiations like these for basic_ios.

I guess I'll change this stuff that looks for dllexport to look for COFF
instead:
  // Don't create a weak alias for a dllexport'd symbol.
  if (AliasDecl.getDecl()->hasAttr<DLLExportAttr>() &&
      llvm::GlobalValue::isWeakForLinker(Linkage))
    return true;

-- 
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/20151110/4983cdee/attachment.html>


More information about the llvm-bugs mailing list