bluemoon wrote:1. you did not preserve registers.
Looking at my copy of the System V ABI (to which GCC adheres), and for AMD64, this would be all the GPRs other than rbp, rbx, and r12-r15?
bluemoon wrote:2. You gain nothing on the resulting binary, by putting the assembly stub within inline assembly.
Expected. It was kind of born of laziness anyway, with the admittedly flimsy excuse of source locality, rather than any machine-code benefit.
bluemoon wrote:3. You need to deal with non-trivial problems like optimization and non standard behaviours: you hijack a function to create another function, both the hosting function and inline asm block may get optimized away, or otherwise get hidden visibility
Even if a pointer to the function is used, in the kernel, as part of IDT initialization? I guess since GCC will probably notice it's not used directly in the source, that makes sense.
Also, for better or worse, and probably in a lot of places where it's not needed, I've been marking inline assembly blocks as volatile. From my reading of GCC's manual, it could still remove the block as unreachable, so I guess this is revealed as the hacky solution that it is.
bluemoon wrote:In short, you should just put the assembly stub in an assembly file.
Looks that way. Thanks for weighing in.