【问题标题】:How to fix error "cannot run C compiled programs" when using ASAN使用 ASAN 时如何修复错误“无法运行 C 编译程序”
【发布时间】:2019-08-12 15:30:00
【问题描述】:

问题:运行configure 脚本工作正常,可以使用C 编译器并运行生成的程序。一旦添加了 ASAN,配置脚本就会抱怨生成的程序无法运行。

./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
...

对比

./configure CFLAGS="-fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fstack-protector" LDFLAGS="-fsanitize=undefined -fsanitize=address" --enable-debug
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether CFLAGS can be modified... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/tmp/test-asan':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

config.log 显示:

configure:3653: checking whether we are cross compiling
configure:3661: gcc -o conftest -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fstack-protector  -fsanitize=undefined -fsanitize=address conftest.c  >&5
configure:3665: $? = 0
configure:3672: ./conftest
==9941==LeakSanitizer has encountered a fatal error.
==9941==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==9941==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)
configure:3676: $? = 1
configure:3683: error: in `/tmp/test-asan':
configure:3685: error: cannot run C compiled programs.

【问题讨论】:

  • 您应该-lasan-lubsan 添加到LDFLAGS。它们是库,如果需要,应添加到 LIBS。但是,它们不是必需的。而是将-fsanitize=address -fsanitize=undefined 添加到LDFLAGS。编译器驱动程序将添加正确的库。

标签: linux configure ptrace address-sanitizer


【解决方案1】:

配置脚本的错误信息非常混乱(不涉及交叉编译),L​​eakSanitizer 的提示也好不到哪里去(我们不做任何调试)但包含一个重要提示:ptrace。

正如 GDB + ptrace question 中所暗示的,问题是 Yama kernel security module 被配置为阻止 ASAN 使用 ptrace。

在 valgrind 中运行时可以看到类似但更有用的消息:

调用 PR_SET_PTRACER 时出错,vgdb 可能会阻塞

要解决此问题:

  • 选项 1: 在评估的 shell 中运行配置脚本(和以后的测试) (sudo bash)
  • 选项 2(在本地/安全机器上 [可能是 VM/沙盒]): 允许所有人使用 ptrace
    echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

执行此操作时,配置脚本按预期运行,如果清理程序发现任何错误,生成的程序将在退出时中止。

【讨论】:

  • 提交问题以使 LSan 警告更具可读性可能是有意义的。
【解决方案2】:

我在使用“podman build”(“docker build”有效)时遇到了同样的问题。添加 ptrace 作为一项功能可能是可行的。但另一种解决方法是设置ASAN_OPTIONS=detect_leaks=0(在我的情况下是./configuremake test)。

【讨论】:

    猜你喜欢
    • 2015-11-03
    • 2019-11-14
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 2020-06-30
    • 2014-07-31
    • 2021-07-06
    相关资源
    最近更新 更多