llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.97k stars 11.94k forks source link

Undefined symbol when -polly-parallel is enabled #37841

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 38493
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @Meinersbur

Extended Description

When automatic parallelization using polly is applied, a linker outputs an error: undefined symbol: GOMP_*.

-------- test.c --------

include

include

define N 300

define M 4

double a[N][M]; double b[N][M]; double c[N][M];

void foo(int m) { int i,j; for (j=0; j<N; ++j) { for (i=0; i<m; ++i) { a[j][i] += b[j][i]*c[j][i]; } } }

double suma(void) { int i,j; double s; s = 0.0; for (j=0; j<N; ++j) { for (i=0; i<M; ++i) { s += a[j][i]; } } return s; }

define ANS (double)300.0000

define GOSA (double)0.0

int main(void) { int i,j; double s; for (j=0; j<N; ++j) { for (i=0; i<M; ++i) { a[j][i] = 0.0; b[j][i] = 0.5; c[j][i] = 0.5; } } foo(M); s = suma(); if (fabs(s - ANS) <= GOSA) { printf("ok\n"); } else { printf("ng: %lf != %lf\n", s, ANS); } }

$ clang --version clang version 8.0.0 (trunk 339303) Target: x86_64-unknown-linux-gnu

$ clang -O3 -mllvm -polly -mllvm -polly-parallel test.c ld: error: undefined symbol: GOMP_parallel_loop_runtime_start

referenced by 3-P-275_01.c /home/takahiro/tmp/3-P-275_01-0c2466.o:(foo)

ld: error: undefined symbol: GOMP_parallel_end

referenced by 3-P-275_01.c /home/takahiro/tmp/3-P-275_01-0c2466.o:(foo)

ld: error: undefined symbol: GOMP_loop_runtime_next

referenced by 3-P-275_01.c /home/takahiro/tmp/3-P-275_01-0c2466.o:(foo_polly_subfn)

ld: error: undefined symbol: GOMP_loop_runtime_next

referenced by 3-P-275_01.c /home/takahiro/tmp/3-P-275_01-0c2466.o:(foo_polly_subfn)

ld: error: undefined symbol: GOMP_loop_end_nowait

referenced by 3-P-275_01.c /home/takahiro/tmp/3-P-275_01-0c2466.o:(foo_polly_subfn)

But, If I added -fopenmp option to the above options, the linker didn't output the error and compilation succeeded. So, when -polly-parallel option is specified, should I need to specify -fopenmp option? Or, should clang pass "-lomp" to the linker implicitly?

Meinersbur commented 6 years ago

The only possible fix would be to add a compiler flags such as -fpolly-parallel to clang that would add -mllvm -polly -mllvm -polly-parallel as well as an OpenMP runtime.

Meinersbur commented 6 years ago

clang, the driver component of the frontend, does not know that Polly is generating calls to an external library. Hence, some command line argument has to be passed to tell the driver to pass the OpenMP runtime library to the linker. -fopenmp, -lgomp or -fomp should do.