[LLVMdev] Problems of manipulating GEP for struct type

ChiaLun h3355626 at msn.com
Wed Oct 3 22:58:03 PDT 2012


Hi, 

I use JIT to execute the following LLVM IR,

------------------------------------------------------------------------------------------------------------
define internal fastcc i32 @L_00008120_(%struct.ThreadContext* %ThreadCtx) {
L_00000000_:
  %0 = alloca i32
  %1 = alloca i32
  %2 = alloca %struct.ThreadContext*, align 4
  store %struct.ThreadContext* %ThreadCtx, %struct.ThreadContext** %2
  call void @reach()
  br label %L_00008120_

L_00008120_:                                      ; preds = %L_00000000_
  call void @reach()
  %3 = load %struct.ThreadContext** %2, align 4
  call void @reach()
  %4 = getelementptr inbounds %struct.ThreadContext* %3, i32 0, i32 1
  call void @reach()
  %5 = getelementptr inbounds [32 x i32]* %4, i32 0, i32 2
  call void @reach()
*  store i32 33056, i32* %5*
  call void @reach()
  br label %L_00008120_1


.....

--------------------------------------------------------------------------------------------------


Somehow, the storeInst is not successfully performed, it gets

segmentation fault, I wonder if I miss something important.



I pinpoint the problems by inserting call void @reach(), before each
instructions,

the codes for function reach are

void reach()
{
  puts("press any key");
    getchar();
	puts("reach");
	fprintf(stderr,"reach stderr\n");
}

so I am almost sure that the segmentation fault is derived from storeInst.



the structure struct.ThreadContext in LLVM IR corresponds to C struct

struct ThreadContext
{
    int id;
    int r[32];


    void init();
    void setsp(int);
    void setpc(int);
};


The function prototype
typedef uint32_t (*func)(struct ThreadContext* );

func = jit->runJITOnFunction(...);

then execute the function by

func(&ctx); // ctx is defined to be " struct ThreadContext ctx;"



My execution result

press any key

reach
reach stderr
press any key

reach
reach stderr
press any key

reach
reach stderr
press any key

reach
reach stderr
press any key

reach
reach stderr
0  libDynTrans.so 0x013650b8
Stack dump:
0.	Program arguments: ./Release+Asserts/bin/translator
../testcase/print_arm2011 
Segmentation fault


If anyone can give a hint on the possible reason of segmentation fault, I
would be grateful.

Chia Lun





--
View this message in context: http://llvm.1065342.n5.nabble.com/Problems-of-manipulating-GEP-for-struct-type-tp49616.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.



More information about the llvm-dev mailing list