1 RUN: lld-link -lldmingw %S/Inputs/inline-weak.o %S/Inputs/inline-weak2.o -out:%t.exe
3 When compiling certain forms of templated inline functions, some
4 versions of GCC (tested with 5.4) produces a weak symbol for the function.
5 Newer versions of GCC don't do this though.
7 The bundled object files are an example of that, they can be produced
8 with test code like this:
13 template<typename... _Args> int get(_Args&&... args) {
21 #include "inline-weak.h"
25 int main(int argc, char* argv[]) {
31 extern "C" void mainCRTStartup(void) {
34 extern "C" void __main(void) {
37 $ cat inline-weak2.cpp
38 #include "inline-weak.h"
44 $ x86_64-w64-mingw32-g++ -std=c++11 -c inline-weak.cpp
45 $ x86_64-w64-mingw32-g++ -std=c++11 -c inline-weak2.cpp
47 $ x86_64-w64-mingw32-nm inline-weak.o | grep MyClass3get
48 0000000000000000 p .pdata$_ZN7MyClass3getIJEEEiDpOT_
49 0000000000000000 t .text$_ZN7MyClass3getIJEEEiDpOT_
50 0000000000000000 T .weak._ZN7MyClass3getIIEEEiDpOT_.main
51 0000000000000000 r .xdata$_ZN7MyClass3getIJEEEiDpOT_
52 w _ZN7MyClass3getIIEEEiDpOT_
53 0000000000000000 T _ZN7MyClass3getIJEEEiDpOT_
55 $ x86_64-w64-mingw32-nm inline-weak2.o | grep MyClass3get
56 0000000000000000 p .pdata$_ZN7MyClass3getIJEEEiDpOT_
57 0000000000000000 t .text$_ZN7MyClass3getIJEEEiDpOT_
58 0000000000000000 T .weak._ZN7MyClass3getIIEEEiDpOT_._Z3getR7MyClass
59 0000000000000000 r .xdata$_ZN7MyClass3getIJEEEiDpOT_
60 w _ZN7MyClass3getIIEEEiDpOT_
61 0000000000000000 T _ZN7MyClass3getIJEEEiDpOT_
63 This can't be reproduced by assembling .s files with llvm-mc, since that
64 always produces a symbol named .weak.<weaksymbol>.default, therefore
65 the test uses prebuilt object files instead.
67 In these cases, the undefined weak symbol points to the regular symbol
68 .weak._ZN7MyClass3getIIEEEiDpOT_.<othersymbol>, where <othersymbol>
69 varies among the object files that emit the same function. This regular
70 symbol points to the same location as the comdat function
71 _ZN7MyClass3getIJEEEiDpOT_.
73 When linking, the comdat section from the second object file gets
74 discarded, as it matches the one that already exists. This means that
75 the uniquely named symbol .weak.<weakname>.<othername> points to a
76 discarded section chunk.
78 Previously, this would have triggered adding an Undefined symbol for
79 this case, which would later break linking. However, also previously,
80 if the second object file is linked in via a static library, this
81 leftover symbol is retained as a Lazy symbol, which would make the link