Skip to content

Commit f5d8b84

Browse files
committedJul 6, 2018
[OPENMP] Fix PR38026: Link -latomic when -fopenmp is used.
On Linux atomic constructs in OpenMP require libatomic library. Patch links libatomic when -fopenmp is used. llvm-svn: 336467
1 parent 71c7c43 commit f5d8b84

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed
 

‎clang/lib/Driver/ToolChains/Gnu.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
479479

480480
bool WantPthread = Args.hasArg(options::OPT_pthread) ||
481481
Args.hasArg(options::OPT_pthreads);
482+
bool WantAtomic = false;
482483

483484
// FIXME: Only pass GompNeedsRT = true for platforms with libgomp that
484485
// require librt. Most modern Linux platforms do, but some may not.
@@ -487,13 +488,16 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
487488
/* GompNeedsRT= */ true))
488489
// OpenMP runtimes implies pthreads when using the GNU toolchain.
489490
// FIXME: Does this really make sense for all GNU toolchains?
490-
WantPthread = true;
491+
WantAtomic = WantPthread = true;
491492

492493
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
493494

494495
if (WantPthread && !isAndroid)
495496
CmdArgs.push_back("-lpthread");
496497

498+
if (WantAtomic)
499+
CmdArgs.push_back("-latomic");
500+
497501
if (Args.hasArg(options::OPT_fsplit_stack))
498502
CmdArgs.push_back("--wrap=pthread_create");
499503

‎clang/test/OpenMP/linking.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// RUN: | FileCheck --check-prefix=CHECK-LD-32 %s
99
// CHECK-LD-32: "{{.*}}ld{{(.exe)?}}"
1010
// CHECK-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
11-
// CHECK-LD-32: "-lpthread" "-lc"
11+
// CHECK-LD-32: "-lpthread" "-latomic" "-lc"
1212
//
1313
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
1414
// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
1515
// RUN: | FileCheck --check-prefix=CHECK-LD-64 %s
1616
// CHECK-LD-64: "{{.*}}ld{{(.exe)?}}"
1717
// CHECK-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
18-
// CHECK-LD-64: "-lpthread" "-lc"
18+
// CHECK-LD-64: "-lpthread" "-latomic" "-lc"
1919
//
2020
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
2121
// RUN: -fopenmp=libgomp -target i386-unknown-linux -rtlib=platform \
@@ -27,7 +27,7 @@
2727
// SIMD-ONLY2-NOT: liomp
2828
// CHECK-GOMP-LD-32: "{{.*}}ld{{(.exe)?}}"
2929
// CHECK-GOMP-LD-32: "-lgomp" "-lrt"
30-
// CHECK-GOMP-LD-32: "-lpthread" "-lc"
30+
// CHECK-GOMP-LD-32: "-lpthread" "-latomic" "-lc"
3131

3232
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target i386-unknown-linux -rtlib=platform | FileCheck --check-prefix SIMD-ONLY2 %s
3333
// SIMD-ONLY2-NOT: lgomp
@@ -39,21 +39,21 @@
3939
// RUN: | FileCheck --check-prefix=CHECK-GOMP-LD-64 %s
4040
// CHECK-GOMP-LD-64: "{{.*}}ld{{(.exe)?}}"
4141
// CHECK-GOMP-LD-64: "-lgomp" "-lrt"
42-
// CHECK-GOMP-LD-64: "-lpthread" "-lc"
42+
// CHECK-GOMP-LD-64: "-lpthread" "-latomic" "-lc"
4343
//
4444
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
4545
// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
4646
// RUN: | FileCheck --check-prefix=CHECK-IOMP5-LD-32 %s
4747
// CHECK-IOMP5-LD-32: "{{.*}}ld{{(.exe)?}}"
4848
// CHECK-IOMP5-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
49-
// CHECK-IOMP5-LD-32: "-lpthread" "-lc"
49+
// CHECK-IOMP5-LD-32: "-lpthread" "-latomic" "-lc"
5050
//
5151
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
5252
// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
5353
// RUN: | FileCheck --check-prefix=CHECK-IOMP5-LD-64 %s
5454
// CHECK-IOMP5-LD-64: "{{.*}}ld{{(.exe)?}}"
5555
// CHECK-IOMP5-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]"
56-
// CHECK-IOMP5-LD-64: "-lpthread" "-lc"
56+
// CHECK-IOMP5-LD-64: "-lpthread" "-latomic" "-lc"
5757
//
5858
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
5959
// RUN: -fopenmp=lib -target i386-unknown-linux \
@@ -71,15 +71,15 @@
7171
// RUN: | FileCheck --check-prefix=CHECK-LD-OVERRIDE-32 %s
7272
// CHECK-LD-OVERRIDE-32: "{{.*}}ld{{(.exe)?}}"
7373
// CHECK-LD-OVERRIDE-32: "-lgomp" "-lrt"
74-
// CHECK-LD-OVERRIDE-32: "-lpthread" "-lc"
74+
// CHECK-LD-OVERRIDE-32: "-lpthread" "-latomic" "-lc"
7575
//
7676
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
7777
// RUN: -fopenmp -fopenmp=libgomp -target x86_64-unknown-linux \
7878
// RUN: -rtlib=platform \
7979
// RUN: | FileCheck --check-prefix=CHECK-LD-OVERRIDE-64 %s
8080
// CHECK-LD-OVERRIDE-64: "{{.*}}ld{{(.exe)?}}"
8181
// CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt"
82-
// CHECK-LD-OVERRIDE-64: "-lpthread" "-lc"
82+
// CHECK-LD-OVERRIDE-64: "-lpthread" "-latomic" "-lc"
8383
//
8484
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
8585
// RUN: -fopenmp=libomp -target x86_64-msvc-win32 -rtlib=platform \

0 commit comments

Comments
 (0)
Please sign in to comment.