Skip to content

Commit c2735d2

Browse files
authored
[libc][stdlib] Bring all GPU's alloc/free entrypoints under the same conditional. (#96373)
1 parent d69050d commit c2735d2

File tree

1 file changed

+104
-104
lines changed

1 file changed

+104
-104
lines changed

libc/src/stdlib/CMakeLists.txt

Lines changed: 104 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -317,97 +317,121 @@ add_entrypoint_object(
317317
libc.include.stdlib
318318
)
319319

320-
if(LLVM_LIBC_INCLUDE_SCUDO)
321-
set(SCUDO_DEPS "")
320+
if(NOT LIBC_TARGET_OS_IS_GPU)
321+
if(LLVM_LIBC_INCLUDE_SCUDO)
322+
set(SCUDO_DEPS "")
323+
324+
include(${LIBC_SOURCE_DIR}/../compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake)
325+
326+
# scudo distinguishes riscv32 and riscv64, so we need to translate the architecture
327+
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO ${LIBC_TARGET_ARCHITECTURE})
328+
if(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
329+
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO riscv64)
330+
elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV32)
331+
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO riscv32)
332+
endif()
333+
334+
if(NOT (LIBC_TARGET_ARCHITECTURE_FOR_SCUDO IN_LIST ALL_SCUDO_STANDALONE_SUPPORTED_ARCH))
335+
message(FATAL_ERROR "Architecture ${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} is not supported by SCUDO.
336+
Either disable LLVM_LIBC_INCLUDE_SCUDO or change your target architecture.")
337+
endif()
338+
339+
list(APPEND SCUDO_DEPS RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
340+
RTScudoStandaloneCWrappers.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO})
341+
342+
list(APPEND SCUDO_DEPS
343+
RTGwpAsan.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
344+
RTGwpAsanBacktraceLibc.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
345+
RTGwpAsanSegvHandler.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
346+
)
322347

323-
include(${LIBC_SOURCE_DIR}/../compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake)
324-
325-
# scudo distinguishes riscv32 and riscv64, so we need to translate the architecture
326-
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO ${LIBC_TARGET_ARCHITECTURE})
327-
if(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
328-
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO riscv64)
329-
elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV32)
330-
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO riscv32)
331-
endif()
348+
add_entrypoint_external(
349+
malloc
350+
DEPENDS
351+
${SCUDO_DEPS}
352+
)
353+
add_entrypoint_external(
354+
calloc
355+
DEPENDS
356+
${SCUDO_DEPS}
357+
)
358+
add_entrypoint_external(
359+
realloc
360+
DEPENDS
361+
${SCUDO_DEPS}
362+
)
363+
add_entrypoint_external(
364+
aligned_alloc
365+
DEPENDS
366+
${SCUDO_DEPS}
367+
)
368+
add_entrypoint_external(
369+
free
370+
DEPENDS
371+
${SCUDO_DEPS}
372+
)
373+
else()
374+
# Only use freelist malloc for baremetal targets.
375+
add_entrypoint_object(
376+
freelist_malloc
377+
SRCS
378+
freelist_malloc.cpp
379+
HDRS
380+
malloc.h
381+
DEPENDS
382+
libc.src.__support.freelist_heap
383+
COMPILE_OPTIONS
384+
-DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
385+
)
386+
get_target_property(freelist_malloc_is_skipped libc.src.stdlib.freelist_malloc "SKIPPED")
387+
if(LIBC_TARGET_OS_IS_BAREMETAL AND NOT freelist_malloc_is_skipped)
388+
add_entrypoint_object(
389+
malloc
390+
ALIAS
391+
DEPENDS
392+
.freelist_malloc
393+
)
394+
else()
395+
add_entrypoint_external(
396+
malloc
397+
)
398+
endif()
332399

