Last active
December 10, 2015 01:46
-
-
Save uliwitness/4cfde8cbb1a094c50c85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can specify the underlying name for a C function the linker/compiler should actually use. If you use an existing | |
function's name, it will just let you refer to it with your prototype's name. If you define the function, it'll give | |
it that name. It even complains if a function of that name already exists. Tested with clang on a Mac, but AFAIK also | |
works in GCC. You can even use special characters in your function names, like you can do in assembly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern int PrintIt(const char *format, ...) __asm("_printf"); | |
void MyFunc( int a ) __asm("foo$barMüller"); | |
void MyFunc( int a ) | |
{ | |
PrintIt("Yay %d\n", a); | |
} | |
int main() | |
{ | |
PrintIt("Hello, world!\n"); | |
MyFunc(5); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(__TEXT,__text) section | |
foo$barMüller: | |
0000000100000f00 pushq %rbp | |
0000000100000f01 movq %rsp, %rbp | |
0000000100000f04 subq $0x10, %rsp | |
0000000100000f08 leaq 0x73(%rip), %rax ## literal pool for: "Yay %d\n" | |
0000000100000f0f movl %edi, -0x4(%rbp) | |
0000000100000f12 movl -0x4(%rbp), %esi | |
0000000100000f15 movq %rax, %rdi | |
0000000100000f18 movb $0x0, %al | |
0000000100000f1a callq 0x100000f62 ## symbol stub for: _printf | |
0000000100000f1f movl %eax, -0x8(%rbp) | |
0000000100000f22 addq $0x10, %rsp | |
0000000100000f26 popq %rbp | |
0000000100000f27 retq | |
0000000100000f28 nopl (%rax,%rax) | |
_main: | |
0000000100000f30 pushq %rbp | |
0000000100000f31 movq %rsp, %rbp | |
0000000100000f34 subq $0x10, %rsp | |
0000000100000f38 leaq 0x4b(%rip), %rdi ## literal pool for: "Hello, world!\n" | |
0000000100000f3f movl $0x0, -0x4(%rbp) | |
0000000100000f46 movb $0x0, %al | |
0000000100000f48 callq 0x100000f62 ## symbol stub for: _printf | |
0000000100000f4d movl $0x5, %edi | |
0000000100000f52 movl %eax, -0x8(%rbp) | |
0000000100000f55 callq "foo$barMüller" | |
0000000100000f5a xorl %eax, %eax | |
0000000100000f5c addq $0x10, %rsp | |
0000000100000f60 popq %rbp | |
0000000100000f61 retq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, world! | |
Yay 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment