aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authoryonghong-song <yhs@fb.com>2026-02-28 12:44:25 -0800
committerGitHub <noreply@github.com>2026-02-28 12:44:25 -0800
commit3e05ab6322cbf2a96362dcacb5907ba519fe552d (patch)
tree1f85d2e4b011ff5cde05bddf65c2a002c1ea22f1 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
parente317f424557cbf76deaa568ab8a5416822453d50 (diff)
downloadllvm-3e05ab6322cbf2a96362dcacb5907ba519fe552d.zip
llvm-3e05ab6322cbf2a96362dcacb5907ba519fe552d.tar.gz
llvm-3e05ab6322cbf2a96362dcacb5907ba519fe552d.tar.bz2
[ThinLTO] Reduce the number of renaming due to promotions (#183793)
Currently for thin-lto, the imported static global values (functions, variables, etc) will be promoted/renamed from e.g., foo() to foo.llvm.(). Such a renaming caused difficulties in live patching since function name is changed ([1]). It is possible that some global value names have to be promoted to avoid name collision and linker failure. But in practice, majority of name promotions can be avoided. In [2], the suggestion is that thin-lto pre-link decides whether a particular global value needs name promotion or not. If yes, later on in thinBackend() the name will be promoted. I compiled a particular linux kernel version (latest bpf-next tree) and found 1216 global values with suffix .llvm.. With this patch, the number of promoted functions is 2, 98% reduction from the original kernel build. If some native objects are not participating with LTO, name promotions have to be done to avoid potential linker issues. So the current implementation cannot be on by default. But in certain cases, e.g., linux kernel build, people can enable lld flag --lto-whole-program-visibility to reduce the number of functions like foo.llvm.(). For ThinLTOCodeGenerator.cpp which is used by llvm-lto tool and a few other rare cases, reducing the number of renaming due to promotion, is not implemented as lld flag '-lto-whole-program-visibility' is not supported in ThinLTOCodeGenerator.cpp for now. In summary, this pull request only supports llvm-lto2 style workflow. The feature is off by default. To enable the future, lld flag '-lto-whole-program-visibility' and llvm flag '-always-rename-promoted-locals=false' are needed. The link [3] has more context for the pull request discussions. [1] https://lpc.events/event/19/contributions/2212 [2] https://discourse.llvm.org/t/rfc-avoid-functions-like-foo-llvm-for-kernel-live-patch/89400 [3] https://github.com/llvm/llvm-project/pull/178587
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index cc0491b..f031611 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1337,6 +1337,8 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
unsigned ImportType = Flags.ImportType | ImportAsDecl;
RawFlags |= (ImportType << 10); // 1 bit
+ RawFlags |= (Flags.NoRenameOnPromotion << 11); // 1 bit
+
return RawFlags;
}