c - 尝试将 GCC 特定的 asm goto 移植到 Clang

标签 c linux gcc linux-kernel clang

我一直在尝试将一些 GNU 扩展转换为实际的标准 C,以便它可以在 clang 上运行,知道标准 C 而不是 GNU 扩展,我有点不知所措。

    __asm__ (goto("1:"
            STATIC_KEY_INITIAL_NOP
            ".pushsection __jump_table,  \"aw\" \n\t"
            _ASM_ALIGN "\n\t"
            _ASM_PTR "1b, %l[l_yes], %c0 \n\t"
            ".popsection \n\t"
            : :  "i" (key) : : l_yes););

我试图将其转化为实际的 asm,但尚未成功。

如果您好奇的话,除了那一部分之外,这是我即将在 clang 上构建的内核的一部分。

最佳答案

您似乎在编译 arch/x86/include/asm/jump_label.h 时遇到问题.整个代码片段是为了启用对“跳跃标签修补”的支持。一项非常有用的新功能,允许调试(打印日志等),在禁用调试时开销几乎为零。

你遇到的实现 depends on gcc(v4.5) which adds a new asm goto statement允许分支到标签。

It appears that Clang/LLVM < 9.0.0 does NOT support asm goto.

作为让 Linux 内核正确编译的快速修复,您可以在内核配置中禁用 CONFIG_JUMP_LABEL。当编译器不正确支持 asm goto 时,此配置选项用于禁用优化。


更新:对asm goto 的初始支持是added to Clang in v9.0.0 .

Initial support for asm goto statements (a GNU C extension) has been added for control flow from inline assembly to labels. The main consumers of this construct are the Linux kernel (CONFIG_JUMP_LABEL=y) and glib. There are still a few unsupported corner cases in Clang's integrated assembler and IfConverter. Please file bugs for any issues you run into.

关于c - 尝试将 GCC 特定的 asm goto 移植到 Clang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863363/

相关文章:

c - C 中的父子进程通过公共(public)文件进行通信

c++ - ld: 未找到体系结构 x86_64 行::AddColumn 的符号

c - C 标准库中的头文件可以包含另一个头文件吗?

c - 如何将 <mhash.h> 添加到我的 C 项目中

linux - 在cshrc中执行别名

linux - bash 脚本中的 [...] 代表什么?

c - 阅读双倍时的 scanf 问题

c - 错误 : no include path in which to search for stdio. h

c - 如何在单个CPU的多个CPU核心而不是多个CPU上设置亲和性?

c - 关于Linux fork的问题