[all-commits] [llvm/llvm-project] d1da64: [LLD] [MinGW] Implement the --exclude-symbols option

Martin Storsjö via All-commits all-commits at lists.llvm.org
Thu Aug 11 02:01:42 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d1da6469f9ea9b078276ee2e098241f0440468be
  Author: Martin Storsjö <martin at martin.st>
  Date:   2022-08-11 (Thu, 11 Aug 2022)

  Changed paths:
    M lld/COFF/Driver.cpp
    M lld/COFF/MinGW.cpp
    M lld/COFF/MinGW.h
    M lld/COFF/Options.td
    M lld/MinGW/Driver.cpp
    M lld/MinGW/Options.td
    M lld/docs/ReleaseNotes.rst
    A lld/test/COFF/exclude-symbols.s
    M lld/test/MinGW/driver.test

  Log Message:
  [LLD] [MinGW] Implement the --exclude-symbols option

This adds support for the existing GNU ld command line option, which
allows excluding individual symbols from autoexport (when linking a
DLL and no symbols are marked explicitly as dllexported).

Differential Revision: https://reviews.llvm.org/D130118

  Commit: 5d513ef6cf4646e64bbb1d5f8610afd530964588
  Author: Martin Storsjö <martin at martin.st>
  Date:   2022-08-11 (Thu, 11 Aug 2022)

  Changed paths:
    M lld/COFF/Driver.cpp
    M lld/COFF/Driver.h
    M lld/COFF/DriverUtils.cpp
    M lld/COFF/MinGW.cpp
    M lld/COFF/MinGW.h
    M lld/docs/ReleaseNotes.rst
    A lld/test/COFF/exclude-symbols-embedded.s

  Log Message:
  [LLD] [COFF] Add support for a new, mingw specific embedded directive -exclude-symbols:

This is an entirely new embedded directive - extending the GNU ld
command line option --exclude-symbols to be usable in embedded
directives too.

(GNU ld.bfd also got support for the same new directive, currently in
the latest git version, after the 2.39 branch.)

This works as an inverse to the regular embedded dllexport directives,
for cases when autoexport of all eligible symbols is performed.

Differential Revision: https://reviews.llvm.org/D130120

  Commit: c5b3de6745c37dd991430b9b88ff97c35b6fc455
  Author: Martin Storsjö <martin at martin.st>
  Date:   2022-08-11 (Thu, 11 Aug 2022)

  Changed paths:
    M llvm/docs/ReleaseNotes.rst
    M llvm/lib/IR/Mangler.cpp
    A llvm/test/CodeGen/X86/mingw-hidden.ll

  Log Message:
  [COFF] Emit embedded -exclude-symbols: directives for hidden visibility for MinGW

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

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 the llvm-mingw distribution, 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 the 15.x branch 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

This allows improving the current mingw dylib situation significantly,
by using the same hidden visibility options and attributes as on Unix.
With those in place, a current build of LLVM git main ends up at 35142
symbols instead of 64650.

For code using hidden visibility, this now requires linking with either
a current git lld or ld.bfd. (Older lld error out on the unknown
directives, older ld.bfd will successfully link, but will print huge
amounts of warnings.)

Differential Revision: https://reviews.llvm.org/D130121

Compare: https://github.com/llvm/llvm-project/compare/164067918725...c5b3de6745c3

More information about the All-commits mailing list