[all-commits] [llvm/llvm-project] 272bd6: [WPD][LLD] Add option to validate RTTI is enabled ...

modiking via All-commits all-commits at lists.llvm.org
Mon Sep 18 15:52:28 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 272bd6f9cc86bf6b4dd6bd51e85c46db10e8b86a
      https://github.com/llvm/llvm-project/commit/272bd6f9cc86bf6b4dd6bd51e85c46db10e8b86a
  Author: modimo <modimo at fb.com>
  Date:   2023-09-18 (Mon, 18 Sep 2023)

  Changed paths:
    M lld/ELF/Config.h
    M lld/ELF/Driver.cpp
    M lld/ELF/LTO.cpp
    M lld/ELF/Options.td
    A lld/test/ELF/lto/Inputs/devirt_validate_vtable_typeinfos.ll
    A lld/test/ELF/lto/Inputs/devirt_validate_vtable_typeinfos_no_rtti.ll
    A lld/test/ELF/lto/Inputs/devirt_validate_vtable_typeinfos_ref.ll
    A lld/test/ELF/lto/Inputs/devirt_validate_vtable_typeinfos_undef.ll
    A lld/test/ELF/lto/devirt_validate_vtable_typeinfos.ll
    A lld/test/ELF/lto/devirt_validate_vtable_typeinfos_mixed_lto.ll
    A lld/test/ELF/lto/devirt_validate_vtable_typeinfos_no_rtti.ll
    A lld/test/ELF/lto/devirt_validate_vtable_typeinfos_ref.ll
    M llvm/include/llvm/LTO/Config.h
    M llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
    M llvm/lib/LTO/LTO.cpp
    M llvm/lib/LTO/LTOCodeGenerator.cpp
    M llvm/lib/LTO/ThinLTOCodeGenerator.cpp
    M llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
    M llvm/tools/opt/opt.cpp

  Log Message:
  -----------
  [WPD][LLD] Add option to validate RTTI is enabled on all native types and prevent devirtualization on types with native RTTI

Discussion about this approach: https://discourse.llvm.org/t/rfc-safer-whole-program-class-hierarchy-analysis/65144/18

When enabling WPD in an environment where native binaries are present, types we want to optimize can be derived from inside these native files and devirtualizing them can lead to correctness issues. RTTI can be used as a way to determine all such types in native files and exclude them from WPD providing a safe checked way to enable WPD.

The approach is:
1. In the linker, identify if RTTI is available for all native types. If not, under `--lto-validate-all-vtables-have-type-infos` `--lto-whole-program-visibility` is automatically disabled. This is done by examining all .symtab symbols in object files and .dynsym symbols in DSOs for vtable (_ZTV) and typeinfo (_ZTI) symbols and ensuring there's always a match for every vtable symbol.
2. During thinlink, if `--lto-validate-all-vtables-have-type-infos` is set and RTTI is available for all native types, identify all typename (_ZTS) symbols via their corresponding typeinfo (_ZTI) symbols that are used natively or outside of our summary and exclude them from WPD.

Testing:
ninja check-all
large Meta service that uses boost, glog and libstdc++.so runs successfully with WPD via --lto-whole-program-visibility. Previously, native types in boost caused incorrect devirtualization that led to crashes.

Reviewed By: MaskRay, tejohnson

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




More information about the All-commits mailing list