[PATCH] D58321: [WIP] Support for relative vtables

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 22 22:14:48 PDT 2019


leonardchan updated this revision to Diff 196180.
leonardchan added a subscriber: mcgrathr.
leonardchan added a comment.
Herald added a subscriber: hiraditya.

Uploading my latest version of this patch and reporting some results. Will proceed with formatting and cleanup and ask for official reviews later.

___

After toying around with this for a bit, just enabling this flag on all c++ code in zircon shows about a 1% size increase in the final image (x64.zbi), but does its job of moving many vtables from .data.rel.ro to rodata. For each shared library that's included in the image, some of them decrease while most increase in size. These changes though are pretty small and rounded up align to page sizes (4kB), resulting in the overall 1% increase. This is mostly from extra instructions and extra PLT entries, through we have an idea for how we could reduce the PLT size.

We still get the benefits of moving vtables into rodata and having them shared between processes. Below is the section dump for one of our shared libraries (omitting the debug sections):

Without relative ABI

  Section Headers:
    [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
    [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
    [ 1] .note.gnu.build-id NOTE            0000000000000270 000270 000018 00   A  0   0  4
    [ 2] .dynsym           DYNSYM          0000000000000288 000288 000540 18   A  5   1  8
    [ 3] .gnu.hash         GNU_HASH        00000000000007c8 0007c8 000050 00   A  2   0  8
    [ 4] .dynamic          DYNAMIC         0000000000000818 000818 000170 10   A  5   0  8
    [ 5] .dynstr           STRTAB          0000000000000988 000988 000424 00   A  0   0  1
    [ 6] .rela.dyn         RELA            0000000000000db0 000db0 0000a8 18   A  2   0  8  # missing
    [ 7] .relr.dyn         00000013: <unknown> 0000000000000e58 000e58 000080 08   A  0   0  8
    [ 8] .rela.plt         RELA            0000000000000ed8 000ed8 000468 18   A  2  15  8
    [ 9] .rodata           PROGBITS        0000000000001340 001340 0025c8 00 AMS  0   0 16
    [10] .eh_frame_hdr     PROGBITS        0000000000003908 003908 000a1c 00   A  0   0  4
    [11] .eh_frame         PROGBITS        0000000000004328 004328 0032cc 00   A  0   0  8
    [12] .text             PROGBITS        0000000000008000 008000 014c1b 00  AX  0   0 16
    [13] .plt              PROGBITS        000000000001cc20 01cc20 000300 00  AX  0   0 16
    [14] .data.rel.ro      PROGBITS        000000000001d000 01d000 001948 00  WA  0   0 16
    [15] .got.plt          PROGBITS        000000000001e948 01e948 000190 00  WA  0   0  8

With relative ABI

  Section Headers:
    [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
    [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
    [ 1] .note.gnu.build-id NOTE            0000000000000270 000270 000018 00   A  0   0  4
    [ 2] .dynsym           DYNSYM          0000000000000288 000288 000540 18   A  5   1  8
    [ 3] .gnu.hash         GNU_HASH        00000000000007c8 0007c8 000050 00   A  2   0  8
    [ 4] .dynamic          DYNAMIC         0000000000000818 000818 000140 10   A  5   0  8
    [ 5] .dynstr           STRTAB          0000000000000958 000958 000424 00   A  0   0  1
    [ 6] .relr.dyn         00000013: <unknown> 0000000000000d80 000d80 000068 08   A  0   0  8
    [ 7] .rela.plt         RELA            0000000000000de8 000de8 000480 18   A  2  14  8
    [ 8] .rodata           PROGBITS        0000000000001270 001270 002990 00 AMS  0   0 16
    [ 9] .eh_frame_hdr     PROGBITS        0000000000003c00 003c00 000a1c 00   A  0   0  4
    [10] .eh_frame         PROGBITS        0000000000004620 004620 0032cc 00   A  0   0  8
    [11] .text             PROGBITS        0000000000008000 008000 014ffb 00  AX  0   0 16
    [12] .plt              PROGBITS        000000000001d000 01d000 000310 00  AX  0   0 16
    [13] .data.rel.ro      PROGBITS        000000000001e000 01e000 0012d0 00  WA  0   0 16
    [14] .got.plt          PROGBITS        000000000001f2d0 01f2d0 000198 00  WA  0   0  8
    [15] .data             PROGBITS        0000000000020000 020000 000038 00  WA  0   0 16
    [16] .bss              NOBITS          0000000000020038 020038 000100 00  WA  0   0  8

We were also able to build libc++ with relative ABI and got ~2% decrease in size for the final shared library.

Other stuff in this patch:

- Remove any LTO related code
- Ensure `needsRelocation()` catches the relative offset function pointers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58321/new/

https://reviews.llvm.org/D58321

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/debug-info-virtual-fn-relative.cpp
  clang/test/CodeGenCXX/vtable-relative-abi.cpp
  llvm/lib/IR/Constants.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58321.196180.patch
Type: text/x-patch
Size: 40179 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190423/844939d3/attachment.bin>


More information about the llvm-commits mailing list