333-
if(NOT (LIBC_TARGET_ARCHITECTURE_FOR_SCUDO IN_LIST ALL_SCUDO_STANDALONE_SUPPORTED_ARCH))
334-
message(FATAL_ERROR "Architecture ${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} is not supported by SCUDO.
335-
Either disable LLVM_LIBC_INCLUDE_SCUDO or change your target architecture.")
400+
add_entrypoint_external(
401+
free
402+
)
403+
add_entrypoint_external(
404+
calloc
405+
)
406+
add_entrypoint_external(
407+
realloc
408+
)
409+
add_entrypoint_external(
410+
aligned_alloc
411+
)
336412
endif()
413+
endif()
337414

338-
list(APPEND SCUDO_DEPS RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
339-
RTScudoStandaloneCWrappers.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO})
415+
if(NOT LLVM_LIBC_FULL_BUILD)
416+
return()
417+
endif()
340418

341-
list(APPEND SCUDO_DEPS
342-
RTGwpAsan.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
343-
RTGwpAsanBacktraceLibc.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
344-
RTGwpAsanSegvHandler.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
345-
)
419+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
420+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
421+
endif()
346422

347-
add_entrypoint_external(
423+
if(LIBC_TARGET_OS_IS_GPU)
424+
add_entrypoint_object(
348425
malloc
426+
ALIAS
349427
DEPENDS
350-
${SCUDO_DEPS}
351-
)
352-
add_entrypoint_external(
353-
calloc
354-
DEPENDS
355-
${SCUDO_DEPS}
356-
)
357-
add_entrypoint_external(
358-
realloc
359-
DEPENDS
360-
${SCUDO_DEPS}
361-
)
362-
add_entrypoint_external(
363-
aligned_alloc
364-
DEPENDS
365-
${SCUDO_DEPS}
366-
)
367-
add_entrypoint_external(
368-
free
369-
DEPENDS
370-
${SCUDO_DEPS}
371-
)
372-
elseif(LIBC_TARGET_OS_IS_GPU)
373-
add_entrypoint_external(
374-
calloc
375-
)
376-
add_entrypoint_external(
377-
realloc
378-
)
379-
add_entrypoint_external(
380-
aligned_alloc
428+
.${LIBC_TARGET_OS}.malloc
381429
)
382-
else()
383-
# Only use freelist malloc for baremetal targets.
384430
add_entrypoint_object(
385-
freelist_malloc
386-
SRCS
387-
freelist_malloc.cpp
388-
HDRS
389-
malloc.h
390-
DEPENDS
391-
libc.src.__support.freelist_heap
392-
COMPILE_OPTIONS
393-
-DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
394-
)
395-
get_target_property(freelist_malloc_is_skipped libc.src.stdlib.freelist_malloc "SKIPPED")
396-
if(LIBC_TARGET_OS_IS_BAREMETAL AND NOT freelist_malloc_is_skipped)
397-
add_entrypoint_object(
398-
malloc
399-
ALIAS
400-
DEPENDS
401-
.freelist_malloc
402-
)
403-
else()
404-
add_entrypoint_external(
405-
malloc
406-
)
407-
endif()
408-
409-
add_entrypoint_external(
410431
free
432+
ALIAS
433+
DEPENDS
434+
.${LIBC_TARGET_OS}.free
411435
)
412436
add_entrypoint_external(
413437
calloc
@@ -420,14 +444,6 @@ else()
420444
)
421445
endif()
422446

423-
if(NOT LLVM_LIBC_FULL_BUILD)
424-
return()
425-
endif()
426-
427-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
428-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
429-
endif()
430-
431447
add_entrypoint_object(
432448
_Exit
433449
SRCS
@@ -499,19 +515,3 @@ add_entrypoint_object(
499515
DEPENDS
500516
.${LIBC_TARGET_OS}.abort
501517
)
502-
503-
if(LIBC_TARGET_OS_IS_GPU)
504-
add_entrypoint_object(
505-
malloc
506-
ALIAS
507-
DEPENDS
508-
.${LIBC_TARGET_OS}.malloc
509-
)
510-
511-
add_entrypoint_object(
512-
free
513-
ALIAS
514-
DEPENDS
515-
.${LIBC_TARGET_OS}.free
516-
)
517-
endif()

0 commit comments

Comments
 (0)