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