[llvm] llvm-tli-checker: Take ifunc symbols into account (PR #158596)
Gleb Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 15 03:29:54 PDT 2025
https://github.com/arrowd created https://github.com/llvm/llvm-project/pull/158596
FreeBSD libc has a lot of symbols that are ifuncs, which makes TLI checker believe they are not available. This change makes the tool consider symbols with the STT_GNU_IFUNC type.
>From fb232e410da939b0697679432d91c645873db56d Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold at gmail.com>
Date: Thu, 19 Jun 2025 09:32:06 +0300
Subject: [PATCH] llvm-tli-checker: Take ifunc symbols into account
FreeBSD libc has a lot of symbols that are ifuncs, which makes TLI checker
believe they are not available. This change makes the tool consider symbols
with the STT_GNU_IFUNC type.
---
llvm/test/tools/llvm-tli-checker/ifuncs.yaml | 39 +++++++++++++++++++
.../llvm-tli-checker/llvm-tli-checker.cpp | 8 +++-
2 files changed, 45 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/tools/llvm-tli-checker/ifuncs.yaml
diff --git a/llvm/test/tools/llvm-tli-checker/ifuncs.yaml b/llvm/test/tools/llvm-tli-checker/ifuncs.yaml
new file mode 100644
index 0000000000000..4eae66c3051a7
--- /dev/null
+++ b/llvm/test/tools/llvm-tli-checker/ifuncs.yaml
@@ -0,0 +1,39 @@
+# REQUIRES: x86-registered-target
+#
+# stpncpy is declared as available in TargetLibraryInfo for FreeBSD, but
+# llvm-tli-checker won't be able to find it unless it knows how to check ifuncs.
+# This test makes sure that llvm-tli-checker supports processing ifuncs.
+#
+# RUN: yaml2obj %s -o=%t1
+# RUN: llvm-tli-checker --triple=x86_64-unknown-freebsd %t1 | FileCheck %s
+#
+# CHECK: == Total TLI yes SDK yes: 1
+#
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_FREEBSD
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ - Name: .rela.plt
+ Type: SHT_RELA
+ Flags: [ SHF_ALLOC, SHF_INFO_LINK ]
+ Address: 0x3CA20
+ Link: .dynsym
+ AddressAlign: 0x8
+ Relocations:
+ - Offset: 0x1E2C68
+ Symbol: stpncpy
+ Type: R_X86_64_JUMP_SLOT
+DynamicSymbols:
+ - Name: stpncpy
+ Type: STT_GNU_IFUNC
+ Section: .text
+ Binding: STB_WEAK
+ Value: 0x15D5E0
+ Size: 0xC
diff --git a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
index 3cd5d597ee133..0cf8c5c63bef2 100644
--- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
+++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
@@ -153,8 +153,12 @@ void SDKNameMap::maybeInsertSymbol(const SymbolRef &S, const ObjectFile &O) {
uint32_t Flags = unwrapIgnoreError(S.getFlags());
section_iterator Section = unwrapIgnoreError(S.getSection(),
/*Default=*/O.section_end());
- if (Type == SymbolRef::ST_Function && (Flags & SymbolRef::SF_Global) &&
- Section != O.section_end()) {
+ bool IsRegularFunction = Type == SymbolRef::ST_Function &&
+ (Flags & SymbolRef::SF_Global) &&
+ Section != O.section_end();
+ bool IsIFunc =
+ Type == SymbolRef::ST_Other && (Flags & SymbolRef::SF_Indirect);
+ if (IsRegularFunction || IsIFunc) {
StringRef Name = unwrapIgnoreError(S.getName());
insert({ Name, true });
}
More information about the llvm-commits
mailing list