【问题标题】:How to compile an executable using clang and safe-stack flag如何使用 clang 和安全堆栈标志编译可执行文件
【发布时间】:2016-02-10 18:36:36
【问题描述】:

我正在尝试使用带有 -fsanitize=safe-stack 标志的 clang-3.7(也尝试过 3.8 (dev))编译一个简单的 hello-world 可执行文件。正如这里 (http://clang.llvm.org/docs/SafeStack.html) 所解释的,我需要将此标志传递给编译器和链接器。

“要启用 SafeStack,只需将 -fsanitize=safe-stack 标志传递给编译和链接命令行。”

我尝试了以下命令来编译可执行文件:

clang-3.7 -fsanitize=safe-stack -o a.out -Wl,-fsanitize=safe-stack test.c

但是链接器告诉我,如果我将 -f 标志传递给链接器,我需要将其编译为共享库 (-shared)。

/usr/bin/ld: -f may not be used without -shared

如何使用 -fsanitize=safe-stack 标志编译可执行文件

【问题讨论】:

  • 你试过删除“-Wl,-fsanitize=safe-stack”吗?

标签: c linker clang llvm


【解决方案1】:

通过“将它传递给编译和链接命令行”,文档意味着在编译和链接时都传递它。这并不意味着使用-Wl,它将它直接传递给链接器 - -f 意味着与链接器完全无关的东西。

在这种情况下,

clang-3.7 -fsanitize=safe-stack -o a.out test.c

就足够了。如果您使用单独的命令执行来编译和链接,则需要将其传递给两者:

clang-3.7 -fsanitize=safe-stack -c -o test.o test.c
clang-3.7 -fsanitize=safe-stack -o a.out test.o

【讨论】:

    猜你喜欢
    • 2020-04-19
    • 1970-01-01
    • 2023-03-23
    • 2014-07-28
    • 2021-04-11
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 2011-03-02
    相关资源
    最近更新 更多