LTO: Decide upfront whether to use opaque/non-opaque pointer types
authorMatthias Braun <matze@braunis.de>
Wed, 18 May 2022 03:33:22 +0000 (20:33 -0700)
committerMatthias Braun <matze@braunis.de>
Thu, 2 Jun 2022 01:05:53 +0000 (18:05 -0700)
commit850d53a197f9ffbf5708b7bd795056335e81e9b7
treeb603ba420faf60c193035255d61fd65ff031dc40
parenta92ed167f2c98d332ad7ce5b0544444b8e917bc0
LTO: Decide upfront whether to use opaque/non-opaque pointer types

LTO code may end up mixing bitcode files from various sources varying in
their use of opaque pointer types. The current strategy to decide
between opaque / typed pointers upon the first bitcode file loaded does
not work here, since we could be loading a non-opaque bitcode file first
and would then be unable to load any files with opaque pointer types
later.

So for LTO this:
- Adds an `lto::Config::OpaquePointer` option and enforces an upfront
  decision between the two modes.
- Adds `-opaque-pointers`/`-no-opaque-pointers` options to the gold
  plugin; disabled by default.
- `--opaque-pointers`/`--no-opaque-pointers` options with
  `-plugin-opt=-opaque-pointers`/`-plugin-opt=-no-opaque-pointers`
  aliases to lld; disabled by default.
- Adds an `-lto-opaque-pointers` option to the `llvm-lto2` tool.
- Changes the clang driver to pass `-plugin-opt=-opaque-pointers` to
  the linker in LTO modes when clang was configured with opaque
  pointers enabled by default.

This fixes https://github.com/llvm/llvm-project/issues/55377

Differential Revision: https://reviews.llvm.org/D125847
46 files changed:
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/CodeGen/thinlto-inline-asm2.c
clang/test/Driver/arm-float-abi-lto.c
clang/test/Driver/lto-no-opaque-pointers.c [new file with mode: 0644]
clang/test/Driver/lto-opaque-pointers.c [new file with mode: 0644]
clang/test/Driver/memtag_lto.c
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/ELF/Options.td
lld/test/ELF/lto/discard-value-names.ll
lld/test/ELF/lto/ltopasses-basic.ll
lld/test/ELF/lto/type-merge.ll
lld/test/ELF/lto/type-merge2.ll
lld/test/ELF/lto/wrap-unreferenced-before-codegen.test
llvm/docs/OpaquePointers.rst
llvm/include/llvm/LTO/Config.h
llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll
llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
llvm/test/LTO/Resolution/X86/alias-alias.ll
llvm/test/LTO/Resolution/X86/comdat.ll
llvm/test/LTO/Resolution/X86/ifunc2.ll
llvm/test/LTO/Resolution/X86/local-def-dllimport.ll
llvm/test/LTO/X86/Inputs/opaque-pointers.ll [new file with mode: 0644]
llvm/test/LTO/X86/cfi_jt_aliases.ll
llvm/test/LTO/X86/mix-opaque-typed.ll [new file with mode: 0644]
llvm/test/LTO/X86/type-mapping-bug4.ll
llvm/test/ThinLTO/X86/Inputs/import-constant.ll
llvm/test/ThinLTO/X86/cfi-devirt.ll
llvm/test/ThinLTO/X86/cfi-unsat.ll
llvm/test/ThinLTO/X86/devirt-after-icp.ll
llvm/test/ThinLTO/X86/devirt2.ll
llvm/test/ThinLTO/X86/devirt_check.ll
llvm/test/ThinLTO/X86/devirt_promote.ll
llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll
llvm/test/ThinLTO/X86/globals-import-blockaddr.ll
llvm/test/ThinLTO/X86/import-constant.ll
llvm/test/ThinLTO/X86/import-dsolocal.ll
llvm/test/ThinLTO/X86/index-const-prop-gvref-pie.ll
llvm/test/ThinLTO/X86/index-const-prop-gvref.ll
llvm/test/ThinLTO/X86/index-const-prop-linkage.ll
llvm/test/ThinLTO/X86/reference_non_importable.ll
llvm/test/ThinLTO/X86/weak_externals.ll
llvm/tools/gold/gold-plugin.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp