<div dir="ltr"><div>Hello all</div><div><br></div><div>llvm-link merges together the metadata from the IR files being linked together. This means that when linking different libraries together (i.e. multiple source files that have been compiled into a single LLVM IR file) it can be hard or impossible to identify the library boundaries.</div><div><br></div><div>We're using LLVM to do static analysis of applications (together with their dependent libraries) and have found it useful to be able to determine which library a particular Instruction* or GlobalVariable* came from (e.g. so that we can ignore some of them, or focus analysis on particular ones).</div><div><br></div><div>To preserve this information across linking, I've implemented a new kind of metadata node MDLLVMModule that records:</div><div><br></div><div>1) Which LLVM modules (i.e. LLVM IR file) have been linked into this LLVM module</div><div>2) Which compilation units directly contribute to this LLVM module (i.e. that are not part of an LLVM submodule)</div><div><br></div><div>The format of the metadata looks like this:</div><div><br></div><div>!llvm.module = !{!0}</div><div><br></div><div>!0 = !MDLLVMModule(name: "test123.bc", modules: !1, cus: !24)</div><div>!1 = !{!2}</div><div>!2 = !MDLLVMModule(name: "test12.bc", cus: !3)</div><div>!3 = !{!4, !18}</div><div>!4 = !MDCompileUnit(... filename: "test1.c" ...)</div><div>!18 = !MDCompileUnit(... filename: "test2.c" ...)</div><div>!24 = !{!25}</div><div>!25 = !MDCompileUnit(... filename: "test3.c" ...)</div><div><br></div><div>Each linked LLVM module has the named metadata node "llvm.module" that points</div><div>to its own MDLLVMModule node. In this example, we see that this is the metadata</div><div>for llvm module "test123.bc" that is built up from linking module "test12.bc"</div><div>and the compilation unit "test3.c." Module "test12.bc" itself is built up by linking the compilation units "test1.c" and "test2.c"</div><div><br></div><div>The name of a module defaults to the base filename of the output file, but this can be overridden with the (also new) command-line flag -module-name to llvm-link, as in:</div><div><br></div><div>llvm-link -module-name=mytest -o test.bc <files></div><div><br></div><div>I thought this might be useful to the wider LLVM community and would like to see this added to LLVM. </div><div><br></div><div>I have attached a patch that I produced against r232466. I've also added a corresponding DILLVMModule class.</div><div><br></div><div>I would be very grateful if someone could review this.</div><div><br></div><div>Thanks</div><div><br></div><div><div><div dir="ltr"><div><div>--</div>Khilan Gudka</div><div><div>Research Associate</div><div>Security Group</div><div>Computer Laboratory<br></div><div><div>University of Cambridge</div></div><div><a href="http://www.cl.cam.ac.uk/~kg365/" target="_blank">http://www.cl.cam.ac.uk/~kg365/</a></div></div></div></div></div>
<div dir="ltr"><br></div></div>