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