gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:49:46 30 4
gpt4 key购买 nike

我一直在尝试将一些 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com