On Sat, Nov 14, 2009 at 1:00 PM, <sudheer.divakaran@xxxxxxxxx> wrote: > 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 > > > > You have not used "ret" instruction in AsmFn2, I guess it will cause undefined behavior. I think it has nothing to do with how you compile the code. It works perfectly after adding ret instruction at the end of AsmFn2. Correct me if I am missing something here. -Vinit -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