I have an issue when trying to execute a c program using assembly code in it. The issue is only occuring with parrot, the program perfectly works when using an other operating system. When trying to use an extern asm function in my C code, i’m immediately getting a segfault for an unknown reason. So i’m wondering if the issue comes from me and my setup or is it a common issue with parrot? And if possible, how could I fix this.
Here is the code:
progC.c
#include <stdio.h>
#include <inttypes.h>
extern int64_t max2(int64_t a, int64_t b);
int main() {
int64_t i =10;
int64_t j =17;
printf("%ld\n",max2(i,j));
return(0);
}
Very interesting. I think the reason is the version of GCC that Parrot is using.
From GDB, program crashes when it goes to first line of function max2 (i edited to max in code)
Trying disas the function gave me error 'max' has unknown type; cast it to its declared type
It would be nice if any C / ASM guy can help you about this.
After googling and testing, here is the code that should work
The important part is .type fuma, @function that registers fumax (which should be max2, i edited function name again to make sure there is no same prebuilt function name) to be a C function
I figured out where was the problem using your code: the problem wasn’t because of he .type <name>, @function but because of the presence of the .data. I removed it and know it’s working. If you want to use a .data you should then specify the .text for your function etc…
The only strange things is that this error only occured with parrot for me, i tried on ubuntu and mint and it works.
Thanks you all for the help!
Oh nice! Good to know that. This is very first time i do this and i was just removing things and adding things.
It is very strange to me as well. In theory same binary (ofc if compiler generates same binaries from source code) must have same behaviors and same results.