Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support] Include Support/thread.h before api implementations #111175

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

fsfod
Copy link
Contributor

@fsfod fsfod commented Oct 4, 2024

This header was included after the implementations to work around an issue with FreeBSD, however, , this causes some issues when dllexport\explicit visibility
attributes will be added to the headers on Windows, since the definitions need to see the declarations for the attributes to apply.

This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on windows.

This header was included after the implementations to work around an
issue with FreeBSD, however, this causes some issues when dllexport\explicit visibility
attributes will be added to the headers on Windows, since the definitions need to see
the declarations for the attributes to apply.
This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on windows.
@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2024

@llvm/pr-subscribers-llvm-support

@llvm/pr-subscribers-platform-windows

Author: Thomas Fransham (fsfod)

Changes

This header was included after the implementations to work around an issue with FreeBSD, however, , this causes some issues when dllexport\explicit visibility
attributes will be added to the headers on Windows, since the definitions need to see the declarations for the attributes to apply.

This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on windows.


Full diff: https://github.com/llvm/llvm-project/pull/111175.diff

2 Files Affected:

  • (modified) llvm/lib/Support/Unix/Threading.inc (+8)
  • (modified) llvm/lib/Support/Windows/Threading.inc (+1)
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index a354984cabb1ef..ca855eb1160c73 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -33,6 +33,14 @@
 #include <pthread_np.h> // For pthread_getthreadid_np() / pthread_set_name_np()
 #endif
 
+
+// Must be included after Threading.inc to provide definition for llvm::thread
+// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
+// keyword.
+#ifndef __FreeBSD__
+#include "llvm/Support/thread.h"
+#endif
+
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include <errno.h>
 #include <sys/cpuset.h>
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 4baf8b8cb82aed..d862dbd7f71c9d 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/thread.h"
 
 #include "llvm/Support/Windows/WindowsSupport.h"
 #include <process.h>

Copy link

github-actions bot commented Oct 4, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@vgvassilev vgvassilev requested a review from compnerd October 6, 2024 10:57
// Must be included after Threading.inc to provide definition for llvm::thread
// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
// keyword.
#ifndef __FreeBSD__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just undef thread instead on FreeBSD. I think that we can just do this for now, it is more conservative.

@vgvassilev vgvassilev merged commit 9093ba9 into llvm:main Oct 10, 2024
9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 10, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux running on sanitizer-buildbot2 while building llvm at step 2 "annotate".

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

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[385/391] Generating Fuzzer-x86_64-Test
[386/391] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[387/391] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[388/391] Generating Msan-x86_64-with-call-Test
[389/391] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[390/391] Generating Msan-x86_64-Test
[390/391] Running compiler_rt regression tests
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 10346 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60
FAIL: SanitizerCommon-ubsan-i386-Linux :: Posix/create_thread_loop.cpp (6825 of 10346)
******************** TEST 'SanitizerCommon-ubsan-i386-Linux :: Posix/create_thread_loop.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=undefined  -m32 -funwind-tables  -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O3 -pthread /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp &&  /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp 1000
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=undefined -m32 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O3 -pthread /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp 1000
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==2073156==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0xee6f4bc0 (pc 0xf6f98182 bp 0xffc42e68 sp 0xffc42e40 T2073156)
==2073156==The signal is caused by a READ memory access.
    #0 0xf6f98182 in pthread_detach (/lib/i386-linux-gnu/libc.so.6+0x8e182) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b)
    #1 0x56d1f4f0 in main /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp:23:7
    #2 0xf6f2ecb8  (/lib/i386-linux-gnu/libc.so.6+0x24cb8) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b)
    #3 0xf6f2ed7b in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x24d7b) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b)
    #4 0x56ceea06 in _start (/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp+0x22a06)

