<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57288>57288</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [compiler-rt] TSAN Dynamic Library Linker Error on Ubuntu
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          lstricevic
      </td>
    </tr>
</table>

<pre>
    When compiling this piece of code with dynamically linked ThreadSanitizer runtime library, linking error occurs:
```
#include <stdio.h>
#include <pthread.h>

int x=0;

void* fun(void* in) {
    for (int i = 0; i < 10000000; i++ ) 
        x++;
    return NULL;
}

int main(){
    pthread_t t1, t2;
    pthread_create(&t1, NULL, fun, NULL);
    pthread_create(&t2, NULL, fun, NULL);
    pthread_join(t1, NULL);
    pthread_join(t2, NULL);

    printf("X: %d\n", x);
    return 0;
}
```
Compiling with:

`clang -fsanitize=thread -shared-libsan -lpthread race.c`

gives linker error:
```
/usr/bin/ld: /opt/src/llvm-project/build-2108/lib/clang/16.0.0/lib/x86_64-unknown-linux-gnu/libclang_rt.tsan.so: siglongjmp: invalid version 21 (max 0)
/opt/src/llvm-project/build-2108/lib/clang/16.0.0/lib/x86_64-unknown-linux-gnu/libclang_rt.tsan.so: error adding symbols: Bad value
```
Affected versions of LLVM are 14.x, 15.x and current (commit d9756fa723be). Error can be also reproduced with binary release: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz

The tests have been made on x86_64 Ubuntu 18.04 and 20.04 versions.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVcuSmzoQ_Rq86YISwmC88MKPzMrJJpOb7KYEEkYTIVyS8Nj5-tsS2OPJnZtUVqEogdSv00etVtXzy-prKzTUfXeUSuoDuFZaOEpRC-gbXOcCXqRr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