Files
termux-packages/packages/libllvm/clang-lib-Driver-ToolChains-Linux.cpp.patch
termux-pacman-bot 9b1d8bc03e fix(main/clang): default to using the static library of the address sanitizer instead of the shared library
- Makes the default behavior of on-device building with the address sanitizer match the default behavior of building with the address sanitizer on Clang for Desktop Linux distros, which is to use the static library

- Fixes https://github.com/termux/termux-packages/issues/26485

- On devices that do not have `libclang_rt.asan-$arch-android.so` or which have a corrupted one, fixes building on-device with `-fsanitize=address`

- Samsung Galaxy S III SPH-L710 with LineageOS 14.1 Android 7.1.2 before:

```
~ $ clang test.c -fsanitize=address
~ $ ./a.out
WARNING: linker: /data/data/com.termux/files/home/a.out: unsupported flags DT_FLAGS_1=0x8000001
CANNOT LINK EXECUTABLE "./a.out": library "libclang_rt.asan-arm-android.so" not found
Aborted                    ./a.out
~ $ clang test.c -fsanitize=address -Wl,-rpath=$PREFIX/lib/clang/20/lib/linux
~ $ ./a.out
WARNING: linker: /data/data/com.termux/files/home/a.out: unsupported flags DT_FLAGS_1=0x8000001
~ $ termux-elf-cleaner ./a.out
termux-elf-cleaner: Replacing unsupported DF_1_* flags 134217729 with 1 in './a.out'
~ $ ./a.out
~ $ file /system/lib/libclang_rt.asan-arm-android.so
/system/lib/libclang_rt.asan-arm-android.so: cannot open `/system/lib/libclang_rt.asan-arm-android.so' (No such file or directory)
~ $
```

- After:
```
~ $ clang test.c -fsanitize=address
~ $ ./a.out
WARNING: linker: /data/data/com.termux/files/home/a.out: unsupported flags DT_FLAGS_1=0x8000001
~ $ termux-elf-cleaner a.out
termux-elf-cleaner: Replacing unsupported DF_1_* flags 134217729 with 1 in 'a.out'
~ $ ./a.out
~ $
```

- Vivo iQOO Neo8 V2301A with Android 15 before:

```
thread #1, name = 'a.out', stop reason = signal SIGILL: illegal opcode
```

- After: believed to work
2025-10-13 15:06:11 +00:00

44 lines
1.9 KiB
Diff

--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -162,8 +162,8 @@
// FIXME: This is a bit of a hack. We should really unify this code for
// reasoning about oslibdir spellings with the lib dir spellings in the
// GCCInstallationDetector, but that is a more significant refactoring.
- if (Triple.getArch() == llvm::Triple::x86 || Triple.isPPC32() ||
- Triple.getArch() == llvm::Triple::sparc)
+ if (!Triple.isAndroid() && (Triple.getArch() == llvm::Triple::x86 || Triple.isPPC32() ||
+ Triple.getArch() == llvm::Triple::sparc))
return "lib32";
if (Triple.getArch() == llvm::Triple::x86_64 && Triple.isX32())
@@ -287,6 +287,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
}
addPathIfExists(D, concat(SysRoot, "/usr/lib", MultiarchTriple), Paths);
+ if (!IsAndroid)
addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir), Paths);
if (IsRISCV) {
StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
@@ -311,7 +311,20 @@
addPathIfExists(D, D.Dir + "/../lib", Paths);
addPathIfExists(D, concat(SysRoot, "/lib"), Paths);
- addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
+ bool nativeBuild = MultiarchTriple == getMultiarchTriple(D, llvm::Triple(llvm::sys::getDefaultTargetTriple()), SysRoot);
+ if (nativeBuild || !IsAndroid)
+ addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
+
+ if (IsAndroid) {
+ addPathIfExists(D, concat(SysRoot, "/usr/", MultiarchTriple, "/lib"), Paths);
+ addPathIfExists(D, concat("/system/", OSLibDir), Paths);
+ if (Args.hasFlag(options::OPT_ftermux_rpath, options::OPT_fno_termux_rpath, true)) {
+ if (nativeBuild)
+ ExtraOpts.push_back("-rpath=" + SysRoot + "/usr/lib");
+ else
+ ExtraOpts.push_back("-rpath=" + SysRoot + "/usr/" + MultiarchTriple + "/lib");
+ }
+ }
}
ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const {