Skip to content

Commit fb232e4

Browse files
committed
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.
1 parent 94213a4 commit fb232e4

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# REQUIRES: x86-registered-target
2+
#
3+
# stpncpy is declared as available in TargetLibraryInfo for FreeBSD, but
4+
# llvm-tli-checker won't be able to find it unless it knows how to check ifuncs.
5+
# This test makes sure that llvm-tli-checker supports processing ifuncs.
6+
#
7+
# RUN: yaml2obj %s -o=%t1
8+
# RUN: llvm-tli-checker --triple=x86_64-unknown-freebsd %t1 | FileCheck %s
9+
#
10+
# CHECK: == Total TLI yes SDK yes: 1
11+
#
12+
13+
--- !ELF
14+
FileHeader:
15+
Class: ELFCLASS64
16+
Data: ELFDATA2LSB
17+
OSABI: ELFOSABI_FREEBSD
18+
Type: ET_DYN
19+
Machine: EM_X86_64
20+
Sections:
21+
- Name: .text
22+
Type: SHT_PROGBITS
23+
- Name: .rela.plt
24+
Type: SHT_RELA
25+
Flags: [ SHF_ALLOC, SHF_INFO_LINK ]
26+
Address: 0x3CA20
27+
Link: .dynsym
28+
AddressAlign: 0x8
29+
Relocations:
30+
- Offset: 0x1E2C68
31+
Symbol: stpncpy
32+
Type: R_X86_64_JUMP_SLOT
33+
DynamicSymbols:
34+
- Name: stpncpy
35+
Type: STT_GNU_IFUNC
36+
Section: .text
37+
Binding: STB_WEAK
38+
Value: 0x15D5E0
39+
Size: 0xC

llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ void SDKNameMap::maybeInsertSymbol(const SymbolRef &S, const ObjectFile &O) {
153153
uint32_t Flags = unwrapIgnoreError(S.getFlags());
154154
section_iterator Section = unwrapIgnoreError(S.getSection(),
155155
/*Default=*/O.section_end());
156-
if (Type == SymbolRef::ST_Function && (Flags & SymbolRef::SF_Global) &&
157-
Section != O.section_end()) {
156+
bool IsRegularFunction = Type == SymbolRef::ST_Function &&
157+
(Flags & SymbolRef::SF_Global) &&
158+
Section != O.section_end();
159+
bool IsIFunc =
160+
Type == SymbolRef::ST_Other && (Flags & SymbolRef::SF_Indirect);
161+
if (IsRegularFunction || IsIFunc) {
158162
StringRef Name = unwrapIgnoreError(S.getName());
159163
insert({ Name, true });
160164
}

0 commit comments

Comments
 (0)