LINUX KERNEL
Two patches queued into the Linux kernel’s build system development tree, kbuild-next, would enable the -fms-extensions compiler argument everywhere for allowing GCC and LLVM/Clang to use the Microsoft C Extensions when compiling the Linux kernel. Being in kbuild-next these patches will likely be submitted for the Linux 6.19 kernel merge window next month but remains to be seen if there will be any last minute objections to this change.

The -fms-extensions compiler option honored by the GNU Compiler Collection and LLVM/Clang allow enabling some non-standard C/C++ constructs used within Microsoft header files and honored by the the Microsoft Visual C/C++ compiler. For Linux kernel development purposes, enabling the Microsoft C Extensions would allow including a tagged struct or union anonymously in another struct/union.

Going back many years there have been patches floated to unconditionally enable -fms-extensions for the Linux kernel but they haven’t made it past the Linux kernel mailing list. But now with these two patches being in kbuild-next mean that it will likely be submitted for the Linux 6.19 kernel merge window barring any objections from prominent Linux kernel developers or Linus Torvalds himself.

Rasmus Villemoes argued with Kbuild: enable -fms-extensions that would allow for “prettier code” and others have noted in the past the potential for saving stack space and all around being beneficial in being able to leverage the Microsoft C behavior:

“Once in a while, it turns out that enabling -fms-extensions could allow some slightly prettier code. But every time it has come up, the code that had to be used instead has been deemed “not too awful” and not worth introducing another compiler flag for.

That’s probably true for each individual case, but then it’s somewhat of a chicken/egg situation.

If we just “bite the bullet” as Linus says and enable it once and for all, it is available whenever a use case turns up, and no individual case has to justify it.

A lore.kernel.org search provides these examples:

– https://lore.kernel.org/lkml/[email protected]/

– https://lore.kernel.org/lkml/[email protected]/

– https://lore.kernel.org/lkml/[email protected]/

– https://lore.kernel.org/lkml/[email protected]/

– https://lore.kernel.org/lkml/CAHk-=wjeZwww6Zswn6F_iZTpUihTSNKYppLqj36iQDDhfntuEw@mail.gmail.com/

Undoubtedly, there are more places in the code where this could also be used but where -fms-extensions just didn’t come up in any discussion.”

The second patch is kbuild: Add ‘-fms-extensions’ to areas with dedicated CFLAGS to ensure -fms-extensions is passed for the CPU architectures that rely on their own CFLAGS being set rather than the main KBUILD_CFLAGS.

Linus Torvalds chimed in on the prior mailing list discussion and doesn’t appear to be against enabling -fms-extensions beginning with the Linux 6.19 kernel.

Linux MS C

Enabling -fms-extensions will allow for some better looking C code though some may feel the wrong way around Microsoft C behavior being permitted for the mainline Linux kernel coding.