0

On Cygwin POSIX symbols in libc.a are strong symbols (e.g. accept):

$ nm /usr/lib/libc.a | grep 'accept' -w
0000000000000000 T accept

while on Linux they are weak symbols (e.g. accept):

$ nm /usr/lib/x86_64-linux-gnu/libc.a |& grep 'accept' -w
accept.o:
0000000000000000 W accept
                 U accept
                 U accept
                 U accept
                 U accept

Note: having POSIX symbols in libc.a may be a bit unexpected.

However, why in Cygwin's libc.a POSIX symbols are strong symbols?

Example: If user has mylib.a containing the definition of accept and the mylib.a goes after the libc.a in the list of command line arguments, then the accept from the libc.a may be (and usually is) selected.


UPD. https://stackoverflow.com/a/2290838/1778275:

MSVC++ has __declspec(selectany) which covers part of the functionality of weak symbols.

pmor
  • 5,392
  • 4
  • 17
  • 36

1 Answers1

1

https://en.wikipedia.org/wiki/Weak_symbol

Weak Symbol are not available on COFF PE binary. It is also one of the reason why all symbols must be defined at compilation time.

matzeri
  • 8,062
  • 2
  • 15
  • 16
  • Is "weak symbol" == "weak external"? The [Microsoft Portable Executable and Common Object File Format Specification](https://courses.cs.washington.edu/courses/cse378/03wi/lectures/LinkerFiles/coff.pdf) has section 5.5.3. "Auxiliary Format 3: Weak Externals". – pmor Mar 20 '22 at 19:22