[all-commits] [llvm/llvm-project] 2c2fb0: [llvm] Use hidden visibility when building for Min...

Martin Storsjö via All-commits all-commits at lists.llvm.org
Thu Aug 11 14:58:21 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2c2fb0c7375061147711cd21396d79faad7dfdfb
      https://github.com/llvm/llvm-project/commit/2c2fb0c7375061147711cd21396d79faad7dfdfb
  Author: Martin Storsjö <martin at martin.st>
  Date:   2022-08-12 (Fri, 12 Aug 2022)

  Changed paths:
    M llvm/cmake/modules/HandleLLVMOptions.cmake
    M llvm/include/llvm/Support/Compiler.h
    M llvm/lib/Target/CMakeLists.txt

  Log Message:
  -----------
  [llvm] Use hidden visibility when building for MinGW with Clang

Since c5b3de6745c37dd991430b9b88ff97c35b6fc455 (git main,
August 11th), Clang does generate working hidden visibility
on MinGW targets. Using that reduces the number of exports from
a dylib build of LLVM significantly, which is vital for fitting
within the limit of 64k exported symbols from a DLL.

It's essential that if we set CMAKE_CXX_VISIBILITY_PRESET=hidden
(which passes -fvisibility=hidden on the command line), we also
must define LLVM_EXTERNAL_VISIBILITY consistently to override
it. (If there are mismatches, e.g. setting hidden visibility generally
but never overriding it back to default for the symbols that do need
to be exported, we'd get broken builds in such configurations.)

We don't want to be using __attribute__((visibility("hidden"))) on
MinGW with GCC, because GCC produces a warning about it. (GCC hasn't
warned about the command line options that set hidden visibility
though.) Clang has historically not warned about either of them, so
it is harmless to use the hidden visibility when building with older
Clang (so we don't need to detect the exact version of Clang/LLVM where
it has an effect).

This reduces the number of exported symbols for a dylib build of LLVM;
previously libLLVM exported around 64650 symbols (when the maximum is
65536) when the ARM, AArch64 and X86 targets were enabled. If enabling
more targets (or if building with e.g. assertions enabled), it would
exceed the limit. Now with visibility flags in use, the same build
with ARM, AArch64 and X86 ends up at around 35k exported symbols.

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




More information about the All-commits mailing list