在具有不受支持的组件的目标上使用 -fsanitize 标志

The usage of -fsanitize flag on a target with unsupported components

使用 -fsanitize 编译时,是否必须使用它编译每个目标?

我有一些它不支持的目标(汇编和 C 目标)。

主要可执行文件是受支持的 C++ 文件。

fsanitize 会起作用吗?还是我需要删除不支持的文件?或者它会只使用用标志编译的部分吗?

文档告诉我们 -fsanitize 启用了 AddressSanitizer,为其主页提供了一个 link。这样,我们可以直接从 the FAQ:

得到答案

Q: I've built my main executable with ASan. Do I also need to build shared libraries?

A: ASan will work even if you rebuild just part of your program. But you'll have to rebuild all components to detect all errors.

虽然您不是在构建共享库,但此答案表明并非每个 link 编辑到您的可执行文件的对象都需要启用 AddressSanitizer。