ucrtbase: Make sure that compat symbols aren't autoexported
When linking a DLL without using dllexport attributes or a def
file, all global symbols are exported, unless they are excluded
for one reason or another. GNU ld has got a list of libraries and
object files to exclude, so any symbols from e.g. libmingwex or
libmingw32 or dllcrt2.o won't get exported.
However, libmsvcrt is missing from that list (and libucrtbase
obviously isn't present either). In LLD, libmsvcrt and libucrtbase
are part of the library exclude list.
By linking with -Wl,--exclude-libs,libucrtbase.a, one can manually
request to exclude any symbols from this library.
There are a number of exceptions to the rules for autoexporting
(which aren't clearly documented but can be found in ld/pe-dll.c
in GNU binutils). One that seems to cover the cases that currently
are found in libmsvcrt.a, explaining why such symbols haven't
been exported before, is that a symbol foo won't be exported, if a
corresponding symbol __imp_foo also is defined.
We can use this to add __imp_ prefixed symbols for symbols that
strictly don't need it (where no calling code currently refers to
it with a dllimport attribute).
Make the _CRTALLOC pointer static with an attribute indicating that
it is used and should be kept even though unreferenced.
All in all, this avoids exporting unintentional symbols from DLLs
that link to ucrtbase, even though it might be desireable to
add libmsvcrt and libucrtbase to the built-in exclude list as well.
Signed-off-by: Martin Storsjö <martin@martin.st>
10 files changed