[libc-commits] [libc] [libc] Make 'rand()' thread-safe using atomics instead of TLS (PR #96692)

LLVM Continuous Integration via libc-commits libc-commits at lists.llvm.org
Wed Jun 26 05:24:58 PDT 2024


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` running on `fuchsia-debian-64-us-central1-a-1` while building `libc` at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/642

Here is the relevant piece of the build log for the reference:
```
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[353/1568] Building CXX object libc/src/stdfix/CMakeFiles/libc.src.stdfix.roundulk.dir/roundulk.cpp.obj
[354/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.asinf.dir/asinf.cpp.obj
[355/1568] Building CXX object libc/src/stdfix/CMakeFiles/libc.src.stdfix.uksqrtui.dir/uksqrtui.cpp.obj
[356/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.acosf.dir/acosf.cpp.obj
[357/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.bsearch.dir/bsearch.cpp.obj
[358/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.hypot.dir/hypot.cpp.obj
[359/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.div.dir/div.cpp.obj
[360/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.ldiv.dir/ldiv.cpp.obj
[361/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.lldiv.dir/lldiv.cpp.obj
[362/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj
FAILED: libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/bin/clang++ --target=armv6m-unknown-eabi -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/include/armv6m-unknown-eabi --target=armv6m-unknown-eabi -mthumb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/runtimes/runtimes-armv6m-unknown-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -O2 -g -DNDEBUG -std=gnu++17 --target=armv6m-unknown-eabi -fpie -DLIBC_FULL_BUILD -ffreestanding -ffixed-point -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 -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj -MF libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj.d -o libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/srand.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/srand.cpp:11:
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand_util.h:12:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/CPP/atomic.h:90:5: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
   90 |     __scoped_atomic_store_n(&val, rhs, int(mem_ord), (int)(mem_scope));
      |     ^
1 error generated.
[363/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strerror.dir/strerror.cpp.obj
[364/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strerror_r.dir/strerror_r.cpp.obj
[365/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.scalbn.dir/scalbn.cpp.obj
[366/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj
FAILED: libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/bin/clang++ --target=armv6m-unknown-eabi -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/include/armv6m-unknown-eabi --target=armv6m-unknown-eabi -mthumb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/runtimes/runtimes-armv6m-unknown-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -O2 -g -DNDEBUG -std=gnu++17 --target=armv6m-unknown-eabi -fpie -DLIBC_FULL_BUILD -ffreestanding -ffixed-point -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 -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj -MF libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj.d -o libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand.cpp:12:
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand_util.h:12:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/CPP/atomic.h:75:12: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
   75 |     return __scoped_atomic_load_n(&val, int(mem_ord), (int)(mem_scope));
      |            ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/CPP/atomic.h:109:12: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
  109 |     return __atomic_compare_exchange_n(&val, &expected, desired, false,
      |            ^
2 errors generated.
[367/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2.dir/exp2.cpp.obj
[368/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.scalbnl.dir/scalbnl.cpp.obj
[369/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.mempcpy.dir/mempcpy.cpp.obj
[370/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.index.dir/index.cpp.obj
[371/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.rindex.dir/rindex.cpp.obj
[372/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strchr.dir/strchr.cpp.obj
[373/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memchr.dir/memchr.cpp.obj
[374/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcpy.dir/strcpy.cpp.obj
[375/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.stpcpy.dir/stpcpy.cpp.obj
[376/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.stpncpy.dir/stpncpy.cpp.obj
[377/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.qsort.dir/qsort.cpp.obj
[378/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlen.dir/strlen.cpp.obj
[379/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strrchr.dir/strrchr.cpp.obj
[380/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.atoi.dir/atoi.cpp.obj
[381/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.atol.dir/atol.cpp.obj
[382/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strnlen.dir/strnlen.cpp.obj
Step 6 (build) failure: build (failure)
...
[353/1568] Building CXX object libc/src/stdfix/CMakeFiles/libc.src.stdfix.roundulk.dir/roundulk.cpp.obj
[354/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.asinf.dir/asinf.cpp.obj
[355/1568] Building CXX object libc/src/stdfix/CMakeFiles/libc.src.stdfix.uksqrtui.dir/uksqrtui.cpp.obj
[356/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.acosf.dir/acosf.cpp.obj
[357/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.bsearch.dir/bsearch.cpp.obj
[358/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.hypot.dir/hypot.cpp.obj
[359/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.div.dir/div.cpp.obj
[360/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.ldiv.dir/ldiv.cpp.obj
[361/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.lldiv.dir/lldiv.cpp.obj
[362/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj
FAILED: libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/bin/clang++ --target=armv6m-unknown-eabi -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/include/armv6m-unknown-eabi --target=armv6m-unknown-eabi -mthumb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/runtimes/runtimes-armv6m-unknown-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -O2 -g -DNDEBUG -std=gnu++17 --target=armv6m-unknown-eabi -fpie -DLIBC_FULL_BUILD -ffreestanding -ffixed-point -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 -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj -MF libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj.d -o libc/src/stdlib/CMakeFiles/libc.src.stdlib.srand.dir/srand.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/srand.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/srand.cpp:11:
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand_util.h:12:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/CPP/atomic.h:90:5: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
   90 |     __scoped_atomic_store_n(&val, rhs, int(mem_ord), (int)(mem_scope));
      |     ^
1 error generated.
[363/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strerror.dir/strerror.cpp.obj
[364/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strerror_r.dir/strerror_r.cpp.obj
[365/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.scalbn.dir/scalbn.cpp.obj
[366/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj
FAILED: libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/bin/clang++ --target=armv6m-unknown-eabi -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/include/armv6m-unknown-eabi --target=armv6m-unknown-eabi -mthumb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-8e4temoe/runtimes/runtimes-armv6m-unknown-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -O2 -g -DNDEBUG -std=gnu++17 --target=armv6m-unknown-eabi -fpie -DLIBC_FULL_BUILD -ffreestanding -ffixed-point -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 -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj -MF libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj.d -o libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand.dir/rand.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand.cpp:12:
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/rand_util.h:12:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/CPP/atomic.h:75:12: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
   75 |     return __scoped_atomic_load_n(&val, int(mem_ord), (int)(mem_scope));
      |            ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/CPP/atomic.h:109:12: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0  bytes) [-Werror,-Watomic-alignment]
  109 |     return __atomic_compare_exchange_n(&val, &expected, desired, false,
      |            ^
2 errors generated.
[367/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.exp2.dir/exp2.cpp.obj
[368/1568] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.scalbnl.dir/scalbnl.cpp.obj
[369/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.mempcpy.dir/mempcpy.cpp.obj
[370/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.index.dir/index.cpp.obj
[371/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.rindex.dir/rindex.cpp.obj
[372/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strchr.dir/strchr.cpp.obj
[373/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memchr.dir/memchr.cpp.obj
[374/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcpy.dir/strcpy.cpp.obj
[375/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.stpcpy.dir/stpcpy.cpp.obj
[376/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.stpncpy.dir/stpncpy.cpp.obj
[377/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.qsort.dir/qsort.cpp.obj
[378/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlen.dir/strlen.cpp.obj
[379/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strrchr.dir/strrchr.cpp.obj
[380/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.atoi.dir/atoi.cpp.obj
[381/1568] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.atol.dir/atol.cpp.obj
[382/1568] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strnlen.dir/strnlen.cpp.obj

```

https://github.com/llvm/llvm-project/pull/96692


More information about the libc-commits mailing list