1 RUN: lld-link -lldmingw %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
2 RUN: lld-link -lld-allow-duplicate-weak %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
3 RUN: not lld-link %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe 2>&1 | FileCheck %s --check-prefix=DEFAULT-ERROR
5 DEFAULT-ERROR: error: duplicate symbol: weakfunc
8 GNU ld can handle several definitions of the same weak symbol, and
9 unless there is a strong definition of it, it just picks the first
10 weak definition encountered.
12 For each of the weak definitions, GNU tools produce a regular symbol
13 named .weak.<weaksymbol>.<othersymbol>, where the other symbol name is
14 another symbol defined close by.
16 This can't be reproduced by assembling with llvm-mc, as llvm-mc always
17 produces similar regular symbols named .weak.<weaksymbol>.default.
19 The bundled object files can be produced from test code that looks like
23 void weakfunc(void) __attribute__((weak));
26 __attribute__((weak)) void weakfunc() {
29 int main(int argc, char* argv[]) {
34 void mainCRTStartup(void) {
41 void weakfunc(void) __attribute__((weak));
43 __attribute__((weak)) void weakfunc() {
46 void otherfunc(void) {
49 $ x86_64-w64-mingw32-gcc -c -O2 gnu-weak.c
50 $ x86_64-w64-mingw32-gcc -c -O2 gnu-weak2.c
52 $ x86_64-w64-mingw32-nm gnu-weak.o | grep weakfunc
53 0000000000000000 T .weak.weakfunc.main
55 $ x86_64-w64-mingw32-nm gnu-weak2.o | grep weakfunc
56 0000000000000000 T .weak.weakfunc.otherfunc