<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div>Hi</div>
<div>Good day. I am facing issue with creating a GlobalVariable. I already have an extern for that global in a header file to use it in the following way</div>
<code>
<pre style="background-color:rgba(0,0,0,0.05);padding:0.2em 1em">extern const void* DATA_TABLE[];</pre>
</code>
<div>And with a LLVM PASS, I am trying to create this array with the same name and with initializer. So, I have following:</div>
<code>
<pre style="background-color:rgba(0,0,0,0.05);padding:0.2em 1em"><div><code><span style="color:rgb(51, 51, 51)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(170, 170, 170)">GlobalVariable *gvar_data = new GlobalVariable(</span></font></span></code></div><div><code><span style="color:rgb(51, 51, 51)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(170, 170, 170)">    M, blockItems->getType(), true, GlobalValue::CommonLinkage,</span></font></span></code></div><div><code><span style="color:rgb(51, 51, 51)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(170, 170, 170)">    blockItems, "DATA_TABLE");</span></font></span></code></div><div><code><span style="color:rgb(51, 51, 51)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(170, 170, 170)">gvar_data->setAlignment(16);</span></font></span></code></div><div><code><span style="color:rgb(51, 51, 51)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(170, 170, 170)">gvar_data->setSection("data_section");</span></font></span></code></div><div><code><span style="color:rgb(51, 51, 51)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(170, 170, 170)">gvar_data->addAttribute(llvm::Attribute::OptimizeNone);</span></font></span></code></div></pre>
</code>
<div><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><code>I am not sure if I am using the correct Linkage or not.</code></font></div>
<div>The pass has failed to complete it. Here is the runtime fault. Any guess what I am doing incorrect?</div>
<code>
<pre style="background-color:rgba(0,0,0,0.05);padding:0.2em 1em"><span data-emoji-typing="true">'common' global must have a zero initializer!</span><br><span data-emoji-typing="true">[10 x i8*]* @</span>DATA<span data-emoji-typing="true">_TABLE.1</span><br><span data-emoji-typing="true">LLVM ERROR: Broken module found, compilation aborted</span><span data-emoji-typing="true">::::::::</span><span data-emoji-typing="true"><span data-emoji-typing="true">:!</span></span></pre>
</code>
</body>
</html>