<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 3, 2016 at 6:53 AM, Johan Engelen via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div>  I am trying to add ThinLTO to the LDC compiler. It seems to work well on Mac (XCode 8) and Ubuntu (ld.gold + LLVMgold plugin).</div><div>However, I am running into trouble with module-scope inline assembly blocks.</div></div></blockquote><div><br></div><div>Are you adding the support using the new LTO API or using the libLTO C interfaces?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>I have a module ASM with a function `foo` defined in an inline assembly block (and an LLVM IR `declare @foo()` for it). There is also a "normal" function `void simplefunction()` defined in the module.</div><div>```</div><div>module asm "\09.text"</div><div>module asm "\09.globl\09foo"</div><div>module asm "\09.align\0916, 0x90"</div><div>module asm "\09.type\09foo,@function"</div><div>module asm "foo:"</div><div>module asm "\09movq %rdi, %rax"</div><div>module asm "\09rorw $8, %ax"</div><div>module asm "\09ret "</div><div>module asm "\09.size\09foo, .-foo"</div><div>module asm ""</div><div><br></div><div>declare zeroext i16 @foo(i16 zeroext) #0</div><div><br></div><div>define i32 @_simplefunction() #1 {</div><div>  ret i32 1</div><div>}</div><div>```</div><div><br></div><div>Another module MAIN contains a function that calls ASM's `simplefunction()`.</div><div>```</div><div>define i32 @_Dmain({ i64, { i64, i8* }* } %unnamed) #0 {</div><div>  %1 = call i32 @_simplefunction() #1</div><div>  ret i32 %1</div><div>}</div><div>declare i32 @_simplefunction() #1</div><div>```</div><div><br></div><div>Then these two modules are passed to the linker, using ThinLTO, thus bitcode files with .o extension and module summaries added. The linker reports a multiple definition error for the inline assembly function.</div><div>(note that `foo` is not called anywhere)</div><div><br></div><div>I suspect that when ThinLTO decides to import a function from another module for inlining, the other module's module-scope assembly blocks are also imported, which later result in the multiple definition problems.</div><div><br></div><div>My question: is this known, intended, or otherwise broken on _my_ end? Or perhaps is it a bug and importing from modules with module-scope assembly should be disabled / should not import the module-scope asm?</div><div><br></div><div>(I can "fix" things on my end by disabling ThinLTO when there is a module-scope asm block, but perhaps there should be a proper fix in LLVM)</div></div></blockquote><div><br></div><div>I think this should just work, since module-level assembly is parsed when reading bitcode, and if the global foo is imported it should end up with available_externally linkage which would cause the def to be dropped if it wasn't inlined. Not sure what is going wrong.</div><div><br></div><div>Is there a save-temps option for the LDC linker that you could dump the IR after importing? With the new LTO API you can use the Config::addSaveTemps function to enable this. With the old LTO support used by libLTO there is an addSaveTempsDir on ThinLTOCodeGenerator, which looks like it can be set via thinlto_codegen_set_savetemps_dir.</div><div><br></div><div>Teresa</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Thanks!</div><div><br></div><div>Cheers,</div><div>  Johan</div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><span style="font-family:times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"> 408-460-2413</td></tr></tbody></table></span></div>
</div></div>