==2073156==Register values:
eax = 0x00000000  ebx = 0x56d2480c  ecx = 0xffc42d98  edx = 0xee6f4b40  
edi = 0x56d1f548  esi = 0x000001d3  ebp = 0xffc42e68  esp = 0xffc42e40  
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV (/lib/i386-linux-gnu/libc.so.6+0x8e182) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b) in pthread_detach
==2073156==ABORTING

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
58.22s: libFuzzer-x86_64-default-Linux :: out-of-process-fuzz.test
55.89s: ThreadSanitizer-x86_64 :: bench_threads.cpp
54.56s: libFuzzer-x86_64-libcxx-Linux :: out-of-process-fuzz.test
48.28s: libFuzzer-i386-default-Linux :: fork.test
48.06s: libFuzzer-x86_64-static-libcxx-Linux :: out-of-process-fuzz.test
47.58s: libFuzzer-i386-static-libcxx-Linux :: fork_corpus_groups.test
47.23s: libFuzzer-i386-default-Linux :: fork_corpus_groups.test
46.72s: libFuzzer-i386-libcxx-Linux :: fork_corpus_groups.test
Step 14 (test compiler-rt default) failure: test compiler-rt default (failure)
...
[385/391] Generating Fuzzer-x86_64-Test
[386/391] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[387/391] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[388/391] Generating Msan-x86_64-with-call-Test
[389/391] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[390/391] Generating Msan-x86_64-Test
[390/391] Running compiler_rt regression tests
llvm-lit: /home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 10346 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60
FAIL: SanitizerCommon-ubsan-i386-Linux :: Posix/create_thread_loop.cpp (6825 of 10346)
******************** TEST 'SanitizerCommon-ubsan-i386-Linux :: Posix/create_thread_loop.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=undefined  -m32 -funwind-tables  -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O3 -pthread /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp &&  /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp 1000
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=undefined -m32 -funwind-tables -I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O3 -pthread /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp -o /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp 1000
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==2073156==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0xee6f4bc0 (pc 0xf6f98182 bp 0xffc42e68 sp 0xffc42e40 T2073156)
==2073156==The signal is caused by a READ memory access.
    #0 0xf6f98182 in pthread_detach (/lib/i386-linux-gnu/libc.so.6+0x8e182) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b)
    #1 0x56d1f4f0 in main /home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp:23:7
    #2 0xf6f2ecb8  (/lib/i386-linux-gnu/libc.so.6+0x24cb8) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b)
    #3 0xf6f2ed7b in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x24d7b) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b)
    #4 0x56ceea06 in _start (/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Posix/Output/create_thread_loop.cpp.tmp+0x22a06)

==2073156==Register values:
eax = 0x00000000  ebx = 0x56d2480c  ecx = 0xffc42d98  edx = 0xee6f4b40  
edi = 0x56d1f548  esi = 0x000001d3  ebp = 0xffc42e68  esp = 0xffc42e40  
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV (/lib/i386-linux-gnu/libc.so.6+0x8e182) (BuildId: ece90bd35626def53dbc8fa6ec5935e7e697fc8b) in pthread_detach
==2073156==ABORTING

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
58.22s: libFuzzer-x86_64-default-Linux :: out-of-process-fuzz.test
55.89s: ThreadSanitizer-x86_64 :: bench_threads.cpp
54.56s: libFuzzer-x86_64-libcxx-Linux :: out-of-process-fuzz.test
48.28s: libFuzzer-i386-default-Linux :: fork.test
48.06s: libFuzzer-x86_64-static-libcxx-Linux :: out-of-process-fuzz.test
47.58s: libFuzzer-i386-static-libcxx-Linux :: fork_corpus_groups.test
47.23s: libFuzzer-i386-default-Linux :: fork_corpus_groups.test
46.72s: libFuzzer-i386-libcxx-Linux :: fork_corpus_groups.test

@vgvassilev
Copy link
Contributor

Looks like the next build succeeded: https://lab.llvm.org/buildbot/#/builders/66/builds/4729

@fsfod fsfod deleted the exported-api/thread-include branch October 14, 2024 22:22
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
…11175)

This header was included after the implementations to work around an
issue with FreeBSD, however, , this causes some issues when
dllexport\explicit visibility
attributes will be added to the headers on Windows, since the
definitions need to see the declarations for the attributes to apply.

This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on
windows.

---------

Co-authored-by: Tom Stellard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants