Hi List,
Sorry for the off topic question. I think I have better chance of getting a solution from this list..
I was experimenting with x86 assembly under Linux, I have defined two functions (AsmFn1,AsmFn2) in a file named asm.s and my main function (c function) calls 'AsmFn1' & it calls AsmFn2 before returning.
Everything works fine if I use the c source as the first file while compiling
i.e.,
gcc -g -o good test.c asm.s
but, if I use the assembly file as the first file while compiling, when I execute the binary, it is giving SEGFAULT while invoking the Assembly function 'AsmFn1'.
i.e.,
gcc -g -o bad asm.s test.c
./bad will give segfault.
Why is it behaving like this? I'm using FC11 (32 bit) & the gcc comes along with it. I'm pasting the source files below..
asm.s
-----
.text
.globl AsmFn1
.type AsmFn1, @function
AsmFn1:
pushl %ebp
movl %esp, %ebp
call AsmFn2
leave
ret
.size AsmFn1, .-AsmFn1
.globl AsmFn2
.type AsmFn2,@function
AsmFn2:
pushl %ebp
movl %esp,%ebp
leave
.size AsmFn2,.-AsmFn2
test.c
------
extern void AsmFn1(void);
int main(void)
{
AsmFn1();
return 0;
}
TIA,
--
Sudheer
Attachment:
Makefile
Description: Makefile
Attachment:
asm.s
Description: asm.s
extern void AsmFn1(void); int main(void) { AsmFn1(); return 0; }