7

So currently clang, msvc and the new llvm backed intel compiler do not support mixing c in a naked function.

Example

__declspec(naked) void func()
{
     int j;
     _asm(add j, 1) 
}

The compiler i've been using supports this, but it's been deprecated for a couple years now in favor a LLVM alternative. And I would like to swap to a newer version before compatibility issues arise.

Is there an alternative way to mix in c code with assembly, without an auto generated prolog/epilog? As my libraries I use are to large/complex to fully rewrite in pure assembly.

Edit: this relates to a naked function(one with no prolog or epilog) and compilers(MSVC, Clang, New Intel) no longer supporting c code mixed with asm IN the naked function. As the example above shows. This has nothing to do with adding assembly to a project as was suggested.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Infowarrior
  • 309
  • 1
  • 5
  • 1
    Keep using your compiler, and think of this as a lesson learned about compiler extensions; or pay now and properly separate the code. There is no magic bullet. – mevets Dec 02 '20 at 22:35
  • Does this answer your question? [external assembly file in visual studio](https://stackoverflow.com/questions/33751509/external-assembly-file-in-visual-studio) – hookenz Dec 02 '20 at 23:46
  • 1
    @Matt sadly no. This is related to naked functions (A function in C with no prolog or epilogue. Msvc supports this on x86 compilers. While on 64 doesnt, and also doesn’t do inline assembly. Clang supports inline asm and naked functions, but doesn’t support C code in a naked function, and forces it to be pure assembly. I currently use intels previous compiler, which is now deprecated in favor of llvm based. It supported naked functions with c code just like the old x86 compilers. I have tooling going back decades writing shellcode this way, without reverting to pure asm. So can’t rewrite. – Infowarrior Dec 03 '20 at 04:24
  • Out of curiosity, would inlining work here? – Macmade Dec 03 '20 at 05:47
  • 2
    If your code was designed for x86 naked functions and you now need to support x64 you've got a real problem. Calling conventions have changed, so if your code looks in the x86 places for parameters, the results will be a mess (even before you consider pointer lengths). The only way I know to combine C and asm inline is via [extended asm](https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html). It doesn't go in naked functions, but on the plus side, the functions can be inlined. Are you familiar? W/O a more complete example, I don't know how hard this might be, but it's all I've got to offer. – David Wohlferd Dec 03 '20 at 08:05

0 Answers0