7

I've been trying to turn a bit of GNU extensions in to actual standard C so it'll run on clang, knowing standard C and not GNU extensions, I'm at a bit of a loss.

    __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););

I've tried to turn this in to actual asm, but have yet to be successful.

If you're curious, this is part of a kernel I've just about got to build on clang, besides that one section.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
stqism
  • 73
  • 1
  • 3
  • +1 for managing to produce such a thing, although I don't understand it and should probably add a -1 for lack of comments. – Potatoswatter Sep 18 '13 at 04:11
  • Don't blame me for this mess, it's part of the Linux kernel. – stqism Sep 18 '13 at 04:33
  • Oh. I have retagged it. By the way, this is not the domain of standard C. – Potatoswatter Sep 18 '13 at 05:03
  • Search for the function containing this block of assembly, and you will quickly find out messages (like [this one](http://lwn.net/Articles/429447/)) from the KML indicating the people responsible for this piece of code. Fire an email at them. Also, [read this](http://lwn.net/Articles/436041/). – DanielKO Sep 18 '13 at 05:41

1 Answers1

8

You seem to be having a problem compiling arch/x86/include/asm/jump_label.h. The entire code-snippet is to enable support for "jump label patching". A new feature quite useful to allow debugging(print logs etc.) with have near-zero overhead when debugging is disabled.

The implementation you encounter depends on gcc(v4.5) which adds a new asm goto statement that allows branching to a label.

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

As a quick fix to get your Linux kernel compiling properly, you can disable CONFIG_JUMP_LABEL in your kernel configuration. This config option is used to disable the optimisation when the compiler does NOT support asm goto properly.


Update: Initial support for asm goto was 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.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • While it won't help me directly fix the code, the fact that I can disable it entirely didn't even cross my mind. This is a pretty valid solution, thanks! – stqism Sep 18 '13 at 13:51
  • 2
    Asm goto support was merged into LLVM! https://www.phoronix.com/scan.php?page=news_item&px=LLVM-Asm-Goto-Merged :) – user464014 Jun 20 '19 at 18:35