Hi,
How large is the section? How large should it be? Can you post an objdump -r
of it?
Cheers,
James
-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
Behalf Of ret val
Sent: 24 November 2011 02:20
To: llvmdev at cs.uiuc.edu
Subject: [LLVMdev] differences in IR and ELF?
I'm trying to create a GlobalVariable that is a ConstantArray. Id like
each element to be a pointer to other things in the program(global
variables, functions). So that they all have the same type Id like to
make the elements void pointers.
I think I am going about this wrong, heres how I am doing it:
void writeArray(Module &M, GlobalVariable *shadow, Function *val,
Function *func) {
/* Build up contents */
vector<Constant *> v_elements;
Type *elm_type = Type::getInt32PtrTy(M.getContext());
Constant *tmp = dyn_cast<Constant>(shadow);
assert(tmp != NULL && "shadow");
v_elements.push_back(ConstantExpr::getBitCast(tmp,
elm_type));
tmp = dyn_cast<Constant>(val);
assert(tmp != NULL && "value");
v_elements.push_back(ConstantExpr::getBitCast(tmp,
elm_type));
tmp = dyn_cast<Constant>(func);
assert(tmp != NULL && "function");
v_elements.push_back(ConstantExpr::getBitCast(tmp,
elm_type));
/* Create array */
ArrayRef<Constant *> a_elements(v_elements);
ArrayType *type = ArrayType::get(elm_type, 3);
Constant *array = ConstantArray::get(type, a_elements);
/* Make new GlobalVariable from array */
GlobalVariable *global = new GlobalVariable(M, type, true,
my_linkage, array,
"my array");
global->setSection(*my_section);
}
The IR looks like this:
@"my array" = constant [3 x i32*] [i32* bitcast (i32 (i32)**
@"Shadow
Variable for ptr1" to i32*), i32* bitcast (i32 (i32)* @f2 to i32*),
i32* bitcast (i32 (i32)* @f1 to i32*)], section "my_section"
@"my array2" = constant [3 x i32*] [i32* bitcast (i32 (i32)**
@"Shadow
Variable for ptr1" to i32*), i32* bitcast (i32 (i32)* @f1 to i32*),
i32* bitcast (i32 ()* @main to i32*)], section "my_section"
The ELF section is too large. It does not look like padding, it looks
like more are being created and I don't know why.
_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev