Hello. I am sending this at the behest of Renato. I have been working on the ARM integrated assembler in LLVM and came across an interesting item in the Linux kernel.
I am wondering if this is an unstated covenant between the kernel and GCC or simply a clever use of an unintended/undefined behaviour. The Linux kernel uses the *compiler* as a fancy preprocessor to generate a specially crafted assembly file. This file is then post-processed via sed to generate a header containing constants which is shared across assembly and C sources. In order to clarify the question, I am selecting a particular example and pulling out the relevant bits of the source code below. #define DEFINE(sym, val) asm volatile("\n->" #sym " %0 " #val : : "i" (val)) #define __NR_PAGEFLAGS 22 void definitions(void) { DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS); } This is then assembled to generate the following: ->NR_PAGEFLAGS #22 __NR_PAGEFLAGS This will later be post-processed to generate: #define NR_PAGELAGS 22 /* __NR_PAGEFLAGS */ By using the inline assembler to evaluate (constant) expressions into constant values and then emit that using a special identifier (->) is a fairly clever trick. This leads to my question: is this just use of an unintentional "feature" or something that was worked out between the two projects. Please explicitly CC me on any response as I am not subscribed to this mailing list. Thanks. -- Saleem Abdulrasool compnerd (at) compnerd (dot) org