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

    <tr>
        <th>Summary</th>
        <td>
            [UBSAN] Undefined references with `-Wl,--no-undefined`
        </td>
    </tr>

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

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

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

<pre>
    When linking a shared library with `-Wl,--no-undefined` switch and UBSAN enabled, the linking fails with unresolved references to UBSAN symbols.

Here's a test case:

`ubsan_unresolved_test.cpp`:

```
int test(int n)
{
    return n + 10;
}
```

Commands:

```
clang++ -stdlib=libc++ -fsanitize=undefined -fno-sanitize-recover=undefined -o ubsan_unresolved_test.o -c ubsan_unresolved_test.cpp
clang++ -stdlib=libc++ -fsanitize=undefined -fuse-ld=gold -Wl,--no-undefined -shared -o ubsan_unresolved_test.so ubsan_unresolved_test.o
```

Output:

```
ubsan_unresolved_test.o:ubsan_unresolved_test.cpp:function test(int): error: undefined reference to '__ubsan_handle_add_overflow_abort'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

clang version:

```
$ clang -v
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
```

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