aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Linker/LinkModules.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov1-1/+1
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2023-10-29[Linker] Do not keep a private member of a non-prevailing comdat group (#69143)Igor Kudrin1-0/+21
`IRMover` links in referenced private global values unconditionally, see `IRLinker::shouldLink()`. If they are part of a non-prevailing comdat, this leads to duplication of the values. Full and Thin LTO avoid duplication by changing the linkage of members of non-prevailing comdat groups to `available_externally`, which was implemented in https://reviews.llvm.org/D34803 and https://reviews.llvm.org/D135427. This patch does the same for `Linker`, but limits the effect only to private members without aliases to minimize interference. Motivation example: ``` > cat foo.h inline int foo(int a) { return a + 1; } > cat bar.cpp #include "foo.h" int bar(int a) { return foo(a + 1); } > cat main.cpp #include "foo.h" int bar(int a); int main(int argc, const char* argv[]) { return bar(argc) + foo(argc); } > clang++ -c -flto -fprofile-instr-generate main.cpp -o main.o > clang++ -c -flto -fprofile-instr-generate bar.cpp -o bar.o > clang++ -fuse-ld=lld -fprofile-instr-generate main.o bar.o -o test1 > ./test1 > llvm-profdata merge --text default.profraw -o - _Z3fooi # Counter Values: 2 > llvm-link main.o bar.o -o combined.o > clang++ -fuse-ld=lld -fprofile-instr-generate combined.o -o test2 > ./test2 > llvm-profdata merge --text default.profraw -o - _Z3fooi # Counter Values: 4 ```
2022-12-13[rereland][Alignment][NFC] Remove access to deprecated ↵Guillaume Chatelet1-2/+6
GlobalObject::getAlignment from llvm Differential Revision: https://reviews.llvm.org/D139836
2022-12-12Revert "[reland][Alignment][NFC] Remove access to deprecated ↵Guillaume Chatelet1-6/+2
GlobalObject::getAlignment from llvm" This reverts commit 3bbfaee23d41c099547c652f87b252ab6e1f6c46.
2022-12-12[reland][Alignment][NFC] Remove access to deprecated ↵Guillaume Chatelet1-2/+6
GlobalObject::getAlignment from llvm Differential Revision: https://reviews.llvm.org/D139836
2022-12-12Revert D139836 "[Alignment][NFC] Remove deprecated GlobalObject::getAlignment"Guillaume Chatelet1-6/+2
This breaks lldb. This reverts commit f3f15ca27fbb433ad5a65b1a1e0a071d2e9af505.
2022-12-12[Alignment][NFC] Remove deprecated GlobalObject::getAlignmentGuillaume Chatelet1-2/+6
Differential Revision: https://reviews.llvm.org/D139836
2022-03-22Cleanup includes: Linkerserge-sans-paille1-1/+0
Preprocessor output diff: -7300 lines Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D122182
2022-03-14[IRLinker] make IRLinker::AddLazyFor optional (llvm::unique_function). NFCNick Desaulniers1-5/+7
2 of the 3 callsite of IRMover::move() pass empty lambda functions. Just make this parameter llvm::unique_function. Came about via discussion in D120781. Probably worth making this change regardless of the resolution of D120781. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D121630
2021-11-05[llvm] Use make_early_inc_range (NFC)Kazu Hirata1-9/+3
2021-10-06[IR][NFC] Rename getBaseObject to getAliaseeObjectItay Bookstein1-1/+1
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-08-31[Linker] Handle comdat nodeduplicateFangrui Song1-25/+35
For a variable in a comdat nodeduplicate, its initializer may be significant. E.g. its content may be implicitly referenced by another comdat member (or required to parallel to another comdat member by the runtime when explicit section is used). We can clone it into an unnamed private linkage variable to preserve its content. This partially fixes PR51394 (Sony's proprietary linker using LTO): no error will be reported. This is partial because we do not guarantee the global variable order if the runtime has parallel section requirement. --- There is a similar issue for regular LTO, but unrelated to PR51394: with lib/LTO (using either ld.lld or LLVMgold.so), linking two modules with a weak function of the same name, can leave one weak profc and two private profd, due to lib/LTO's current deficiency that it mixes the two concepts together: comdat selection and symbol resolution. If the issue is considered important, we should suppress private profd for the weak+ regular LTO case. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D108879
2021-08-31[Linker] Support weak symbols in nodeduplicate COMDAT groupPetr Hosek1-3/+19
When a nodeduplicate COMDAT group contains a weak symbol, choose a non-weak symbol (or one of the weak ones) rather than reporting an error. This should address issue PR51394. With the current IR representation, a generic comdat nodeduplicate semantics is not representable for LTO. In the linker, sections and symbols are separate concepts. A dropped weak symbol does not force the defining input section to be dropped as well (though it can be collected by GC). In the IR, when a weak linkage symbol is dropped, its associate section content is dropped as well. For InstrProfiling, which is where ran into this issue in PR51394, the deduplication semantic is a sufficient workaround. Differential Revision: https://reviews.llvm.org/D108689
2021-08-28[Linker] Replace comdat based bool LinkFromSrc with enum class LinkFrom and ↵Fangrui Song1-21/+21
improve nodeduplicate tests. NFC This is different from symbol resolution based LinkFromSrc. Rename to be clearer. In the future we may support a new enum member 'Both' for nodeduplicate. This is feasible (by renaming to a private linkage GlobalValue), but we need to be careful not to break InstrProfiling.cpp's expectation of parallel profd/profc. The challenge is that current LTO symbol resolution only allows to mark one profc as prevailing: the other profc in another comdat nodeduplicate may be discarded while its associated profd isn't.
2021-08-14[Linker] Import GlobalIFunc when importing symbols from another moduleItay Bookstein1-0/+4
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D107988
2021-07-20[IR] Rename `comdat noduplicates` to `comdat nodeduplicate`Fangrui Song1-2/+2
In the textual format, `noduplicates` means no COMDAT/section group deduplication is performed. Therefore, if both sets of sections are retained, and they happen to define strong external symbols with the same names, there will be a duplicate definition linker error. In PE/COFF, the selection kind lowers to `IMAGE_COMDAT_SELECT_NODUPLICATES`. The name describes the corollary instead of the immediate semantics. The name can cause confusion to other binary formats (ELF, wasm) which have implemented/ want to implement the "no deduplication" selection kind. Rename it to be clearer. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D106319
2021-07-09[NFC][OpaquePtr] Use GlobalValue::getValueType() moreArthur Eubanks1-2/+1
Instead of getType()->getElementType().
2021-01-23[llvm-link] Fix for an assertion when linking global with appending linkageSergey Dmitriev1-1/+1
This patch fixes llvm-link assertion when linking external variable declaration with a definition with appending linkage. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D95126
2019-10-15[Alignment][NFC] Remove dependency on GlobalObject::setAlignment(unsigned)Guillaume Chatelet1-1/+2
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: arsenm, mehdi_amini, jvesely, nhaehnle, hiraditya, steven_wu, dexonsmith, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68944 llvm-svn: 374880
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2017-08-09[Linker] PR33527 - Linker::LinkOnlyNeeded should import AppendingLinkage globalsBenoit Belley1-2/+12
Linker::LinkOnlyNeeded should always import globals with AppendingLinkage. This resolves PR33527. Differential Revision: https://reviews.llvm.org/D34448 llvm-svn: 310522
2017-03-13[Linker] Provide callback for internalizationJonas Devlieghere1-19/+27
Differential Revision: https://reviews.llvm.org/D30738 llvm-svn: 297649
2017-02-03IRMover: Merge flags LinkModuleInlineAsm and IsPerformingImport.Peter Collingbourne1-1/+0
Currently these flags are always the inverse of each other, so there is no need to keep them separate. Differential Revision: https://reviews.llvm.org/D29471 llvm-svn: 294016
2017-02-03ModuleLinker: Remove importing support. NFCI.Peter Collingbourne1-58/+12
Differential Revision: https://reviews.llvm.org/D29470 llvm-svn: 294015
2017-02-03FunctionImport: Use IRMover directly.Peter Collingbourne1-2/+1
The importer was previously using ModuleLinker in a sort of "IRMover mode". Use IRMover directly instead in order to remove a level of indirection. I will remove all importing support from ModuleLinker in a separate change. Differential Revision: https://reviews.llvm.org/D29468 llvm-svn: 294014
2017-02-02Linker: Move special casing for available_externally in IRMover to clients. ↵Peter Collingbourne1-1/+2
NFCI. The goal is to simplify the semantic model for clients of IRMover. Differential Revision: https://reviews.llvm.org/D29435 llvm-svn: 293864
2016-12-12[ThinLTO] Import only necessary DICompileUnit fieldsTeresa Johnson1-1/+2
Summary: As discussed on mailing list, for ThinLTO importing we don't need to import all the fields of the DICompileUnit. Don't import enums, macros, retained types lists. Also only import local scoped imported entities. Since we don't currently import any global variables, we also don't need to import the list of global variables (added an assert to verify none are being imported). This is being done by pre-populating the value map entries to map the unneeded metadata to nullptr. For the imported entities, we can simply replace the source module's list with a new list containing only those needed imported entities. This is done in the IRLinker constructor so that value mapping automatically does the desired mapping. Reviewers: mehdi_amini, dexonsmith, dblaikie, aprantl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27635 llvm-svn: 289441
2016-10-12[ThinLTO] Don't link module level assembly when importingTeresa Johnson1-1/+2
Module inline asm was always being linked/concatenated when running the IRLinker. This is correct for full LTO but not when we are importing for ThinLTO, as it can result in multiply defined symbols when the module asm defines a global symbol. In order to test with llvm-lto2, I had to work around PR30396, where a symbol that is defined in module assembly but defined in the LLVM IR appears twice. Added workaround to llvm-lto2 with a FIXME. Fixes PR30610. Reviewers: mehdi_amini Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25359 llvm-svn: 284030
2016-06-14IR: Introduce local_unnamed_addr attribute.Peter Collingbourne1-3/+4
If a local_unnamed_addr attribute is attached to a global, the address is known to be insignificant within the module. It is distinct from the existing unnamed_addr attribute in that it only describes a local property of the module rather than a global property of the symbol. This attribute is intended to be used by the code generator and LTO to allow the linker to decide whether the global needs to be in the symbol table. It is possible to exclude a global from the symbol table if three things are true: - This attribute is present on every instance of the global (which means that the normal rule that the global must have a unique address can be broken without being observable by the program by performing comparisons against the global's address) - The global has linkonce_odr linkage (which means that each linkage unit must have its own copy of the global if it requires one, and the copy in each linkage unit must be the same) - It is a constant or a function (which means that the program cannot observe that the unique-address rule has been broken by writing to the global) Although this attribute could in principle be computed from the module contents, LTO clients (i.e. linkers) will normally need to be able to compute this property as part of symbol resolution, and it would be inefficient to materialize every module just to compute it. See: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html for earlier discussion. Part of the fix for PR27553. Differential Revision: http://reviews.llvm.org/D20348 llvm-svn: 272709
2016-06-08Apply most suggestions of clang-tidy's performance-unnecessary-value-paramBenjamin Kramer1-2/+2
Avoids unnecessary copies. All changes audited & pass tests with asan. No functional change intended. llvm-svn: 272190
2016-05-27Linker: teach the IR mover to return llvm::Error.Peter Collingbourne1-4/+15
This will be needed in order to consistently return an Error to clients of the API being developed in D20268. Differential Revision: http://reviews.llvm.org/D20550 llvm-svn: 270967
2016-04-21Fix recursive -only-needed.Rafael Espindola1-1/+1
We were assuming that only linkonce_odr GVs were lazy linked. llvm-svn: 266995
2016-04-21ThinLTO/ModuleLinker: add a flag to not always pull-in linkonce when ↵Mehdi Amini1-0/+9
performing importing Summary: The function importer already decided what symbols need to be pulled in. Also these magically added ones will not be in the export list for the source module, which can confuse the internalizer for instance. Reviewers: tejohnson, rafael Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D19096 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266948
2016-04-20ModuleLinker: only import what is in GlobalsToImport, regarless if it is a ↵Mehdi Amini1-22/+6
function or not. The alias handling was specific to the old iterative inlining mechanism, so that is dead now. The variable handling could make a difference, since we were previously falling through to the normal selection logic, but we don't observe changes in the validation because no client seems to rely on it. Differential Revision: http://reviews.llvm.org/D19307 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266893
2016-03-29[ThinLTO] Remove post-pass metadata linking supportTeresa Johnson1-25/+5
Since we have moved to a model where functions are imported in bulk from each source module after making summary-based importing decisions, there is no longer a need to link metadata as a postpass, and all users have been removed. This essentially reverts r255909 and follow-on fixes. llvm-svn: 264763
2016-03-24Fix another case where we were unconditionally linking linkonce GVs.Rafael Espindola1-0/+6
With this I think that now llvm-link, lld and the gold plugin should agree on which symbol is kept. llvm-svn: 264292
2016-03-24Fix resolution of linkonce symbols in comdats.Rafael Espindola1-2/+8
After comdat processing, the symbols still go through regular symbol resolution. We were not doing it for linkonce symbols since they are lazy linked. This fixes pr27044. llvm-svn: 264288
2016-03-24Fix lazy linking of comdat members.Rafael Espindola1-13/+15
If not for lazy linking of linkonce GVs, comdats are just a preprocessing before symbol resolution. Lazy linking complicates it since when we pick a visible member of comdat, we have to make sure the rest of it passes symbol resolution too. llvm-svn: 264223
2016-03-23Fix logic for which symbols to keep with comdats.Rafael Espindola1-4/+4
If a comdat is dropped, all symbols in it are dropped. If a comdat is kept, the symbols survive to pass regular symbol resolution. With this patch we do that for all global symbols. The added test is a copy of test/tools/gold/X86/comdat.ll that we now pass. llvm-svn: 264192
2016-03-22Drop comdats from the dst module if they are not selected.Rafael Espindola1-1/+72
A really unfortunate design of llvm-link and related libraries is that they operate one module at a time. This means they can copy a GV to the destination module that should not be there in the final result because a later bitcode file takes precedence. We already handled cases like a strong GV replacing a weak for example. One case that is not currently handled is a comdat replacing another. This doesn't happen in ELF, but with COFF largest selection kind it is possible. In "llvm-link a.ll b.ll" if the selected comdat was from a.ll, everything will work and we will not copy the comdat from b.ll. But if we run "llvm-link b.ll a.ll", we fail to delete the already copied comdat from b.ll. This patch fixes that. llvm-svn: 264103
2016-03-19Rework linkInModule(), making it oblivious to ThinLTOMehdi Amini1-47/+16
Summary: ThinLTO is relying on linkInModule to import selected function. However a lot of "magic" was hidden in linkInModule and the IRMover, who would rename and promote global variables on the fly. This is moving to an approach where the steps are decoupled and the client is reponsible to specify the list of globals to import. As a consequence some test are changed because they were relying on the previous behavior which was importing the definition of *every* single global without control on the client side. Now the burden is on the client to decide if a global has to be imported or not. Reviewers: tejohnson Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D18122 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 263863
2016-03-15[ThinLTO] Renaming of function index to module summary index (NFC)Teresa Johnson1-7/+7
(Resubmitting after fixing missing file issue) With the changes in r263275, there are now more than just functions in the summary. Completed the renaming of data structures (started in r263275) to reflect the wider scope. In particular, changed the FunctionIndex* data structures to ModuleIndex*, and renamed related variables and comments. Also renamed the files to reflect the changes. A companion clang patch will immediately succeed this patch to reflect this renaming. llvm-svn: 263513
2016-03-14Revert "[ThinLTO] Renaming of function index to module summary index (NFC)"Teresa Johnson1-7/+7
This reverts commit r263490. Missed a file. llvm-svn: 263493
2016-03-14[ThinLTO] Renaming of function index to module summary index (NFC)Teresa Johnson1-7/+7
With the changes in r263275, there are now more than just functions in the summary. Completed the renaming of data structures (started in r263275) to reflect the wider scope. In particular, changed the FunctionIndex* data structures to ModuleIndex*, and renamed related variables and comments. Also renamed the files to reflect the changes. A companion clang patch will immediately succeed this patch to reflect this renaming. llvm-svn: 263490
2016-03-09FunctionIndex is not optional for renameModuleForThinLTO(), make it a ↵Mehdi Amini1-1/+1
reference (NFC) From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 262976
2016-02-16Pass a std::unique_ptr to IRMover::move.Rafael Espindola1-19/+19
It was already the one "destroying" the source module, now the API reflects that. llvm-svn: 260989
2016-02-12Delete the deprecated LLVMLinkModules.Rafael Espindola1-34/+0
llvm-svn: 260683
2016-02-10[ThinLTO] Move global processing from Linker to TransformUtils (NFC)Teresa Johnson1-294/+6
Summary: As discussed on IRC, move the ThinLTOGlobalProcessing code out of the linker, and into TransformUtils. The name of the class is changed to FunctionImportGlobalProcessing. Reviewers: joker.eph, rafael Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D17081 llvm-svn: 260395
2016-02-08[ThinLTO] Remove imported available externally defs from comdats.Teresa Johnson1-2/+14
Summary: Available externally definitions are considered declarations for the linker and eventually dropped. As such they are not allowed to be in comdats. Remove any such imported functions from comdats. Reviewers: rafael Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D16120 llvm-svn: 260122
2016-01-22[ThinLTO] Do metadata linking during batch function importingTeresa Johnson1-2/+0
Summary: Since we are currently not doing incremental importing there is no need to link metadata as a postpass. The module linker will only link in the imported subroutines due to the functionality added by r256003. (Note that the metadata postpass linking functionalitiy is still used by llvm-link, and may be needed here in the future if a more incremental strategy is adopted.) Reviewers: joker.eph Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D16424 llvm-svn: 258458