llvm-project/lld/MachO
Nico Weber a38ebed258 [lld/mac] Implement support for .weak_def_can_be_hidden
I first had a more invasive patch for this (D101069), but while trying
to get that polished for review I realized that lld's current symbol
merging semantics mean that only a very small code change is needed.
So this goes with the smaller patch for now.

This has no effect on projects that build with -fvisibility=hidden
(e.g.  chromium), since these see .private_extern symbols instead.

It does have an effect on projects that build with -fvisibility-inlines-hidden
(e.g. llvm) in -O2 builds, where LLVM's GlobalOpt pass will promote most inline
functions from .weak_definition to .weak_def_can_be_hidden.

Before this patch:

    % ls -l out/gn/bin/clang out/gn/lib/libclang.dylib
    -rwxr-xr-x  1 thakis  staff  113059936 Apr 22 11:51 out/gn/bin/clang
    -rwxr-xr-x  1 thakis  staff   86370064 Apr 22 11:51 out/gn/lib/libclang.dylib
    % out/gn/bin/llvm-objdump --macho --weak-bind out/gn/bin/clang | wc -l
        8291
    % out/gn/bin/llvm-objdump --macho --weak-bind out/gn/lib/libclang.dylib | wc -l
        5698

With this patch:

    % ls -l out/gn/bin/clang out/gn/lib/libclang.dylib
    -rwxr-xr-x  1 thakis  staff  111721096 Apr 22 11:55 out/gn/bin/clang
    -rwxr-xr-x  1 thakis  staff   85291208 Apr 22 11:55 out/gn/lib/libclang.dylib
    thakis@MBP llvm-project % out/gn/bin/llvm-objdump --macho --weak-bind out/gn/bin/clang | wc -l
         725
    thakis@MBP llvm-project % out/gn/bin/llvm-objdump --macho --weak-bind out/gn/lib/libclang.dylib | wc -l
         542

Linking clang becomes a tiny bit faster with this patch:

    x 100    0.67263818    0.77847815    0.69430709    0.69877208   0.017715892
    + 100    0.67209601    0.73323393    0.68600798    0.68917346   0.012824377
    Difference at 95.0% confidence
            -0.00959861 +/- 0.00428661
            -1.37364% +/- 0.613449%
            (Student's t, pooled s = 0.0154648)

This only happens if lld with the patch and lld without the patch are both
linked with an lld with the patch or both linked with an lld without the patch
(...or with ld64). I accidentally linked the lld with the patch with an lld
without the patch and the other way round at first. In that setup, no
difference is found. That makese sense, since having fewer weak imports will
make the linked output a bit faster too. So not only does this make linking
binaries such as clang a bit faster (since fewer exports need to be written to
the export trie by lld), the linked output binary binary is also a bit faster
(since dyld needs to process fewer dynamic imports).

This also happens to fix the one `check-clang` failure when using lld as host
linker, but mostly for silly reasons: See crbug.com/1183336, mostly comment 26.
The real bug here is that c-index-test links all of LLVM both statically and
dynamically, which is an ODR violation. Things just happen to work with this
patch.

So after this patch, check-clang, check-lld, check-llvm all pass with lld as
host linker :)

