[llvm-dev] ThinLTO promotion is ending up with "invalid" IR before IR-Linking

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 28 16:18:55 PST 2016


> On Dec 27, 2016, at 7:29 AM, Teresa Johnson <tejohnson at google.com> wrote:
> 
> 
> 
> On Fri, Dec 23, 2016 at 11:04 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
> 
>> On Dec 23, 2016, at 9:34 AM, Teresa Johnson <tejohnson at google.com <mailto:tejohnson at google.com>> wrote:
>> 
>> 
>> 
>> On Thu, Dec 22, 2016 at 8:55 PM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
>> Hey,
>> 
>> As I’m playing with Metadata lazy-loading, I added a verifier right before running the IRLinker in FunctionImport.cpp, and it does not pass (on current trunk) in a few cases. One that I looked at ended up with aliases pointing to available_externally functions for instance.
>> 
>> How do these look after IRLinking (in the dest module)? I looked at the logic in renameModuleForThinLTO and all the conversions to available_externally are predicated on it being in the provided GlobalsToImport set. But in FunctionImport.cpp selectCallee() we specifically prevent importing of aliases that would result in the aliasee becoming available_externally. Presumably the resulting IRLinked dest module looks legit, otherwise we would have later verifier failures.
> 
> So the source module is:
> 
> @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
> define void @globalfunc1() #0 {
> entry:
>   ret void
> }
> 
> But we turn globalfunc1 into available_externally in renameModuleForThinLTO(), which make the alias invalid.
> 
> We don’t import the IR so the destination module is OK.
> 
> Presumably we have decided to import globalfunc1 (otherwise renameModuleForThinLTO would not convert its linkage type), but not weakalias (since selectcallee should block it because aliases can't be imported unless the aliasee is linkonceodr). And the dest module is ok because we only import globalfunc1 and not weakalias. In that case, yes, I guess the source module can't be verified after doing renameModuleForThinLTO. Why not just verify before we do renameModuleForThinLTO, and then the dest module again after IR linking? Not sure it is worth verifying between those two points. 
> 
> Except that as noted in the follow-on emails, type ODRing which kicks in when the source module is loaded, will cause other issues.
> 
> Ah, see that you added the verification before renameModuleForThinLTO, then removed it again due to the typeODR issue.

Right, this was extremely annoying was bringing up the on-demand loading of metadata. Being able to validate the IR after loading is really important in this case.


>> I’m hesitant about breaking the IR verifier like that before calling the IRLinker. The alternative I can see now would be:
>> - to perform any handling that requires breaking the verifier as part of the IRLinker process,
>> - or to perform the verifier-breaking changes that we do as a pre-process step to the IRLinker as a post-process step on the linked module.
>> 
>> Wouldn't this second option result in verification errors on the resulting dest module?
> 
> Not sure why? Since currently the destination module is valid, the post-process should be OK as well?
> 
> I misunderstood what you were saying - you mentioned applying "verifier-breaking changes" as a post-process, but the key difference is that they are not verifier-breaking at that point.
> 
> I'm not sure it is worth making these changes, especially since there are other reasons (type ODR) that prevent verification until that point. 

I don’t have an immediate need / issue, but since it is not usual to manipulate “incorrect IR” in a pass or a transformation utility “by design", I figured I’ll bring up this issue.

— 
Mehdi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161228/8c26dc2f/attachment.html>


More information about the llvm-dev mailing list