flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Does fasm support inlining of C "static inline" fu |
Author |
|
HaHaAnonymous 27 Jul 2016, 16:25
I think function inline is compiler thing, it will just do some "tricks" and incorporate "add3" to your code, without calling it.
The only way I can think of inlining functions in FASM is by using macros. Or repeat each code you need, manually. |
|||
27 Jul 2016, 16:25 |
|
revolution 27 Jul 2016, 20:42
fasm can create an object file for linking with other objects. That's probably about as close as you will get with having some external code inlined with any C compiler. For inlining to work the compiler has to know the code, and it can't know anything from just the object file.
|
|||
27 Jul 2016, 20:42 |
|
redsock 27 Jul 2016, 23:19
I'll chime in here, despite your test inlined.{c,h} not really making a lot of sense to me.
I think what you are really looking for is this: http://gcc.gnu.org/wiki/LinkTimeOptimization. Way back in the olden days, the MIPSPro compiler team did a fantastic job with inter-procedural optimizations, and now most compilers do similarly. The gcc options -fwhole-program and -flto are the meaty bits. This is to say that I can create a fasm-generated .o file with exported public symbols, and include them in a C/C++ project. If I then use link time optimization, gcc will do its best to optimize even fasm-produced code samples. Whether it eliminates calls and chooses inlining or not is very much compiler-specific. |
|||
27 Jul 2016, 23:19 |
|
Libby 28 Jul 2016, 06:45
thankyou very much everyone for feedback so far!
redsock, I want to go the other way though - I dont want to create a fasm .o and call from gcc ... I want to call my gcc-created .o from fasm, and hopefully have fasm inline the calls that i've declared to be "static inline" in the C source |
|||
28 Jul 2016, 06:45 |
|
Trinitek 28 Jul 2016, 08:19
Oh, I had a hard time understanding your posts. You want GCC to export functions that don't have the stack setup/cleanup/return so you can use them in FASM as if they were FASM macros.
|
|||
28 Jul 2016, 08:19 |
|
redsock 28 Jul 2016, 21:44
Libby wrote: redsock, I want to go the other way though - I dont want to create a fasm .o and call from gcc ... I want to call my gcc-created .o from fasm, and hopefully have fasm inline the calls that i've declared to be "static inline" in the C source To demonstrate this effect, I too created a source file: Code: #include <cstdio> #include <cstdlib> static inline unsigned long int add3(unsigned long int dword1) { return dword1 + 3; } void export_function() { printf("%ld\n", add3(rand())); } Code: Disassembly of section .text: 0000000000000000 <_Z15export_functionv>: 0: 48 83 ec 08 sub rsp,0x8 4: e8 00 00 00 00 call 9 <_Z15export_functionv+0x9> 5: R_X86_64_PC32 rand-0x4 9: 48 63 f0 movsxd rsi,eax c: 48 83 c6 03 add rsi,0x3 10: bf 00 00 00 00 mov edi,0x0 11: R_X86_64_32 .rodata.str1.1 15: b8 00 00 00 00 mov eax,0x0 1a: e8 00 00 00 00 call 1f <_Z15export_functionv+0x1f> 1b: R_X86_64_PC32 printf-0x4 1f: 48 83 c4 08 add rsp,0x8 23: c3 ret Code: Disassembly of section .text: 0000000000000000 <_ZL4add3m>: 0: 55 push rbp 1: 48 89 e5 mov rbp,rsp 4: 48 89 7d f8 mov QWORD PTR [rbp-0x8],rdi 8: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8] c: 48 83 c0 03 add rax,0x3 10: 5d pop rbp 11: c3 ret 0000000000000012 <_Z15export_functionv>: 12: 55 push rbp 13: 48 89 e5 mov rbp,rsp 16: e8 00 00 00 00 call 1b <_Z15export_functionv+0x9> 17: R_X86_64_PC32 rand-0x4 1b: 48 98 cdqe 1d: 48 89 c7 mov rdi,rax 20: e8 db ff ff ff call 0 <_ZL4add3m> 25: 48 89 c6 mov rsi,rax 28: bf 00 00 00 00 mov edi,0x0 29: R_X86_64_32 .rodata 2d: b8 00 00 00 00 mov eax,0x0 32: e8 00 00 00 00 call 37 <_Z15export_functionv+0x25> 33: R_X86_64_PC32 printf-0x4 37: 5d pop rbp 38: c3 ret The only way fasm (or any external lang) could detect your "static inline" keywords is if it were also a C/C++ compiler, and that doesn't make any sense IMO. The above objdump code hopefully highlights the issue with what you are after. |
|||
28 Jul 2016, 21:44 |
|
Libby 29 Jul 2016, 07:35
well that's disappointing, but understandable. Thankyou very much for the detailed explanation, very much appreciated!!!
|
|||
29 Jul 2016, 07:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.