File: gnu-weak.test

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (57 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
RUN: lld-link -lldmingw %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
RUN: lld-link -lld-allow-duplicate-weak %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
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

DEFAULT-ERROR: error: duplicate symbol: weakfunc


GNU ld can handle several definitions of the same weak symbol, and
unless there is a strong definition of it, it just picks the first
weak definition encountered.

For each of the weak definitions, GNU tools produce a regular symbol
named .weak.<weaksymbol>.<othersymbol>, where the other symbol name is
another symbol defined close by.

This can't be reproduced by assembling with llvm-mc, as llvm-mc always
produces similar regular symbols named .weak.<weaksymbol>.default.

The bundled object files can be produced from test code that looks like
this:

$ cat gnu-weak.c
void weakfunc(void) __attribute__((weak));
void otherfunc(void);

__attribute__((weak)) void weakfunc() {
}

int main(int argc, char* argv[]) {
    otherfunc();
    weakfunc();
    return 0;
}
void mainCRTStartup(void) {
    main(0, (char**)0);
}
void __main(void) {
}

$ cat gnu-weak2.c
void weakfunc(void) __attribute__((weak));

__attribute__((weak)) void weakfunc() {
}

void otherfunc(void) {
}

$ x86_64-w64-mingw32-gcc -c -O2 gnu-weak.c
$ x86_64-w64-mingw32-gcc -c -O2 gnu-weak2.c

$ x86_64-w64-mingw32-nm gnu-weak.o | grep weakfunc
0000000000000000 T .weak.weakfunc.main
                 w weakfunc
$ x86_64-w64-mingw32-nm gnu-weak2.o | grep weakfunc
0000000000000000 T .weak.weakfunc.otherfunc
                 w weakfunc