Skip to content

Commit 38be8f4

Browse files
committed
Add llvm-tli-checker
A new tool that compares TargetLibraryInfo's opinion of the availability of library function calls against the functions actually exported by a specified set of libraries. Can be helpful in verifying the correctness of TLI for a given target, and avoid mishaps such as had to be addressed in D107509 and 94b4598. The tool currently supports ELF object files only, although it's unlikely to be hard to add support for other formats. Re-commits 62dd488 with changes to use pre-generated objects, as not all bots have ld.lld available. Differential Revision: https://reviews.llvm.org/D111358
1 parent ae40d62 commit 38be8f4

File tree

8 files changed

+776
-0
lines changed

8 files changed

+776
-0
lines changed

llvm/docs/CommandGuide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ Developer Tools
8282
llvm-locstats
8383
llvm-pdbutil
8484
llvm-profgen
85+
llvm-tli-checker
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
llvm-tli-checker - TargetLibraryInfo vs library checker
2+
=======================================================
3+
4+
.. program:: llvm-tli-checker
5+
6+
SYNOPSIS
7+
--------
8+
9+
:program:`llvm-tli-checker` [*options*] [*library-file...*]
10+
11+
DESCRIPTION
12+
-----------
13+
14+
:program:`llvm-tli-checker` compares TargetLibraryInfo's opinion of the
15+
availability of library functions against the set of functions exported
16+
by the specified library files, reporting any disagreements between TLI's
17+
opinion and whether the function is actually present. This is primarily
18+
useful for vendors to ensure the TLI for their target is correct, and
19+
the compiler will not "optimize" some code sequence into a library call
20+
that is not actually available.
21+
22+
EXAMPLE
23+
-------
24+
25+
.. code-block:: console
26+
27+
$ llvm-tli-checker --triple x86_64-scei-ps4 example.so
28+
TLI knows 466 symbols, 235 available for 'x86_64-scei-ps4'
29+
30+
Looking for symbols in 'example.so'
31+
Found 235 global function symbols in 'example.so'
32+
Found a grand total of 235 library symbols
33+
<< TLI yes SDK no: '_ZdaPv' aka operator delete[](void*)
34+
>> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
35+
<< Total TLI yes SDK no: 1
36+
>> Total TLI no SDK yes: 1
37+
== Total TLI yes SDK yes: 234
38+
FAIL: LLVM TLI doesn't match SDK libraries.
39+
40+
OPTIONS
41+
-------
42+
43+
.. option:: --dump-tli
44+
45+
Print "available"/"not available" for each library function, according to
46+
TargetLibraryInfo's information for the specified triple, and exit. This
47+
option does not read any input files.
48+
49+
.. option:: --help, -h
50+
51+
Print a summary of command line options and exit.
52+
53+
.. option:: --libdir=<directory>
54+
55+
A base directory to prepend to each library file path. This is handy
56+
when there are a number of library files all in the same directory, or
57+
a list of input filenames are kept in a response file.
58+
59+
.. option:: --report=<level>
60+
61+
The amount of information to report. <level> can be summary, discrepancy,
62+
or full. A summary report gives only the count of matching and mis-matching
63+
symbols; discrepancy lists the mis-matching symbols; and full lists all
64+
symbols known to TLI, matching or mis-matching. The default is discrepancy.
65+
66+
.. option:: --separate
67+
68+
Read and report a summary for each library file separately. This can be
69+
useful to identify library files that don't contribute anything that TLI
70+
knows about. Implies --report=summary (can be overridden).
71+
72+
.. option:: --triple=<triple>
73+
74+
The triple to use for initializing TargetLibraryInfo.
75+
76+
.. option:: @<FILE>
77+
78+
Read command-line options and/or library names from response file `<FILE>`.
79+
80+
EXIT STATUS
81+
-----------
82+
83+
:program:`llvm-tli-checker` returns 0 even if there are mismatches. It returns a
84+
non-zero exit code if there is an unrecognized option, or no input files are
85+
provided.
Binary file not shown.
Binary file not shown.
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
# REQUIRES: x86-registered-target
2+
#
3+
## The object files ps4-tli-checks.right.so and ps4-tli-checks.wrong.so
4+
## were generated with the following commands:
5+
## llvm-mc --triple=x86_64-scei-ps4 --filetype=obj ps4-tli-check.s -o t.o
6+
## ld.lld --shared t.o -o Inputs/ps4-tli-check.right.so
7+
## llvm-mc --triple=x86_64-scei-ps4 --defsym WRONG=1 --filetype=obj ps4-tli-check.s -o t2.o
8+
## ld.lld --shared t2.o -o Inputs/ps4-tli-check.wrong.so
9+
#
10+
# RUN: llvm-tli-checker --triple=x86_64-scei-ps4 %S/Inputs/ps4-tli-check.right.so | FileCheck %s
11+
#
12+
# RUN: echo %S/Inputs/ps4-tli-check.wrong.so > %t2.txt
13+
# RUN: llvm-tli-checker --triple x86_64-scei-ps4 @%t2.txt | \
14+
# RUN: FileCheck %s --check-prefix=WRONG_SUMMARY --check-prefix=WRONG_DETAIL \
15+
# RUN: --implicit-check-not="==" --implicit-check-not="<<" --implicit-check-not=">>"
16+
# RUN: llvm-tli-checker --triple x86_64-scei-ps4 @%t2.txt --report=summary | \
17+
# RUN: FileCheck %s --check-prefix=WRONG_SUMMARY \
18+
# RUN: --implicit-check-not="==" --implicit-check-not="<<" --implicit-check-not=">>"
19+
## --separate implies --report=summary.
20+
# RUN: llvm-tli-checker --triple x86_64-scei-ps4 @%t2.txt --separate | \
21+
# RUN: FileCheck %s --check-prefix=WRONG_SUMMARY \
22+
# RUN: --implicit-check-not="==" --implicit-check-not="<<" --implicit-check-not=">>"
23+
#
24+
# RUN: llvm-tli-checker --triple x86_64-scei-ps4 --dump-tli > %t3.txt
25+
# RUN: FileCheck %s --check-prefix=AVAIL --input-file %t3.txt
26+
# RUN: FileCheck %s --check-prefix=UNAVAIL --input-file %t3.txt
27+
#
28+
# CHECK: << Total TLI yes SDK no: 0
29+
# CHECK: >> Total TLI no SDK yes: 0
30+
# CHECK: == Total TLI yes SDK yes: 235
31+
#
32+
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv'
33+
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj'
34+
# WRONG_SUMMARY: << Total TLI yes SDK no: 1{{$}}
35+
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
36+
# WRONG_SUMMARY: == Total TLI yes SDK yes: 234
37+
#
38+
## The -COUNT suffix doesn't care if there are too many matches, so check
39+
## the exact count first; the two directives should add up to that.
40+
# AVAIL: TLI knows 466 symbols, 235 available
41+
# AVAIL-COUNT-235: {{^}} available
42+
# UNAVAIL-COUNT-231: not available
43+
44+
.macro defname name
45+
.globl \name
46+
.type \name ,@function
47+
\name : nop
48+
.endm
49+
50+
.text
51+
# For the WRONG case, omit _ZdaPv and include _ZdaPvj.
52+
.ifdef WRONG
53+
defname _ZdaPvj
54+
.else
55+
defname _ZdaPv
56+
.endif
57+
defname _ZdaPvRKSt9nothrow_t
58+
defname _ZdaPvSt11align_val_t
59+
defname _ZdaPvSt11align_val_tRKSt9nothrow_t
60+
defname _ZdaPvm
61+
defname _ZdaPvmSt11align_val_t
62+
defname _ZdlPv
63+
defname _ZdlPvRKSt9nothrow_t
64+
defname _ZdlPvSt11align_val_t
65+
defname _ZdlPvSt11align_val_tRKSt9nothrow_t
66+
defname _ZdlPvm
67+
defname _ZdlPvmSt11align_val_t
68+
defname _Znam
69+
defname _ZnamRKSt9nothrow_t
70+
defname _ZnamSt11align_val_t
71+
defname _ZnamSt11align_val_tRKSt9nothrow_t
72+
defname _Znwm
73+
defname _ZnwmRKSt9nothrow_t
74+
defname _ZnwmSt11align_val_t
75+
defname _ZnwmSt11align_val_tRKSt9nothrow_t
76+
defname __cxa_atexit
77+
defname __cxa_guard_abort
78+
defname __cxa_guard_acquire
79+
defname __cxa_guard_release
80+
defname abs
81+
defname acos
82+
defname acosf
83+
defname acosh
84+
defname acoshf
85+
defname acoshl
86+
defname acosl
87+
defname aligned_alloc
88+
defname asin
89+
defname asinf
90+
defname asinh
91+
defname asinhf
92+
defname asinhl
93+
defname asinl
94+
defname atan
95+
defname atan2
96+
defname atan2f
97+
defname atan2l
98+
defname atanf
99+
defname atanh
100+
defname atanhf
101+
defname atanhl
102+
defname atanl
103+
defname atof
104+
defname atoi
105+
defname atol
106+
defname atoll
107+
defname calloc
108+
defname cbrt
109+
defname cbrtf
110+
defname cbrtl
111+
defname ceil
112+
defname ceilf
113+
defname ceill
114+
defname clearerr
115+
defname copysign
116+
defname copysignf
117+
defname copysignl
118+
defname cos
119+
defname cosf
120+
defname cosh
121+
defname coshf
122+
defname coshl
123+
defname cosl
124+
defname exp
125+
defname exp2
126+
defname exp2f
127+
defname exp2l
128+
defname expf
129+
defname expl
130+
defname expm1
131+
defname expm1f
132+
defname expm1l
133+
defname fabs
134+
defname fabsf
135+
defname fabsl
136+
defname fclose
137+
defname fdopen
138+
defname feof
139+
defname ferror
140+
defname fflush
141+
defname fgetc
142+
defname fgetpos
143+
defname fgets
144+
defname fileno
145+
defname floor
146+
defname floorf
147+
defname floorl
148+
defname fmax
149+
defname fmaxf
150+
defname fmaxl
151+
defname fmin
152+
defname fminf
153+
defname fminl
154+
defname fmod
155+
defname fmodf
156+
defname fmodl
157+
defname fopen
158+
defname fprintf
159+
defname fputc
160+
defname fputs
161+
defname fread
162+
defname free
163+
defname frexp
164+
defname frexpf
165+
defname frexpl
166+
defname fscanf
167+
defname fseek
168+
defname fsetpos
169+
defname ftell
170+
defname fwrite
171+
defname getc
172+
defname getchar
173+
defname gets
174+
defname isdigit
175+
defname labs
176+
defname ldexp
177+
defname ldexpf
178+
defname ldexpl
179+
defname llabs
180+
defname log
181+
defname log10
182+
defname log10f
183+
defname log10l
184+
defname log1p
185+
defname log1pf
186+
defname log1pl
187+
defname log2
188+
defname log2f
189+
defname log2l
190+
defname logb
191+
defname logbf
192+
defname logbl
193+
defname logf
194+
defname logl
195+
defname malloc
196+
defname memalign
197+
defname memchr
198+
defname memcmp
199+
defname memcpy
200+
defname memmove
201+
defname memset
202+
defname mktime
203+
defname modf
204+
defname modff
205+
defname modfl
206+
defname nearbyint
207+
defname nearbyintf
208+
defname nearbyintl
209+
defname perror
210+
defname posix_memalign
211+
defname pow
212+
defname powf
213+
defname powl
214+
defname printf
215+
defname putc
216+
defname putchar
217+
defname puts
218+
defname qsort
219+
defname realloc
220+
defname remainder
221+
defname remainderf
222+
defname remainderl
223+
defname remove
224+
defname rewind
225+
defname rint
226+
defname rintf
227+
defname rintl
228+
defname round
229+
defname roundf
230+
defname roundl
231+
defname scanf
232+
defname setbuf
233+
defname setvbuf
234+
defname sin
235+
defname sinf
236+
defname sinh
237+
defname sinhf
238+
defname sinhl
239+
defname sinl
240+
defname snprintf
241+
defname sprintf
242+
defname sqrt
243+
defname sqrtf
244+
defname sqrtl
245+
defname sscanf
246+
defname strcasecmp
247+
defname strcat
248+
defname strchr
249+
defname strcmp
250+
defname strcoll
251+
defname strcpy
252+
defname strcspn
253+
defname strdup
254+
defname strlen
255+
defname strncasecmp
256+
defname strncat
257+
defname strncmp
258+
defname strncpy
259+
defname strpbrk
260+
defname strrchr
261+
defname strspn
262+
defname strstr
263+
defname strtod
264+
defname strtof
265+
defname strtok
266+
defname strtok_r
267+
defname strtol
268+
defname strtold
269+
defname strtoll
270+
defname strtoul
271+
defname strtoull
272+
defname strxfrm
273+
defname tan
274+
defname tanf
275+
defname tanh
276+
defname tanhf
277+
defname tanhl
278+
defname tanl
279+
defname trunc
280+
defname truncf
281+
defname truncl
282+
defname ungetc
283+
defname vfprintf
284+
defname vfscanf
285+
defname vprintf
286+
defname vscanf
287+
defname vsnprintf
288+
defname vsprintf
289+
defname vsscanf
290+
defname wcslen
291+

0 commit comments

Comments
 (0)