58 lines · plain
1RUN: lld-link -lldmingw %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe2RUN: lld-link -lld-allow-duplicate-weak %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe3RUN: not lld-link %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe 2>&1 | FileCheck %s --check-prefix=DEFAULT-ERROR4 5DEFAULT-ERROR: error: duplicate symbol: weakfunc6 7 8GNU ld can handle several definitions of the same weak symbol, and9unless there is a strong definition of it, it just picks the first10weak definition encountered.11 12For each of the weak definitions, GNU tools produce a regular symbol13named .weak.<weaksymbol>.<othersymbol>, where the other symbol name is14another symbol defined close by.15 16This can't be reproduced by assembling with llvm-mc, as llvm-mc always17produces similar regular symbols named .weak.<weaksymbol>.default.18 19The bundled object files can be produced from test code that looks like20this:21 22$ cat gnu-weak.c23void 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.c41void 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.c50$ x86_64-w64-mingw32-gcc -c -O2 gnu-weak2.c51 52$ x86_64-w64-mingw32-nm gnu-weak.o | grep weakfunc530000000000000000 T .weak.weakfunc.main54 w weakfunc55$ x86_64-w64-mingw32-nm gnu-weak2.o | grep weakfunc560000000000000000 T .weak.weakfunc.otherfunc57 w weakfunc58