Skip to content

Commit 5db6aa6

Browse files
jhuber6yuxuanchen1997
authored andcommitted
[libc] Remove workarounds for lack of functional NVPTX linker (#96972)
Summary: Currently we have several hacks to work around the fact that the NVPTX linker, 'nvlink', does not support static libraries or LTO linking. The patch in #96561 introduces a wrapper in the toolchain that allows us to use a standard `ld.lld` like interface. This means all the divergence with this target can be removed. Depends on #96561
1 parent 06a895f commit 5db6aa6

File tree

4 files changed

+20
-54
lines changed

4 files changed

+20
-54
lines changed

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,6 @@ function(create_object_library fq_target_name)
6565
target_include_directories(${fq_target_name} PRIVATE ${LIBC_SOURCE_DIR})
6666
target_compile_options(${fq_target_name} PRIVATE ${compile_options})
6767

68-
# The NVPTX target is installed as LLVM-IR but the internal testing toolchain
69-
# cannot handle it natively. Make a separate internal target for testing.
70-
if(LIBC_TARGET_ARCHITECTURE_IS_NVPTX AND NOT LIBC_GPU_TESTS_DISABLED)
71-
add_library(
72-
${internal_target_name}
73-
EXCLUDE_FROM_ALL
74-
OBJECT
75-
${ADD_OBJECT_SRCS}
76-
${ADD_OBJECT_HDRS}
77-
)
78-
target_include_directories(${internal_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
79-
target_include_directories(${internal_target_name} PRIVATE ${LIBC_SOURCE_DIR})
80-
target_compile_options(${internal_target_name} PRIVATE ${compile_options}
81-
-fno-lto -march=${LIBC_GPU_TARGET_ARCHITECTURE})
82-
set_target_properties(${internal_target_name}
83-
PROPERTIES
84-
CXX_STANDARD ${ADD_OBJECT_CXX_STANDARD})
85-
endif()
86-
8768
if(SHOW_INTERMEDIATE_OBJECTS)
8869
message(STATUS "Adding object library ${fq_target_name}")
8970
if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
@@ -283,12 +264,6 @@ function(create_entrypoint_object fq_target_name)
283264
add_dependencies(${internal_target_name} ${full_deps_list})
284265
target_link_libraries(${internal_target_name} ${full_deps_list})
285266

286-
# The NVPTX target cannot use LTO for the internal targets used for testing.
287-
if(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
288-
target_compile_options(${internal_target_name} PRIVATE
289-
-fno-lto -march=${LIBC_GPU_TARGET_ARCHITECTURE})
290-
endif()
291-
292267
add_library(
293268
${fq_target_name}
294269
# We want an object library as the objects will eventually get packaged into

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ function(add_integration_test test_name)
453453
add_executable(
454454
${fq_build_target_name}
455455
EXCLUDE_FROM_ALL
456-
# The NVIDIA 'nvlink' linker does not currently support static libraries.
457-
$<$<BOOL:${LIBC_TARGET_ARCHITECTURE_IS_NVPTX}>:${link_object_files}>
458456
${INTEGRATION_TEST_SRCS}
459457
${INTEGRATION_TEST_HDRS}
460458
)
@@ -473,8 +471,6 @@ function(add_integration_test test_name)
473471
"-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0" -nostdlib -static
474472
"-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}")
475473
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
476-
# We need to use the internal object versions for NVPTX.
477-
set(internal_suffix ".__internal__")
478474
target_link_options(${fq_build_target_name} PRIVATE
479475
${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
480476
"-Wl,--suppress-stack-size-warning"
@@ -490,10 +486,9 @@ function(add_integration_test test_name)
490486
endif()
491487
target_link_libraries(
492488
${fq_build_target_name}
493-
# The NVIDIA 'nvlink' linker does not currently support static libraries.
494-
$<$<NOT:$<BOOL:${LIBC_TARGET_ARCHITECTURE_IS_NVPTX}>>:${fq_target_name}.__libc__>
495-
libc.startup.${LIBC_TARGET_OS}.crt1${internal_suffix}
496-
libc.test.IntegrationTest.test${internal_suffix}
489+
${fq_target_name}.__libc__
490+
libc.startup.${LIBC_TARGET_OS}.crt1
491+
libc.test.IntegrationTest.test
497492
)
498493
add_dependencies(${fq_build_target_name}
499494
libc.test.IntegrationTest.test
@@ -628,8 +623,6 @@ function(add_libc_hermetic test_name)
628623
add_executable(
629624
${fq_build_target_name}
630625
EXCLUDE_FROM_ALL
631-
# The NVIDIA 'nvlink' linker does not currently support static libraries.
632-
$<$<BOOL:${LIBC_TARGET_ARCHITECTURE_IS_NVPTX}>:${link_object_files}>
633626
${HERMETIC_TEST_SRCS}
634627
${HERMETIC_TEST_HDRS}
635628
)
@@ -656,13 +649,12 @@ function(add_libc_hermetic test_name)
656649

657650
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
658651
target_link_options(${fq_build_target_name} PRIVATE
659-
${LIBC_COMPILE_OPTIONS_DEFAULT}
660-
-mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto -Wno-multi-gpu
652+
${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
653+
-mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
654+
"-Wl,-asdfasdfasdf"
661655
"-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0" -nostdlib -static
662656
"-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}")
663657
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
664-
# We need to use the internal object versions for NVPTX.
665-
set(internal_suffix ".__internal__")
666658
target_link_options(${fq_build_target_name} PRIVATE
667659
${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
668660
"-Wl,--suppress-stack-size-warning"
@@ -679,11 +671,10 @@ function(add_libc_hermetic test_name)
679671
target_link_libraries(
680672
${fq_build_target_name}
681673
PRIVATE
682-
libc.startup.${LIBC_TARGET_OS}.crt1${internal_suffix}
674+
libc.startup.${LIBC_TARGET_OS}.crt1
683675
${link_libraries}
684676
LibcHermeticTestSupport.hermetic
685-
# The NVIDIA 'nvlink' linker does not currently support static libraries.
686-
$<$<NOT:$<BOOL:${LIBC_TARGET_ARCHITECTURE_IS_NVPTX}>>:${fq_target_name}.__libc__>)
677+
${fq_target_name}.__libc__)
687678
add_dependencies(${fq_build_target_name}
688679
LibcTest.hermetic
689680
libc.test.UnitTest.ErrnoSetterMatcher

libc/config/gpu/entrypoints.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
2+
set(extra_entrypoints
3+
# stdio.h entrypoints
4+
libc.src.stdio.snprintf
5+
libc.src.stdio.sprintf
6+
libc.src.stdio.vsnprintf
7+
libc.src.stdio.vsprintf
8+
)
9+
endif()
10+
111
set(TARGET_LIBC_ENTRYPOINTS
212
# assert.h entrypoints
313
libc.src.assert.__assert_fail
@@ -176,16 +186,13 @@ set(TARGET_LIBC_ENTRYPOINTS
176186
libc.src.errno.errno
177187

178188
# stdio.h entrypoints
189+
${extra_entrypoints}
179190
libc.src.stdio.clearerr
180191
libc.src.stdio.fclose
181192
libc.src.stdio.printf
182193
libc.src.stdio.vprintf
183194
libc.src.stdio.fprintf
184195
libc.src.stdio.vfprintf
185-
libc.src.stdio.sprintf
186-
libc.src.stdio.snprintf
187-
libc.src.stdio.vsprintf
188-
libc.src.stdio.vsnprintf
189196
libc.src.stdio.feof
190197
libc.src.stdio.ferror
191198
libc.src.stdio.fflush

libc/test/UnitTest/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ function(add_unittest_framework_library name)
1111
"header only libraries, use 'add_header_library'")
1212
endif()
1313

14-
# The Nvidia 'nvlink' linker does not support static libraries.
15-
if(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
16-
set(library_type OBJECT)
17-
else()
18-
set(library_type STATIC)
19-
endif()
20-
2114
foreach(lib IN ITEMS ${name}.unit ${name}.hermetic)
2215
add_library(
2316
${lib}
24-
${library_type}
17+
STATIC
2518
EXCLUDE_FROM_ALL
2619
${TEST_LIB_SRCS}
2720
${TEST_LIB_HDRS}

0 commit comments

Comments
 (0)