Contents of section my_section: 400890 c3666666 6666662e 0f1f8400 00000000 .ffffff......... 4008a0 38106000 00000000 b0064000 00000000 8.`....... at ..... 4008b0 d0064000 00000000 0f1f8400 00000000 .. at ............. 4008c0 38106000 00000000 d0064000 00000000 8.`....... at ..... 4008d0 30074000 00000000 0. at ..... This seems too big and doesn't make sense considering the IR. On Thu, Nov 24, 2011 at 3:44 AM, James Molloy <james.molloy at arm.com> wrote:> 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 > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111124/3b006eb3/attachment.html>