1RUN: lld-link -lldmingw %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe 2RUN: lld-link -lld-allow-duplicate-weak %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe 3RUN: not lld-link %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe 2>&1 | FileCheck %s --check-prefix=DEFAULT-ERROR 4 5DEFAULT-ERROR: error: duplicate symbol: weakfunc 6 7 8GNU ld can handle several definitions of the same weak symbol, and 9unless there is a strong definition of it, it just picks the first 10weak definition encountered. 11 12For each of the weak definitions, GNU tools produce a regular symbol 13named .weak.<weaksymbol>.<othersymbol>, where the other symbol name is 14another symbol defined close by. 15 16This can't be reproduced by assembling with llvm-mc, as llvm-mc always 17produces similar regular symbols named .weak.<weaksymbol>.default. 18 19The bundled object files can be produced from test code that looks like 20this: 21 22$ cat gnu-weak.c 23void weakfunc(void) __attribute__((weak)); 24void otherfunc(void); 25 26__attribute__((weak)) void weakfunc() { 27} 28 29int main(int argc, char* argv[]) { 30 otherfunc(); 31 weakfunc(); 32 return 0; 33} 34void mainCRTStartup(void) { 35 main(0, (char**)0); 36} 37void __main(void) { 38} 39 40$ cat gnu-weak2.c 41void weakfunc(void) __attribute__((weak)); 42 43__attribute__((weak)) void weakfunc() { 44} 45 46void otherfunc(void) { 47} 48 49$ x86_64-w64-mingw32-gcc -c -O2 gnu-weak.c 50$ x86_64-w64-mingw32-gcc -c -O2 gnu-weak2.c 51 52$ x86_64-w64-mingw32-nm gnu-weak.o | grep weakfunc 530000000000000000 T .weak.weakfunc.main 54 w weakfunc 55$ x86_64-w64-mingw32-nm gnu-weak2.o | grep weakfunc 560000000000000000 T .weak.weakfunc.otherfunc 57 w weakfunc 58