Differential Revision: https://reviews.llvm.org/D101080
2021-04-22 22:51:34 -04:00
..
Arch [lld-macho] Support subtractor relocations that reference sections 2021-04-20 16:58:57 -04:00
CMakeLists.txt [lld-macho] Add support for arm64_32 2021-04-15 21:16:33 -04:00
Config.h [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
Driver.cpp [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
Driver.h [lld-macho] clang-format cleanup 2021-04-06 14:26:13 -04:00
DriverUtils.cpp [TextAPI] move source code files out of subdirectory, NFC 2021-04-05 10:24:42 -07:00
Dwarf.cpp [lld-macho][NFC] add const to pointer/reference induction variables of range-based for loops 2021-03-10 12:07:31 -08:00
Dwarf.h [lld-macho] Emit STABS symbols for debugging, and drop debug sections 2020-12-01 15:05:20 -08:00
ExportTrie.cpp [lld-macho][NFC] add const to pointer/reference induction variables of range-based for loops 2021-03-10 12:07:31 -08:00
ExportTrie.h [lld-macho] Export trie addresses should be relative to the image base 2020-09-20 20:43:15 -07:00
InputFiles.cpp [lld/mac] Implement support for .weak_def_can_be_hidden 2021-04-22 22:51:34 -04:00
InputFiles.h [lld][MachO] Refactor findCommand 2021-04-21 08:38:17 -07:00
InputSection.cpp [lld-macho] Support subtractor relocations that reference sections 2021-04-20 16:58:57 -04:00
InputSection.h [lld-macho] Initial groundwork for -bitcode_bundle 2021-04-16 16:47:14 -04:00
LTO.cpp [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
LTO.h [lld-macho] Add very basic support for LTO 2020-11-10 12:19:28 -08:00
MachOStructs.h [lld-macho] Add support for arm64_32 2021-04-15 21:16:33 -04:00
MapFile.cpp [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
MapFile.h [lld-macho] implement options -map 2021-03-18 10:39:19 -04:00
MergedOutputSection.cpp [lld-macho][NFC] Drop unnecessary braces around simple if/for bodies 2021-03-16 22:39:39 -07:00
MergedOutputSection.h [lld-macho] Refactor segment/section creation, sorting, and merging 2020-06-21 17:13:59 -07:00
ObjC.cpp [lld][MachO] Refactor findCommand 2021-04-21 08:38:17 -07:00
ObjC.h [lld-macho] Implement -ObjC 2020-08-26 19:20:55 -07:00
Options.td [lld-macho] Support LC_ENCRYPTION_INFO 2021-04-21 13:39:56 -04:00
OutputSection.cpp [lld-macho] Refactor segment/section creation, sorting, and merging 2020-06-21 17:13:59 -07:00
OutputSection.h [lld-macho] Initial groundwork for -bitcode_bundle 2021-04-16 16:47:14 -04:00
OutputSegment.cpp [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
OutputSegment.h [lld-macho] Ensure segments are laid out contiguously 2021-04-20 16:58:57 -04:00
Relocations.cpp [lld-macho][nfc] Remove DYSYM8 reloc attribute 2021-04-09 19:48:08 -04:00
Relocations.h [lld-macho] Add 32-bit compact unwind support 2021-04-15 21:16:33 -04:00
SymbolTable.cpp [lld-macho] LTO: Unset VisibleToRegularObj where possible 2021-04-15 21:16:33 -04:00
SymbolTable.h [lld-macho] LTO: Unset VisibleToRegularObj where possible 2021-04-15 21:16:33 -04:00
Symbols.cpp [lld-macho] clang-format cleanup 2021-04-06 14:26:13 -04:00
Symbols.h [lld-macho] LTO: Unset VisibleToRegularObj where possible 2021-04-15 21:16:33 -04:00
SyntheticSections.cpp [lld-macho][nfc] Clean up some constructor declarations 2021-04-22 18:25:44 -04:00
SyntheticSections.h [lld-macho] Initial groundwork for -bitcode_bundle 2021-04-16 16:47:14 -04:00
Target.cpp [lld-macho][nfc] Create Relocations.{h,cpp} for relocation-specific code 2021-03-11 13:28:09 -05:00
Target.h [lld-macho] Support LC_ENCRYPTION_INFO 2021-04-21 13:39:56 -04:00
UnwindInfoSection.cpp [lld/mac] make a few "named parameter comments" more consistent 2021-04-22 10:48:03 -04:00
UnwindInfoSection.h [lld-macho] Add 32-bit compact unwind support 2021-04-15 21:16:33 -04:00
Writer.cpp [lld-macho][nfc] Clean up some constructor declarations 2021-04-22 18:25:44 -04:00
Writer.h [lld-macho][nfc] Refactor in preparation for 32-bit support 2021-04-02 18:46:39 -04:00