[英]clang 32bit with address sanitizer with nix
我正在使用 nix 构建可重现的构建环境。 该代码是在 32 位模式下使用 clang-10 构建的。 此外,它与 ASAN 相关联。
clang a.c -m32 -fsanitize=leak
我在 shell.nix 中使用pkgsi686Linux.clang_10 package
那是我得到的错误:
/nix/store/4c4fy3hs558qm0ykif24f200d8mvcrkb-binutils-2.35.1/bin/ld: 找不到/nix/store/h4h6h98m32xcp18vcbd2mx5rfd34bmw1-clang-wrapper-10.0.1/resource-root/lib/linux/libclang_irt.lsan-:没有这样的文件或目录 clang-10: error: linker 命令失败,退出代码为 1(使用 -v 查看调用)
似乎找不到带有libclang_rt.lsan-i386.a 的 nix package 。 我该如何解决这个问题?
你坚持用clang 10吗? 使用更新的 clang 一切正常; 对于测试,只需使用-O0
禁用优化,否则不会出现泄漏(使用 12、13 和 14 进行测试,使用 clang 11 当我运行二进制文件时出现一些错误==517055==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
)。
为了演示,我在这里创建了一个薄片。
$ nix build 'git+https://gist.github.com/tobiasBora/0952c923d3cd892e41fbc3ef025ac020?ref=main#hello'
$ file ./result/bin/a.out
./result/bin/a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped
$ ./result/bin/a.out
Hello world
=================================================================
==548464==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x40c4f2 (/nix/store/3i0ipj0zwpjm8g1fslvfjb5dng4bd9s0--/bin/a.out+0x40c4f2)
#1 0x43b858 (/nix/store/3i0ipj0zwpjm8g1fslvfjb5dng4bd9s0--/bin/a.out+0x43b858)
#2 0x7f381db5624d (/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/libc.so.6+0x2924d) (BuildId: 2bb226bc600b443958c7566207d0d02f8345e6ea)
SUMMARY: LeakSanitizer: 7 byte(s) leaked in 1 allocation(s).
$ nix build 'git+https://gist.github.com/tobiasBora/0952c923d3cd892e41fbc3ef025ac020?ref=main#hello-32'
$ file ./result/bin/a.out
./result/bin/a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /nix/store/bzw74a7dla8iqk2h8wshwi03fbgj2c5h-glibc-2.35-163/lib/ld-linux.so.2, for GNU/Linux 2.6.32, not stripped
$ ./result/bin/a.out
Hello world
=================================================================
==554039==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x8055779 (/nix/store/yh4klla6n8c9flgcxd7r05zj705kycdl--/bin/a.out+0x8055779)
#1 0x8094238 (/nix/store/yh4klla6n8c9flgcxd7r05zj705kycdl--/bin/a.out+0x8094238)
#2 0xf7c102f9 (/nix/store/bzw74a7dla8iqk2h8wshwi03fbgj2c5h-glibc-2.35-163/lib/libc.so.6+0x212f9) (BuildId: 0fc69f6f66391d65b1e33788a951319bda8ba1d4)
SUMMARY: LeakSanitizer: 7 byte(s) leaked in 1 allocation(s).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.