[Openmp-commits] [PATCH] D59451: Fix gettid warnings and one test on FreeBSD

Dimitry Andric via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Mar 16 13:02:28 PDT 2019

dim added a comment.

In D59451#1432201 <https://reviews.llvm.org/D59451#1432201>, @protze.joachim wrote:

> This code does not directly use pthreads, but uses C++11 threads.
>  Why does the compiler not link the necessary threading library, when using C++11 threads?

How would the compiler know up-front what is in the code?  I have not often seen compilers that influence linking flags from the code that was compiled, unless maybe the Microsoft specific `#pragma lib` feature (which somebody is now adding to clang, I believe).  Usually, these kinds of flags are specified by the user, and passed from the frontend to the linker.

> I suggest to define a lit macro like `%cxx11_thread` which sets the necessary flags. I guess, that on Linux -fopenmp already implies linking the pthread library.

It seems so, there is this code in `clang/lib/Driver/ToolChains/Gnu.cpp`:

  // FIXME: Only pass GompNeedsRT = true for platforms with libgomp that
  // require librt. Most modern Linux platforms do, but some may not.
  if (addOpenMPRuntime(CmdArgs, ToolChain, Args,
                       /* GompNeedsRT= */ true))
    // OpenMP runtimes implies pthreads when using the GNU toolchain.
    // FIXME: Does this really make sense for all GNU toolchains?
    WantPthread = true;

IMHO this is a little magic, though. Then again, `-fopenmp` is rather magic anyway. :)

> Searching for other use of pthread in the tests, I found
>   ./tasking/bug_proxy_task_dep_waiting.c
>   ./tasking/bug_nested_proxy_task.c
>   ./misc_bugs/omp_foreign_thread_team_reuse.c
> These tests use -lpthread (should this also be replaced by -pthread?)

Probably best to use the same flags everywhere.

> Furthermore, one of them include omp_testsuite.h, which is supposed to provide a Windows compatible implementation of the pthread-create/join functions, but the testcase still links the pthread library. Does anyone actually run the tests on Windows?

I have no idea, it isn't clear to me where the test suite 'decides' which test cases are run for which operating system.

  rOMP OpenMP



More information about the Openmp-commits mailing list