[llvm] [LTO] Add function alias as function instead of data (PR #112599)
Shimin Cui via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 11:47:53 PDT 2024
https://github.com/scui-ibm created https://github.com/llvm/llvm-project/pull/112599
On AIX, for undefined functions, only the dotnamed symbols (the address of the function) are generated after linking (i.e., no named function symbol is generated).
Currently, all alias symbols are added as defined data symbols when parsing symbols in LTOModule (the Link Time Optimization library used by linker to optimization code at link time). On AIX, if the function alias is used in the native object, and only its dotnamed symbol is generated, the linker will have problem to match the dotnamed symbol from the native object and the defined symbol marked as data from the bitcode at LTO linktime.
This patch is to add function alias as function instead of data.
I haven’t been able to draft a test case for this using existing llvm tools. Please comment if you think we need add a test case for this or not, or if you have any insight on how to test it. Thanks.
>From 668284f98229d283c7b8c0eca90ee4b186e87442 Mon Sep 17 00:00:00 2001
From: Shimin Cui <scui at ca.ibm.com>
Date: Wed, 16 Oct 2024 11:27:54 -0400
Subject: [PATCH] [LTO] Add function alias as function instead of data
---
llvm/include/llvm/LTO/legacy/LTOModule.h | 2 +-
llvm/lib/LTO/LTOModule.cpp | 17 +++++++++++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/LTO/legacy/LTOModule.h b/llvm/include/llvm/LTO/legacy/LTOModule.h
index 1b2de3b333855c..e861a56bcbac1d 100644
--- a/llvm/include/llvm/LTO/legacy/LTOModule.h
+++ b/llvm/include/llvm/LTO/legacy/LTOModule.h
@@ -195,7 +195,7 @@ struct LTOModule {
/// Add a function symbol as defined to the list.
void addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym);
- void addDefinedFunctionSymbol(StringRef Name, const Function *F);
+ void addDefinedFunctionSymbol(StringRef Name, const GlobalValue *F);
/// Add a global symbol from module-level ASM to the defined list.
void addAsmGlobalSymbol(StringRef, lto_symbol_attributes scope);
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index eac78069f4d2bc..00eb8adb4e1035 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -406,11 +406,16 @@ void LTOModule::addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym) {
Buffer.c_str();
}
- const Function *F = cast<Function>(cast<GlobalValue *>(Sym));
- addDefinedFunctionSymbol(Buffer, F);
+ auto *GV = cast<GlobalValue *>(Sym);
+ assert((isa<Function>(GV) ||
+ (isa<GlobalAlias>(GV) &&
+ isa<Function>(cast<GlobalAlias>(GV)->getAliasee()))) &&
+ "Not function or function alias");
+
+ addDefinedFunctionSymbol(Buffer, GV);
}
-void LTOModule::addDefinedFunctionSymbol(StringRef Name, const Function *F) {
+void LTOModule::addDefinedFunctionSymbol(StringRef Name, const GlobalValue *F) {
// add to list of defined symbols
addDefinedSymbol(Name, F, true);
}
@@ -611,7 +616,11 @@ void LTOModule::parseSymbols() {
}
assert(isa<GlobalAlias>(GV));
- addDefinedDataSymbol(Sym);
+
+ if (isa<Function>(cast<GlobalAlias>(GV)->getAliasee()))
+ addDefinedFunctionSymbol(Sym);
+ else
+ addDefinedDataSymbol(Sym);
}
// make symbols for all undefines
More information about the llvm-commits
mailing list