[PATCH] D130121: [3/3] [COFF] Emit embedded -exclude-symbols: directives for hidden visibility for MinGW

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 19 13:27:08 PDT 2022


mstorsjo created this revision.
mstorsjo added reviewers: rnk, mati865, jeremyd2019.
Herald added subscribers: jsji, bzcheeseman, rriddle, pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a subscriber: stephenneuendorffer.
Herald added a project: LLVM.

This works with the automatic export of all symbols; in MinGW mode,
when a DLL has no explicit dllexports, it exports all symbols (except
for some that are hardcoded to be excluded, including some toolchain
libraries).

By hooking up the hidden visibility to the -exclude-symbols: directive,
the automatic export of all symbols can be controlled in an easier
way (with a mechanism that doesn't require strict annotation of every
single symbol, but which allows gradually marking more unnecessary
symbols as hidden).

The primary use case is dylib builds of LLVM/Clang. These can be done
in MinGW mode but not in MSVC mode, as MinGW builds can export all
symbols (and the calling code can use APIs without corresponding
dllimport directives). However, as all symbols are exported, it can
easily overflow the max number of exported symbols in a DLL (65536).

In llvm-mingw, only the X86, ARM and AArch64 backends are enabled;
for the LLVM 13.0.0 release, libLLVM-13.dll ended up with 58112 exported
symbols. For LLVM 14.0.0, it was 62015 symbols. Current builds of
git main end up at around 64650 symbols - i.e. extremely close to the
limit.

The msys2 packages of LLVM have had to progressively disable more
of their backends in their builds, to be able to keep building with a
dylib.

While the proper path forward would be to add complete visibility
annotations to all the APIs (an effort which was started in
https://reviews.llvm.org/D109192, but seems to have stalled currently),
this allows improving the current mingw dylib situation significantly,
by using the same -fvisibility-inlines-hidden option as on Unix
platforms, and by making LLVM_LIBRARY_VISIBILITY expand to
__attribute__ ((visibility("hidden"))).

With those in place, a current build of LLVM git main ends up at
35142 symbols instead of 64650. Without this, a mingw dylib build of
MLIR is impossible (as it exceeds the symbol limit).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130121

Files:
  llvm/lib/IR/Mangler.cpp
  llvm/test/CodeGen/X86/mingw-hidden.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130121.445927.patch
Type: text/x-patch
Size: 4755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220719/4658dc69/attachment.bin>


More information about the llvm-commits mailing list