Skip to content

[libc] thread.cpp fails to build with GCC on x86_64 #127916

@michaelrj-google

Description

@michaelrj-google

It seems like there's an issue with clean fullbuilds with GCC. My guess is something to do with register exhaustion, since the syscall is wrapped in two layers of always_inline functions, but I'm not sure.

CMake command:
cmake ../runtimes -G Ninja -DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLLVM_LIBC_FULL_BUILD=ON -DLLVM_LIBC_INCLUDE_SCUDO=ON -DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON -DCOMPILER_RT_BUILD_GWP_ASAN=OFF -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF

Tested on the latest commit (6342095)

Build failure:

~/llvm-project/build-gcc$ ninja libc
[297/373] Building CXX object libc/src/__support/threads/l...s/libc.src.__support.threads.linux.thread.dir/thread.cpp.o
FAILED: libc/src/__support/threads/linux/CMakeFiles/libc.src.__support.threads.linux.thread.dir/thread.cpp.o 
/usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -D_DEBUG -I~/llvm-project/libc -isystem ~/llvm-project/build-gcc/libc/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=gnu++17 -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -isystem/usr/lib/gcc/x86_64-linux-gnu/14//include -nostdinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -fext-numeric-literals -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -O3 -Wno-frame-address -MD -MT libc/src/__support/threads/linux/CMakeFiles/libc.src.__support.threads.linux.thread.dir/thread.cpp.o -MF libc/src/__support/threads/linux/CMakeFiles/libc.src.__support.threads.linux.thread.dir/thread.cpp.o.d -o libc/src/__support/threads/linux/CMakeFiles/libc.src.__support.threads.linux.thread.dir/thread.cpp.o -c ~/llvm-project/libc/src/__support/threads/linux/thread.cpp
In file included from ~/llvm-project/libc/src/__support/CPP/type_traits/integral_constant.h:11,
                 from ~/llvm-project/libc/src/__support/CPP/type_traits/has_unique_object_representations.h:11,
                 from ~/llvm-project/libc/src/__support/CPP/atomic.h:12,
                 from ~/llvm-project/libc/src/__support/threads/thread.h:12,
                 from ~/llvm-project/libc/src/__support/threads/linux/thread.cpp:9:
In function ‘long int __llvm_libc_21_0_0_git::syscall_impl(long int, long int, long int)’,
    inlined from ‘R __llvm_libc_21_0_0_git::syscall_impl(long int, Ts ...) [with R = long int; Ts = {void*, long unsigned int}]’ at ~/llvm-project/libc/src/__support/OSUtil/linux/syscall.h:34:49,
    inlined from ‘void __llvm_libc_21_0_0_git::free_stack(void*, size_t, size_t)’ at ~/llvm-project/libc/src/__support/threads/linux/thread.cpp:128:37,
    inlined from ‘void __llvm_libc_21_0_0_git::cleanup_thread_resources(ThreadAttributes*)’ at ~/llvm-project/libc/src/__support/threads/linux/thread.cpp:153:15,
    inlined from ‘int __llvm_libc_21_0_0_git::Thread::run(__llvm_libc_21_0_0_git::ThreadStyle, __llvm_libc_21_0_0_git::ThreadRunner, void*, void*, size_t, size_t, bool)’ at ~/llvm-project/libc/src/__support/threads/linux/thread.cpp:335:29:
~/llvm-project/libc/src/__support/macros/attributes.h:28:25: error: ‘asm’ operand has impossible constraints or there are not enough registers
   28 | #define LIBC_INLINE_ASM __asm__ __volatile__
      |                         ^~~~~~~
~/llvm-project/libc/src/__support/OSUtil/linux/x86_64/syscall.h:39:3: note: in expansion of macro ‘LIBC_INLINE_ASM’
   39 |   LIBC_INLINE_ASM("syscall"
      |   ^~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions