Skip to content

Commit e6f7637

Browse files
authored
EntryExitInstrumenter: skip available_externally linkage
gnu::always_inline functions, which lower to available_externally, may not have definitions external to the module. -finstrument-function family options instrumentating the function (which takes the function address) may lead to a linker error if the function is not optimized out, e.g. ``` // -std=c++17 or above with libstdc++ #include <string> std::string str; int main() {} ``` Simplified reproduce: ``` template <typename T> struct A { [[gnu::always_inline]] T bar(T a) { return a * 2; } }; extern template class A<int>; int main(int argc, char **argv) { return A<int>().bar(argc); } ``` GCC's -finstrument-function instrumentation skips such functions (https://gcc.gnu.org/PR78333). Let's skip such functions (available_externally) as well. Fix #50742 Pull Request: #121452
1 parent c19f0f0 commit e6f7637

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ static bool runOnFunction(Function &F, bool PostInlining) {
103103
if (F.hasFnAttribute(Attribute::Naked))
104104
return false;
105105

106+
// available_externally functions may not have definitions external to the
107+
// module (e.g. gnu::always_inline). Instrumenting them might lead to linker
108+
// errors if they are optimized out. Skip them like GCC.
109+
if (F.hasAvailableExternallyLinkage())
110+
return false;
111+
106112
StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined"
107113
: "instrument-function-entry";
108114

llvm/test/Transforms/EntryExitInstrumenter/mcount.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ define void @naked() naked {
129129
ret void
130130
}
131131

132+
define available_externally void @always_inline() {
133+
; CHECK-LABEL: define available_externally void @always_inline() {
134+
; CHECK-NEXT: ret void
135+
;
136+
ret void
137+
}
138+
132139
; The attributes are "consumed" when the instrumentation is inserted.
133140
; CHECK: attributes
134141
; CHECK-NOT: instrument-function

0 commit comments

Comments
 (0)