Originally posted by: huazh01
Hello world,
I have a client application written in C that runs on AIX 5.1. It connects to a server (server A) that runs on the same AIX machine. This application hits SEGV and hangs.
Problem goes away if the application is compiled with debug flag -g.
The 'truss' output shows:
sbrk(0x00001FF0) = 0x202EA010
Incurred fault #6, FLTBOUNDS address = 0xD2C2E490
Received signal #11, SIGSEGV
caught sigprocmask(1, 0x2FF20620, 0x00000000) = 0
sbrk(0x00000000) = 0x202EC000
Incurred fault #6, FLTBOUNDS address = 0xD2BF6AA4
Received signal #11, SIGSEGV
caught sigprocmask(1, 0x2FF1FCF0, 0x00000000) = 0
However, when I run the same application, i.e., same binary file, against another server (server B) on the same machine, everything runs fine. Both server A and B are compiled from same C source code.
I added some diagnostic code into the application. The bad run write some message into the output file, but the good run does not write anything into the output file.
I use 'dbx' to attach to the application, set break point in the function that outputs the message to output file, i.e., function_a, and let the application run. When it hits the break point, the stack shown by 'dbx' looks like:
function_a() <-- this is the function that write message to output file.
function_b()
....
main()
If I let the application continues to run under 'dbx', it will eventually hits a SIGSEGV on function_c().
According to the source code, function_b() do not call function_a(). I've also checked all macro in function_b() and I find none of them make a reference to funcation_a() as well.
flags used to compile source code .c file into .s file is:
xlc_r -c -S -qlanglvl=extc99 -qnoro -qhssngl -qchars=signed -qmaxmem=-1 -qcpluscmt -Q -D_BSD=43 -O
Look into the .s file, in the section for function_b(), I do see there exists instructions that branch into function_a:
__L56c: # 0x0000056c (H.10.NO_SYMBOL+0x56c)
l r3,0(r24)
cal r0,1(r5)
cal r4,64(SP)
cmpi 0,r3,0
bc BO_IF_NOT,CR0_EQ,__L680
cal r3,5(r0)
cmpi 0,r5,0
bc BO_IF_NOT,CR0_EQ,__L788
st r0,0(r31)
bl .function_b
l r4,64(SP)
rlinm r0,r3,24,0,7
srai. r0,r0,24
rlinm r6,r3,0,24,31
cal r0,5(r4)
cal r3,4(r31)
bc BO_IF,CR0_EQ,__L5d8
l r5,0(r22)
cmpl 0,r0,r5
bc BO_IF_NOT,CR0_GT,__L5d8
cal r3,240(r31)
bl .function_a{PR} <--- branch to function_a here
oril r0,r0,0x0000
cal r3,40(r31)
bl .function_a{PR} <--- branch to function_a here
oril r0,r0,0x0000
b __L5ec
Remove the "-O" flag from xlc_r will make it generate a .s file without instructions that branches to function_a from function_b.
Question:
a) why stacks shows function_b() calls function_a()? Could this be related to the SEGV seen in function_c() later?
b) why the assembly code generated with -O contains instructions that branch to function_a() from function_b()? Could this be a problem?
c) any suggestions on how to further diagnostic the problem is highly appreciated. As a reminder, problem goes away if the application is compiled with debug.
Thanks!!
#AIX-Forum