summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
AgeCommit message (Collapse)Author
2025-08-28ThinLTOBitcodeWriter: Split modules with __cfi_check and no type metadata.Peter Collingbourne
Eli Friedman found a case that was not handled correctly by #154833 where we failed to split the module if it contained a __cfi_check function but no type metadata. Handle this case correctly by checking for __cfi_check when deciding whether to split. Reviewers: teresajohnson, efriedma-quic Reviewed By: efriedma-quic Pull Request: https://github.com/llvm/llvm-project/pull/155930
2025-08-21ThinLTOBitcodeWriter: Emit __cfi_check to full LTO part of bitcode file.Peter Collingbourne
The CrossDSOCFI pass runs on the full LTO module and fills in the body of __cfi_check. This function must have the correct attributes in order to be compatible with the rest of the program. For example, when building with -mbranch-protection=standard, the function must have the branch-target-enforcement attribute, which is normally added by Clang. When __cfi_check is missing, CrossDSOCFI will give it the default set of attributes, which are likely incorrect. Therefore, emit __cfi_check to the full LTO part, where CrossDSOCFI will see it. Reviewers: efriedma-quic, vitalybuka, fmayer Reviewed By: efriedma-quic Pull Request: https://github.com/llvm/llvm-project/pull/154833
2025-07-30LTO: Redesign the CFI !aliases metadata.Peter Collingbourne
With the current aliases metadata we lose information about which groups of aliases survive symbol resolution. This causes various problems such as #150075 where symbol resolution breaks the link between alias groups. In this redesign of the aliases metadata, we stop representing the individual aliases in !aliases. Instead, the individual aliases are represented in !cfi.functions in the same way as functions, and the alias groups (i.e. groups of symbols with the same address) are stored in !aliases. At symbol resolution time, we filter out all non-prevailing members of !aliases; the resulting set is used by LowerTypeTests to recreate the aliases. With this change it is now possible for a jump table entry to refer to an alias in one of the ThinLTO object files (e.g. if a function is non-prevailing but its alias is prevailing), so instead of deleting them, rename them with the ".cfi" suffix. Fixes #150070. Fixes #150075. Reviewers: teresajohnson, vitalybuka Reviewed By: vitalybuka Pull Request: https://github.com/llvm/llvm-project/pull/150690
2025-06-11[DebugInfo][RemoveDIs] Remove scoped-dbg-format-setter (#143450)Jeremy Morse
This was a utility for flipping between intrinsic and debug record mode -- we don't need it any more. The "IsNewDbgInfoFormat" should be true everywhere.
2025-04-14ThinLTO: Add flag to print uselistorder in bitcode writer pass (#133230)Matt Arsenault
This is needed in llvm-reduce to avoid perturbing the uselistorder in intermediate steps. Really llvm-reduce wants pure serialization with no dependency on the pass manager. There are other optimizations mixed in to the serialization here depending on metadata in the module, which is also bad. Part of #63621
2025-04-01[DebugInfo][RemoveDIs] Remove debug-intrinsic printing cmdline options (#131855)Jeremy Morse
During the transition from debug intrinsics to debug records, we used several different command line options to customise handling: the printing of debug records to bitcode and textual could be independent of how the debug-info was represented inside a module, whether the autoupgrader ran could be customised. This was all valuable during development, but now that totally removing debug intrinsics is coming up, this patch removes those options in favour of a single flag (experimental-debuginfo-iterators), which enables autoupgrade, in-memory debug records, and debug record printing to bitcode and textual IR. We need to do this ahead of removing the experimental-debuginfo-iterators flag, to reduce the amount of test-juggling that happens at that time. There are quite a number of weird test behaviours related to this -- some of which I simply delete in this commit. Things like print-non-instruction-debug-info.ll , the test suite now checks for debug records in all tests, and we don't want to check we can print as intrinsics. Or the update_test_checks tests -- these are duplicated with write-experimental-debuginfo=false to ensure file writing for intrinsics is correct, but that's something we're imminently going to delete. A short survey of curious test changes: * free-intrinsics.ll: we don't need to test that debug-info is a zero cost intrinsic, because we won't be using intrinsics in the future. * undef-dbg-val.ll: apparently we pinned this to non-RemoveDIs in-memory mode while we sorted something out; it works now either way. * salvage-cast-debug-info.ll: was testing intrinsics-in-memory get salvaged, isn't necessary now * localize-constexpr-debuginfo.ll: was producing "dead metadata" intrinsics for optimised-out variable values, dbg-records takes the (correct) representation of poison/undef as an operand. Looks like we didn't update this in the past to avoid spurious test differences. * Transforms/Scalarizer/dbginfo.ll: this test was explicitly testing that debug-info affected codegen, and we deferred updating the tests until now. This is just one of those silent gnochange issues that get fixed by RemoveDIs. Finally: I've added a bitcode test, dbg-intrinsics-autoupgrade.ll.bc, that checks we can autoupgrade debug intrinsics that are in bitcode into the new debug records.
2024-10-16[LLVM] Add `Intrinsic::getDeclarationIfExists` (#112428)Rahul Joshi
Add `Intrinsic::getDeclarationIfExists` to lookup an existing declaration of an intrinsic in a `Module`.
2024-04-22[RemoveDIs] Make verify-uselistorder preserve the input debug info format ↵Stephen Tozer
(#87789) Verify-uselistorder wants to take some input IR and verify that the uselist order is stable after roundtripping to bitcode and assembly. This is disrupted if the file is converted between the new and old debug info formats after parsing - while there's no functional difference, the change to the in-memory representation of the IR modifies the uselist. This patch changes verify-uselistorder to not convert input files between debug info formats by default, preventing changes from being made to the file being checked. In addition, this patch makes it so that when we _do_ print IR in the new debug info format to bitcode or assembly, we delete any lingering debug intrinsic declarations, ensuring that we don't write uselist entries for them.
2024-04-04[RemoveDIs][NFC] Use ScopedDbgInfoFormatSetter in more places (#87380)Stephen Tozer
The class `ScopedDbgInfoFormatSetter` was added as a convenient way to temporarily change the debug info format of a function or module, as part of IR printing; since this process is repeated in a number of other places, this patch uses the format-setter class in those places as well.
2024-03-19[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)Stephen Tozer
This is the major rename patch that prior patches have built towards. The DPValue class is being renamed to DbgVariableRecord, which reflects the updated terminology for the "final" implementation of the RemoveDI feature. This is a pure string substitution + clang-format patch. The only manual component of this patch was determining where to perform these string substitutions: `DPValue` and `DPV` are almost exclusively used for DbgRecords, *except* for: - llvm/lib/target, where 'DP' is used to mean double-precision, and so appears as part of .td files and in variable names. NB: There is a single existing use of `DPValue` here that refers to debug info, which I've manually updated. - llvm/tools/gold, where 'LDPV' is used as a prefix for symbol visibility enums. Outside of these places, I've applied several basic string substitutions, with the intent that they only affect DbgRecord-related identifiers; I've checked them as I went through to verify this, with reasonable confidence that there are no unintended changes that slipped through the cracks. The substitutions applied are all case-sensitive, and are applied in the order shown: ``` DPValue -> DbgVariableRecord DPVal -> DbgVarRec DPV -> DVR ``` Following the previous rename patches, it should be the case that there are no instances of any of these strings that are meant to refer to the general case of DbgRecords, or anything other than the DPValue class. The idea behind this patch is therefore that pure string substitution is correct in all cases as long as these assumptions hold.
2024-03-15Reapply [RemoveDIs] Read/write DbgRecords directly from/to bitcode (#83251)Orlando Cazalet-Hyams
Reaplying after revert in #85382 (861ebe6446296c96578807363aa292c69d827773). Fixed intermittent test failure by avoiding piping output in some RUN lines. If --write-experimental-debuginfo-iterators-to-bitcode is true (default false) and --expermental-debuginfo-iterators is also true then the new debug info format (non-instruction records) is written to bitcode directly. Added the following records: FUNC_CODE_DEBUG_RECORD_LABEL FUNC_CODE_DEBUG_RECORD_VALUE FUNC_CODE_DEBUG_RECORD_DECLARE FUNC_CODE_DEBUG_RECORD_ASSIGN FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE The last one has an abbrev in FUNCTION_BLOCK BLOCK_INFO. Incidentally, this uses the last value available without widening the code-length for FUNCTION_BLOCK from 4 to 5 bits. Records are formatted as follows: All DbgRecord start with: 1. DILocation FUNC_CODE_DEBUG_RECORD_LABEL 2. DILabel DPValues then share common fields: 2. DILocalVariable 3. DIExpression FUNC_CODE_DEBUG_RECORD_VALUE 4. Location Metadata FUNC_CODE_DEBUG_RECORD_DECLARE 4. Location Metadata FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE 4. Location Value (single) FUNC_CODE_DEBUG_RECORD_ASSIGN 4. Location Metadata 5. DIAssignID 6. DIExpression (address) 7. Location Metadata (address) Encoding the DILocation metadata reference directly appeared to yield smaller bitcode files than encoding the operands seperately (as is done with instruction DILocations). FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE is by far the most common DbgRecord record in optimized code (order of 5x-10x over other kinds). Unoptimized code should only contain FUNC_CODE_DEBUG_RECORD_DECLARE.
2024-03-15Revert "[RemoveDIs] Read/write DbgRecords directly from/to bitcode" (#85382)Orlando Cazalet-Hyams
Reverts llvm/llvm-project#83251 Buildbot: https://lab.llvm.org/buildbot/#/builders/139/builds/61485
2024-03-15[RemoveDIs] Read/write DbgRecords directly from/to bitcode (#83251)Orlando Cazalet-Hyams
If --write-experimental-debuginfo-iterators-to-bitcode is true (default false) and --expermental-debuginfo-iterators is also true then the new debug info format (non-instruction records) is written to bitcode directly. Added the following records: FUNC_CODE_DEBUG_RECORD_LABEL FUNC_CODE_DEBUG_RECORD_VALUE FUNC_CODE_DEBUG_RECORD_DECLARE FUNC_CODE_DEBUG_RECORD_ASSIGN FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE The last one has an abbrev in FUNCTION_BLOCK BLOCK_INFO. Incidentally, this uses the last value available without widening the code-length for FUNCTION_BLOCK from 4 to 5 bits. Records are formatted as follows: All DbgRecord start with: 1. DILocation FUNC_CODE_DEBUG_RECORD_LABEL 2. DILabel DPValues then share common fields: 2. DILocalVariable 3. DIExpression FUNC_CODE_DEBUG_RECORD_VALUE 4. Location Metadata FUNC_CODE_DEBUG_RECORD_DECLARE 4. Location Metadata FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE 4. Location Value (single) FUNC_CODE_DEBUG_RECORD_ASSIGN 4. Location Metadata 5. DIAssignID 6. DIExpression (address) 7. Location Metadata (address) Encoding the DILocation metadata reference directly appeared to yield smaller bitcode files than encoding the operands seperately (as is done with instruction DILocations). FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE is by far the most common DbgRecord record in optimized code (order of 5x-10x over other kinds). Unoptimized code should only contain FUNC_CODE_DEBUG_RECORD_DECLARE.
2024-02-13[DebugInfo][RemoveDIs] Convert back to intrinsic form for ThinLTOJeremy Morse
As explained on discourse [0] (comment 12), to get the non-intrinsic form of debug-info records enabled and testing, we're only using it inside of the pass manager in LLVM right now. Things like the textual IR writer and bitcode writing _passes_ are instrumented to convert back to intrinsic-form when writing a module out, but it turns out we missed the ThinLTO bitcode writing pass. That causes uh, all variable location debug-info to be dropped in ThinLTO mode (oops). This patch adds that conversion; it should be low risk as it's identical to what happens in all the other passes. However should this commit turn out to cause trouble, please instead revert d759618df76 or whichever is the most recent commit to set UseNewDbgInfoFormat to default to true. That'll revert LLVM back to the definitely-correct behaviour. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939
2023-11-06[Transforms] Use StringRef::starts_with/ends_with instead of ↵Simon Pilgrim
startswith/endswith. NFC. startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-11-06[IPO] Remove unnecessary bitcasts (NFC)Nikita Popov
2023-10-24[ThinLTOBitcodeWriter] Do not crash on a typed declaration (#69564)Igor Kudrin
This fixes a crash when `splitAndWriteThinLTOBitcode()` hits a declaration with type metadata. For example, such declarations can be generated by the `EliminateAvailableExternally` pass.
2023-07-05[LTO] Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=off builds after D123803Fangrui Song
2023-07-05[llvm] A Unified LTO Bitcode FrontendMatthew Voss
Here's a high level summary of the changes in this patch. For more information on rational, see the RFC. (https://discourse.llvm.org/t/rfc-a-unified-lto-bitcode-frontend/61774). - Add config parameter to LTO backend, specifying which LTO mode is desired when using unified LTO. - Add unified LTO flag to the summary index for efficiency. Unified LTO modules can be detected without parsing the module. - Make sure that the ModuleID is generated by incorporating more types of symbols. Differential Revision: https://reviews.llvm.org/D123803
2023-06-29Add a type_checked_load_relative to support relative function pointer tablesArnold Schwaighofer
This adds a type_checked_load_relative intrinsic whose semantics it is to load a relative function pointer. A relative function pointer is a pointer to a 32bit value that when added to its address yields the address of the function. Differential Revision: https://reviews.llvm.org/D143204
2023-04-25[ThinLTOBitcodeWriter] Properly report when module is changedArthur Eubanks
Happens with split LTO units. Detected with upcoming changes.
2023-04-17Remove several no longer needed includes. NFCIBjorn Pettersson
Mostly removing includes of InitializePasses.h and Pass.h in passes that no longer has support for the legacy PM.
2023-03-21Fix -fsplit-lto-unit with ifuncsDaniel Kiss
ifuncs can't take part of the whole-program devirtualization so no need them to be copied to the merged module. The corresponding resolver function also kept out which caused the crash. Fixes #60962 #57870 Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D144982
2022-09-14[AA] Tracking per-location ModRef info in FunctionModRefBehavior (NFCI)Nikita Popov
Currently, FunctionModRefBehavior tracks whether the function reads or writes memory (ModRefInfo) and which locations it can access (argmem, inaccessiblemem and other). This patch changes it to track ModRef information per-location instead. To give two examples of why this is useful: * D117095 highlights a weakness of ModRef modelling in the presence of operand bundles. For a memcpy call with deopt operand bundle, we want to say that it can read any memory, but only write argument memory. This would allow them to be treated like any other calls. However, we currently can't express this and have to say that it can read or write any memory. * D127383 would ideally be modelled as a separate threadid location, where threadid Refs outside pre-split coroutines can be ignored (like other accesses to constant memory). The current representation does not allow modelling this precisely. The patch as implemented is intended to be NFC, but there are some obvious opportunities for improvements and simplification. To fully capitalize on this we would also want to change the way we represent memory attributes on functions, but that's a larger change, and I think it makes sense to separate out the FunctionModRefBehavior refactoring. Differential Revision: https://reviews.llvm.org/D130896
2022-08-27[Transforms] Qualify auto in range-based for loops (NFC)Kazu Hirata
Identified with readability-qualified-auto.
2022-08-15[LegacyPM] Remove ThinLTO bitcode writer legacy passArthur Eubanks
Using the legacy PM for the optimization pipeline is deprecated and in the process of being removed. This is a small step in that direction. For an example of migrating to the new PM: https://github.com/llvm/llvm-project/commit/853b57fe80bdb9d6b19697e6f2abc734834e9f6d
2022-07-26[WPD] Use new llvm.public.type.test intrinsic for potentially publicly ↵Arthur Eubanks
visible classes Turning on opaque pointers has uncovered an issue with WPD where we currently pattern match away `assume(type.test)` in WPD so that a later LTT doesn't resolve the type test to undef and introduce an `assume(false)`. The pattern matching can fail in cases where we transform two `assume(type.test)`s into `assume(phi(type.test.1, type.test.2))`. Currently we create `assume(type.test)` for all virtual calls that might be devirtualized. This is to support `-Wl,--lto-whole-program-visibility`. To prevent this, all virtual calls that may not be in the same LTO module instead use a new `llvm.public.type.test` intrinsic in place of the `llvm.type.test`. Then when we know if `-Wl,--lto-whole-program-visibility` is passed or not, we can either replace all `llvm.public.type.test` with `llvm.type.test`, or replace all `llvm.public.type.test` with `true`. This prevents WPD from trying to pattern match away `assume(type.test)` for public virtual calls when failing the pattern matching will result in miscompiles. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D128955
2022-06-18[IPO] Use default member initialization (NFC)Kazu Hirata
Identified with modernize-use-default-member-init.
2022-03-22Cleanup includes: Transforms/IPOserge-sans-paille
Preprocessor output diff: -238205 lines Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D122183
2022-03-15[FunctionAttrs] Replace MemoryAccessKind with FMRB.Florian Hahn
Update FunctionAttrs to use FunctionModRefBehavior instead MemoryAccessKind. This allows for adding support for inferring argmemonly and others, see D121415. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D121460
2022-01-31[BitcodeWriter] Fix cases of some functionsFangrui Song
`WriteIndexToFile` is used by external projects so I do not touch it.
2021-12-10[ThinLTO][MC] Use conditional assignments for promotion aliasesSami Tolvanen
Inline assembly refererences to static functions with ThinLTO+CFI were fixed in D104058 by creating aliases for promoted functions. Creating the aliases unconditionally resulted in an unexpected size increase in a Chrome helper binary: https://bugs.chromium.org/p/chromium/issues/detail?id=1261715 This is caused by the compiler being unable to drop unused code now referenced by the alias in module-level inline assembly. This change adds a .set_conditional assembly extension, which emits an assignment only if the target symbol is also emitted, avoiding phantom references to functions that could have otherwise been dropped. This is an alternative to the solution proposed in D112761. Reviewed By: pcc, nickdesaulniers, MaskRay Differential Revision: https://reviews.llvm.org/D113613
2021-10-06[IR][NFC] Rename getBaseObject to getAliaseeObjectItay Bookstein
To better reflect the meaning of the now-disambiguated {GlobalValue, GlobalAlias}::getBaseObject after breaking off GlobalIFunc::getResolverFunction (D109792), the function is renamed to getAliaseeObject.
2021-09-15[Transforms] Use make_early_inc_range (NFC)Kazu Hirata
2021-09-14[IPO] Use make_early_inc_range (NFC)Kazu Hirata
2021-08-13[NFC] Rename AttributeList::getParam/Ret/FnAttributes() -> get*Attributes()Arthur Eubanks
This is more consistent with similar methods.
2021-08-03ThinLTO: Fix inline assembly references to static functions with CFISami Tolvanen
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. Relands 700d07f8ce6f2879610fd6b6968b05c6f17bb915 with -msvc targets fixed. Link: https://github.com/ClangBuiltLinux/linux/issues/1354 Reviewed By: nickdesaulniers, pcc Differential Revision: https://reviews.llvm.org/D104058
2021-07-20Revert "ThinLTO: Fix inline assembly references to static functions with CFI"Sami Tolvanen
This reverts commit 700d07f8ce6f2879610fd6b6968b05c6f17bb915. Reverting due to a ThinLTO+CFI breakage on -msvc targets.
2021-07-20[ThinTLOBitcodeWriter] Fix unused variable warning (NFC)Nikita Popov
2021-07-20ThinLTO: Fix inline assembly references to static functions with CFISami Tolvanen
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. This version uses module inline assembly to avoid issues with LowerTypeTestsModule. Relands commmit 8e3b5cb39eef462943ed7556469604ce25c07a1d with arch specific tests fixed. Link: https://github.com/ClangBuiltLinux/linux/issues/1354 Reviewed By: nickdesaulniers, pcc Differential Revision: https://reviews.llvm.org/D104058
2021-07-16Revert "ThinLTO: Fix inline assembly references to static functions with CFI"Sami Tolvanen
This reverts commit 8e3b5cb39eef462943ed7556469604ce25c07a1d. Reverting to investigate test failures.
2021-07-16ThinLTO: Fix inline assembly references to static functions with CFISami Tolvanen
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. This version uses module inline assembly to avoid issues with LowerTypeTestsModule. Link: https://github.com/ClangBuiltLinux/linux/issues/1354 Reviewed By: nickdesaulniers, pcc Differential Revision: https://reviews.llvm.org/D104058
2021-06-23Revert "ThinLTO: Fix inline assembly references to static functions with CFI"Zequan Wu
This casues compiler crash: Assertion `materialized_use_empty() && "Uses remain when a value is destroyed!"' This reverts commit e3d24b45b8f808ec66213e134c4ceda5202fbe31.
2021-06-23ThinLTO: Fix inline assembly references to static functions with CFISami Tolvanen
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. This relands commit 4474958d3a97dede2caa0920f7c4a4dc7aac57d3 with a fix to a use-of-uninitialized-value error that tripped MemorySanitizer. Link: https://github.com/ClangBuiltLinux/linux/issues/1354 Reviewed By: nickdesaulniers, pcc Differential Revision: https://reviews.llvm.org/D104058
2021-06-22Revert "ThinLTO: Fix inline assembly references to static functions with CFI"Sami Tolvanen
This reverts commit 4474958d3a97dede2caa0920f7c4a4dc7aac57d3. Breaks check-llvm on Mac.
2021-06-22ThinLTO: Fix inline assembly references to static functions with CFISami Tolvanen
Create an internal alias with the original name for static functions that are renamed in promoteInternals to avoid breaking inline assembly references to them. Link: https://github.com/ClangBuiltLinux/linux/issues/1354 Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D104058
2021-04-19[ThinLTO] Copy UnnamedAddr when spliting module.Zequan Wu
The unnamedaddr property of a function is lost when using `-fwhole-program-vtables` and thinlto which causes size increase under linker's safe icf mode. The size increase of chrome on Linux when switching from all icf to safe icf drops from 5 MB to 3 MB after this change, and from 6 MB to 4 MB on Windows. There is a repro: ``` # a.h struct A { virtual int f(); virtual int g(); }; # a.cpp #include "a.h" int A::f() { return 10; } int A::g() { return 10; } # main.cpp #include "a.h" int g(A* a) { return a->f(); } int main(int argv, char** args) { A a; return g(&a); } $ clang++ -O2 -ffunction-sections -flto=thin -fwhole-program-vtables -fsplit-lto-unit -c main.cpp -o main.o && clang++ -Wl,--icf=safe -fuse-ld=lld -flto=thin main.o -o a.out && llvm-readobj -t a.out | grep -A 1 -e _ZN1A1fEv -e _ZN1A1gEv Name: _ZN1A1fEv (480) Value: 0x201830 -- Name: _ZN1A1gEv (490) Value: 0x201840 ``` Differential Revision: https://reviews.llvm.org/D100498
2021-02-23[ThinLTO] Make cloneUsedGlobalVariables deterministicFangrui Song
Iterating on `SmallPtrSet<GlobalValue *, 8>` with more than 8 elements is not deterministic. Use a SmallVector instead because `Used` is guaranteed to contain unique elements. While here, decrease inline element counts from 8 to 4. The number of `llvm.used`/`llvm.compiler.used` elements is usually 0 or 1. For full LTO/hybrid LTO, the number may be large, so we need to be careful. According to tejohnson's analysis https://reviews.llvm.org/D97128#2582399 , 4 is good for a large project with WholeProgramDevirt, when available_externally vtables are placed in the llvm.compiler.used set. Differential Revision: https://reviews.llvm.org/D97128
2021-02-20[LTO] Fix cloning of llvm*.used when splitting moduleTeresa Johnson
Refines the fix in 3c4c205060c9398da705eb71b63ddd8a04999de9 to only put globals whose defs were cloned into the split regular LTO module on the cloned llvm*.used globals. This avoids an issue where one of the attached values was a local that was promoted in the original module after the module was cloned. We only need to have the values defined in the new module on those globals. Fixes PR49251. Differential Revision: https://reviews.llvm.org/D97013
2021-02-17[WPD][lld] Test handling of vtable definition from shared librariesTeresa Johnson
Adds a lld test for a case that the handling added for dynamically exported symbols in 1487747e990ce9f8851f3d92c3006a74134d7518 already fixes. Because isExportDynamic returns true when the symbol is SharedKind with default visibility, it will treat as dynamically exported and block devirtualization when the definition of a vtable comes from a shared library. This is desireable as it is dangerous to devirtualize in that case, since there could be hidden overrides in the shared library. Typically that happens when the shared library header contains available externally definitions, which applications can override. An example is std::error_category, which is overridden in LLVM and causing failures after a self build with WPD enabled, because libstdc++ contains hidden overrides of the virtual base class methods. The regular LTO case in the new test already worked, but there are 2 fixes in this patch needed for the index-only case and the hybrid LTO case. For the index-only case, WPD should not simply ignore available externally vtables. A follow on fix will be made to clang to emit type metadata for those vtables, which the new test is modeling. For the hybrid case, we need to ensure when the module is split that any llvm.*used globals are cloned to the regular LTO split module so available externally vtable definitions are not prematurely deleted. Another follow on fix will add the equivalent gold test, which requires a small fix to the plugin to treat symbols in dynamic libraries the same way lld already is. Differential Revision: https://reviews.llvm.org/D96721