Skip to content

Commit d4ce57c

Browse files
authored
[libc] Fix unresolved stdio symbols (#132403)
Summary: We have 'generic' implementations for some functions stdio functions. The current logic mandates that all generic functions are implemented by the target. This obviously isn't true and this caused the GPU builds to fail once baremtal added some extra ones. This patch changes the logic to always include the generic sources only if they aren't already defined. This can probably be cleaned up and formalized later, since this pattern is copied in many places, but for now this fixes the failing GPU build bots.
1 parent a013387 commit d4ce57c

File tree

2 files changed

+55
-46
lines changed

2 files changed

+55
-46
lines changed

libc/src/stdio/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ endfunction(add_stdio_entrypoint_object)
2121
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
2222
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
2323
endif()
24-
25-
if(NOT LIBC_TARGET_OS_IS_BAREMETAL AND NOT LIBC_TARGET_OS_IS_GPU)
26-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
27-
endif()
24+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
2825

2926
if(NOT LLVM_LIBC_FULL_BUILD)
3027
list(APPEND use_system_file "COMPILE_OPTIONS" "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE")

libc/src/stdio/generic/CMakeLists.txt

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
add_entrypoint_object(
1+
# Helper to only add the generic implementations if they aren't handled by a
2+
# more specific implementation.
3+
# TODO: This should probably be cleaned up and formalized.
4+
function(add_generic_entrypoint_object name)
5+
if(NOT TARGET libc.src.stdio.${LIBC_TARGET_OS}.${name})
6+
add_entrypoint_object(
7+
${name}
8+
${ARGN}
9+
)
10+
endif()
11+
endfunction(add_generic_entrypoint_object)
12+
13+
add_generic_entrypoint_object(
214
clearerr
315
SRCS
416
clearerr.cpp
@@ -10,7 +22,7 @@ add_entrypoint_object(
1022
libc.src.__support.File.platform_file
1123
)
1224

13-
add_entrypoint_object(
25+
add_generic_entrypoint_object(
1426
clearerr_unlocked
1527
SRCS
1628
clearerr_unlocked.cpp
@@ -22,7 +34,7 @@ add_entrypoint_object(
2234
libc.src.__support.File.platform_file
2335
)
2436

25-
add_entrypoint_object(
37+
add_generic_entrypoint_object(
2638
feof
2739
SRCS
2840
feof.cpp
@@ -34,7 +46,7 @@ add_entrypoint_object(
3446
libc.src.__support.File.platform_file
3547
)
3648

37-
add_entrypoint_object(
49+
add_generic_entrypoint_object(
3850
feof_unlocked
3951
SRCS
4052
feof_unlocked.cpp
@@ -46,7 +58,7 @@ add_entrypoint_object(
4658
libc.src.__support.File.platform_file
4759
)
4860

49-
add_entrypoint_object(
61+
add_generic_entrypoint_object(
5062
ferror
5163
SRCS
5264
ferror.cpp
@@ -58,7 +70,7 @@ add_entrypoint_object(
5870
libc.src.__support.File.platform_file
5971
)
6072

61-
add_entrypoint_object(
73+
add_generic_entrypoint_object(
6274
ferror_unlocked
6375
SRCS
6476
ferror_unlocked.cpp
@@ -70,7 +82,7 @@ add_entrypoint_object(
7082
libc.src.__support.File.platform_file
7183
)
7284

73-
add_entrypoint_object(
85+
add_generic_entrypoint_object(
7486
fileno
7587
SRCS
7688
fileno.cpp
@@ -82,7 +94,7 @@ add_entrypoint_object(
8294
libc.src.__support.File.platform_file
8395
)
8496

85-
add_entrypoint_object(
97+
add_generic_entrypoint_object(
8698
fflush
8799
SRCS
88100
fflush.cpp
@@ -95,7 +107,7 @@ add_entrypoint_object(
95107
libc.src.__support.File.platform_file
96108
)
97109

98-
add_entrypoint_object(
110+
add_generic_entrypoint_object(
99111
fseek
100112
SRCS
101113
fseek.cpp
@@ -107,7 +119,7 @@ add_entrypoint_object(
107119
libc.src.__support.File.platform_file
108120
)
109121

110-
add_entrypoint_object(
122+
add_generic_entrypoint_object(
111123
ftell
112124
SRCS
113125
ftell.cpp
@@ -119,7 +131,7 @@ add_entrypoint_object(
119131
libc.src.__support.File.platform_file
120132
)
121133

122-
add_entrypoint_object(
134+
add_generic_entrypoint_object(
123135
fseeko
124136
SRCS
125137
fseeko.cpp
@@ -131,7 +143,7 @@ add_entrypoint_object(
131143
libc.src.__support.File.platform_file
132144
)
133145

134-
add_entrypoint_object(
146+
add_generic_entrypoint_object(
135147
ftello
136148
SRCS
137149
ftello.cpp
@@ -143,7 +155,7 @@ add_entrypoint_object(
143155
libc.src.__support.File.platform_file
144156
)
145157

146-
add_entrypoint_object(
158+
add_generic_entrypoint_object(
147159
fopen
148160
SRCS
149161
fopen.cpp
@@ -155,7 +167,7 @@ add_entrypoint_object(
155167
libc.src.__support.File.platform_file
156168
)
157169

158-
add_entrypoint_object(
170+
add_generic_entrypoint_object(
159171
fclose
160172
SRCS
161173
fclose.cpp
@@ -168,7 +180,7 @@ add_entrypoint_object(
168180
libc.src.__support.File.platform_file
169181
)
170182

171-
add_entrypoint_object(
183+
add_generic_entrypoint_object(
172184
fread_unlocked
173185
SRCS
174186
fread_unlocked.cpp
@@ -181,7 +193,7 @@ add_entrypoint_object(
181193
libc.src.__support.File.platform_file
182194
)
183195

184-
add_entrypoint_object(
196+
add_generic_entrypoint_object(
185197
fread
186198
SRCS
187199
fread.cpp
@@ -194,7 +206,7 @@ add_entrypoint_object(
194206
libc.src.__support.File.platform_file
195207
)
196208

197-
add_entrypoint_object(
209+
add_generic_entrypoint_object(
198210
fputs
199211
SRCS
200212
fputs.cpp
@@ -207,7 +219,7 @@ add_entrypoint_object(
207219
libc.src.__support.File.platform_file
208220
)
209221

210-
add_entrypoint_object(
222+
add_generic_entrypoint_object(
211223
puts
212224
SRCS
213225
puts.cpp
@@ -220,7 +232,7 @@ add_entrypoint_object(
220232
libc.src.__support.File.platform_stdout
221233
)
222234

223-
add_entrypoint_object(
235+
add_generic_entrypoint_object(
224236
fwrite_unlocked
225237
SRCS
226238
fwrite_unlocked.cpp
@@ -233,7 +245,7 @@ add_entrypoint_object(
233245
libc.src.__support.File.platform_file
234246
)
235247

236-
add_entrypoint_object(
248+
add_generic_entrypoint_object(
237249
fwrite
238250
SRCS
239251
fwrite.cpp
@@ -246,7 +258,7 @@ add_entrypoint_object(
246258
libc.src.__support.File.platform_file
247259
)
248260

249-
add_entrypoint_object(
261+
add_generic_entrypoint_object(
250262
fputc
251263
SRCS
252264
fputc.cpp
@@ -259,7 +271,7 @@ add_entrypoint_object(
259271
libc.src.__support.File.platform_file
260272
)
261273

262-
add_entrypoint_object(
274+
add_generic_entrypoint_object(
263275
putc
264276
SRCS
265277
putc.cpp
@@ -272,7 +284,7 @@ add_entrypoint_object(
272284
libc.src.__support.File.platform_file
273285
)
274286

275-
add_entrypoint_object(
287+
add_generic_entrypoint_object(
276288
putchar
277289
SRCS
278290
putchar.cpp
@@ -285,7 +297,7 @@ add_entrypoint_object(
285297
libc.src.__support.File.platform_file
286298
)
287299

288-
add_entrypoint_object(
300+
add_generic_entrypoint_object(
289301
fgetc
290302
SRCS
291303
fgetc.cpp
@@ -298,7 +310,7 @@ add_entrypoint_object(
298310
libc.src.__support.File.platform_file
299311
)
300312

301-
add_entrypoint_object(
313+
add_generic_entrypoint_object(
302314
fgetc_unlocked
303315
SRCS
304316
fgetc_unlocked.cpp
@@ -311,7 +323,7 @@ add_entrypoint_object(
311323
libc.src.__support.File.platform_file
312324
)
313325

314-
add_entrypoint_object(
326+
add_generic_entrypoint_object(
315327
getc
316328
SRCS
317329
getc.cpp
@@ -324,7 +336,7 @@ add_entrypoint_object(
324336
libc.src.__support.File.platform_file
325337
)
326338

327-
add_entrypoint_object(
339+
add_generic_entrypoint_object(
328340
getc_unlocked
329341
SRCS
330342
getc_unlocked.cpp
@@ -337,7 +349,7 @@ add_entrypoint_object(
337349
libc.src.__support.File.platform_file
338350
)
339351

340-
add_entrypoint_object(
352+
add_generic_entrypoint_object(
341353
getchar
342354
SRCS
343355
getchar.cpp
@@ -350,7 +362,7 @@ add_entrypoint_object(
350362
libc.src.__support.File.platform_file
351363
)
352364

353-
add_entrypoint_object(
365+
add_generic_entrypoint_object(
354366
getchar_unlocked
355367
SRCS
356368
getchar_unlocked.cpp
@@ -385,7 +397,7 @@ if(LLVM_LIBC_FULL_BUILD)
385397
)
386398
endif()
387399

388-
add_entrypoint_object(
400+
add_generic_entrypoint_object(
389401
printf
390402
SRCS
391403
printf.cpp
@@ -395,7 +407,7 @@ add_entrypoint_object(
395407
${printf_deps}
396408
)
397409

398-
add_entrypoint_object(
410+
add_generic_entrypoint_object(
399411
vprintf
400412
SRCS
401413
vprintf.cpp
@@ -405,7 +417,7 @@ add_entrypoint_object(
405417
${printf_deps}
406418
)
407419

408-
add_entrypoint_object(
420+
add_generic_entrypoint_object(
409421
fprintf
410422
SRCS
411423
fprintf.cpp
@@ -415,7 +427,7 @@ add_entrypoint_object(
415427
${fprintf_deps}
416428
)
417429

418-
add_entrypoint_object(
430+
add_generic_entrypoint_object(
419431
vfprintf
420432
SRCS
421433
vfprintf.cpp
@@ -439,7 +451,7 @@ if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_GPU)
439451
)
440452
endif()
441453

442-
add_entrypoint_object(
454+
add_generic_entrypoint_object(
443455
fscanf
444456
SRCS
445457
fscanf.cpp
@@ -449,7 +461,7 @@ add_entrypoint_object(
449461
${scanf_deps}
450462
)
451463

452-
add_entrypoint_object(
464+
add_generic_entrypoint_object(
453465
vfscanf
454466
SRCS
455467
vfscanf.cpp
@@ -459,7 +471,7 @@ add_entrypoint_object(
459471
${scanf_deps}
460472
)
461473

462-
add_entrypoint_object(
474+
add_generic_entrypoint_object(
463475
scanf
464476
SRCS
465477
scanf.cpp
@@ -469,7 +481,7 @@ add_entrypoint_object(
469481
${scanf_deps}
470482
)
471483

472-
add_entrypoint_object(
484+
add_generic_entrypoint_object(
473485
vscanf
474486
SRCS
475487
vscanf.cpp
@@ -479,7 +491,7 @@ add_entrypoint_object(
479491
${scanf_deps}
480492
)
481493

482-
add_entrypoint_object(
494+
add_generic_entrypoint_object(
483495
fgets
484496
SRCS
485497
fgets.cpp
@@ -492,7 +504,7 @@ add_entrypoint_object(
492504
libc.src.__support.File.platform_file
493505
)
494506

495-
add_entrypoint_object(
507+
add_generic_entrypoint_object(
496508
ungetc
497509
SRCS
498510
ungetc.cpp
@@ -504,7 +516,7 @@ add_entrypoint_object(
504516
libc.src.__support.File.platform_file
505517
)
506518

507-
add_entrypoint_object(
519+
add_generic_entrypoint_object(
508520
stdin
509521
SRCS
510522
stdin.cpp
@@ -516,7 +528,7 @@ add_entrypoint_object(
516528
libc.src.__support.File.platform_stdin
517529
)
518530

519-
add_entrypoint_object(
531+
add_generic_entrypoint_object(
520532
stdout
521533
SRCS
522534
stdout.cpp
@@ -528,7 +540,7 @@ add_entrypoint_object(
528540
libc.src.__support.File.platform_stdout
529541
)
530542

531-
add_entrypoint_object(
543+
add_generic_entrypoint_object(
532544
stderr
533545
SRCS
534546
stderr.cpp

0 commit comments

Comments
 (0)