llvm / llvm/llvm-project

[compiler-rt][tysan] libclang_rt.tysan.so Not Produced on Linux, Making -shared-libsan Unusable with TypeSanitizer

Open
#200,683 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt:tysan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

# [compiler-rt][tysan] `libclang_rt.tysan.so` Not Produced on Linux, Making `-shared-libsan` Unusable with TypeSanitizer

## Summary

`compiler-rt/lib/tysan/CMakeLists.txt` produces a shared runtime library (`SHARED`) only on Apple platforms. On Linux and other non-Apple platforms, only a static archive is generated.

As a result, the `-shared-libsan` linker flag does not work for TypeSanitizer on Linux, unlike other sanitizers in `compiler-rt`, which provide both shared and static runtime libraries.

---

## Current Behavior

`compiler-rt/lib/tysan/CMakeLists.txt` contains the following platform-specific logic:

```cmake
if(APPLE)
add_compiler_rt_runtime(clang_rt.tysan
SHARED
...
)

add_compiler_rt_runtime(clang_rt.tysan_static
STATIC
...
)
else()
foreach(arch ${TYSAN_SUPPORTED_ARCH})
add_compiler_rt_runtime(clang_rt.tysan
STATIC
...
)
endforeach()
endif()
```

On non-Apple platforms, only the static runtime is built.

Passing `-shared-libsan` during linking then fails with:

```text
ld.lld: error: cannot open .../libclang_rt.tysan.so: No such file or directory
clang++: error: linker command failed with exit code 1
```

---

## Expected Behavior

`libclang_rt.tysan.so` should be produced on Linux, consistent with AddressSanitizer (ASan), ThreadSanitizer (TSan), and UndefinedBehaviorSanitizer (UBSan), all of which provide both shared and static runtime libraries on Linux.

---

## Impact

The `-shared-libsan` option is unusable with `-fsanitize=type` on Linux because no shared TypeSanitizer runtime is generated.

As a result, users are effectively limited to static linking of the TypeSanitizer runtime.

---

## Suggested Fix

The `RTTysan_dynamic` object library is already built unconditionally near the top of `CMakeLists.txt` for all supported operating systems and architectures.

The only missing piece appears to be a corresponding `SHARED` `add_compiler_rt_runtime()` invocation in the `else()` branch, similar to the implementation used by ASan in:

```text
compiler-rt/lib/asan/CMakeLists.txt
```

Adding a shared runtime target for non-Apple platforms would make TypeSanitizer consistent with the behavior of other sanitizers and enable proper support for the `-shared-libsan` linker option on Linux.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.