[PATCH] D72959: Relative VTables ABI on Fuchsia

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 17 14:15:10 PST 2020


leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, jakehehrlich, pcc, rsmith, rjmccall.
leonardchan added a project: clang.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya, kristof.beyls, mehdi_amini.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.

This contains the updated patch for enabling Peter Collingbourne's relative vtable ABI (described in https://bugs.llvm.org/show_bug.cgi?id=26723) on Fuchsia. The goal is to reduce memory usage by making vtables readonly.

Key differences:

- LTO is not required
- No white listing of classes. Fuchsia does not guarantee C++ ABI stability, so anything running on Fuchsia should either by compiled with this ABI or not depend on the C++ ABI at all.
- Instead of taking the offset between the vtable and virtual function directly, we emit a DSO-local stub that just contains a tail call to the original virtual function, and take the offset between that and the vtable. We do this because there are some cases where the original function that would've been inserted into the vtable is not local or hidden and may require some kind of dynamic relocation which prevents the vtable from being readonly. On x86_64, taking the offset between the function and the vtable gets lowered to the offset between the PLT entry for the function and the vtable which gives us a PLT32 reloc. On Aarch64, right now only CALL26 and JUMP26 instructions generate PLT relocations, so we manifest them with stubs that are just jumps to the original function.
- Although this ABI does not yet work with RTTI, we apply the same technique with the RTTI component in the vtable and emit a proxy that results in a GOTPCREL reloc.

This is only the first patch which lays down the groundwork for the Fuchsia ABI. We would like to commit this, but will keep it disabled for now (hidden behind the flag) until we get RTTI fully working.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72959

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CGCXXABI.cpp
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/Fuchsia/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/Fuchsia/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/Fuchsia/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/Fuchsia/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/Fuchsia/cross-tu-header.h
  clang/test/CodeGenCXX/Fuchsia/diamond-inheritance.cpp
  clang/test/CodeGenCXX/Fuchsia/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/Fuchsia/dynamic-cast.cpp
  clang/test/CodeGenCXX/Fuchsia/inheritted-virtual-function.cpp
  clang/test/CodeGenCXX/Fuchsia/inline-virtual-function.cpp
  clang/test/CodeGenCXX/Fuchsia/inlined-key-function.cpp
  clang/test/CodeGenCXX/Fuchsia/member-function-pointer.cpp
  clang/test/CodeGenCXX/Fuchsia/multiple-inheritance.cpp
  clang/test/CodeGenCXX/Fuchsia/override-pure-virtual-method.cpp
  clang/test/CodeGenCXX/Fuchsia/overriden-virtual-function.cpp
  clang/test/CodeGenCXX/Fuchsia/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/Fuchsia/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/Fuchsia/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/Fuchsia/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/Fuchsia/stub-linkages.cpp
  clang/test/CodeGenCXX/Fuchsia/thunk-mangling.cpp
  clang/test/CodeGenCXX/Fuchsia/type-info.cpp
  clang/test/CodeGenCXX/Fuchsia/virtual-function-call.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  llvm/lib/IR/Constants.cpp
  llvm/test/CodeGen/X86/relptr-rodata.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72959.238885.patch
Type: text/x-patch
Size: 107815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200117/f0e3c4da/attachment-0001.bin>


More information about the cfe-commits mailing list