<div dir="ltr">Oh, you are right. My mistake, I expected that findBaseObject is called on `this` so first hope and other work the same. It would be a good thing to do anyway because it will help to detect loops earlier and make getBaseObject consistent.<br><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 10, 2020 at 9:49 PM Itay Bookstein <<a href="mailto:itay.bookstein@nextsilicon.com">itay.bookstein@nextsilicon.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> I still don't understand how it can happen looking to the code (<a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Globals.cpp#L430" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Globals.cpp#L430</a>). I believe it should return nullptr (the same as if you call it from GlobalAlias that refers to GlobalIFunc).<br>
<br>
That is because that's findBaseObject(), not getBaseObject(): if you<br>
call getBaseObject() on a GlobalIFunc you'll get the<br>
GlobalIndirectSymbol::getBaseObject() implementation<br>
(<a href="https://github.com/llvm/llvm-project/blob/cb19e8c6d192a108b72ab07362921864a9e244f9/llvm/lib/IR/Globals.cpp#L463" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/cb19e8c6d192a108b72ab07362921864a9e244f9/llvm/lib/IR/Globals.cpp#L463</a>),<br>
which passes getOperand(0) - the resolver - as the first parameter to<br>
findBaseObject(). Because the resolver is a Function, findBaseObject()<br>
simply returns it as-is. Just checked in gdb ;)<br>
<br>
<br>
On Thu, Sep 10, 2020 at 3:16 PM Dmitry Polukhin<br>
<<a href="mailto:dmitry.polukhin@gmail.com" target="_blank">dmitry.polukhin@gmail.com</a>> wrote:<br>
><br>
> > * Calling getBaseObject() on a GlobalIFunc returns its resolver function.<br>
><br>
> I still don't understand how it can happen looking to the code (<a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Globals.cpp#L430" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Globals.cpp#L430</a>). I believe it should return nullptr (the same as if you call it from GlobalAlias that refers to GlobalIFunc).<br>
><br>
> I don't have a strong opinion here because deriving GlobalIFunc from GlobalObject does make some sense. At the same time from implementation point of view there were lots of similarities between GlobalAlias and GlobalIFunc (in the most case they should be handled identically or very similarly). getBaseObject method in initial implementation belonged to GlobalAlias only. David moved it to GlobalIndirectSymbol in <a href="https://reviews.llvm.org/rG95549497ec8b5269f0439f12859537b7371b7c90" rel="noreferrer" target="_blank">https://reviews.llvm.org/rG95549497ec8b5269f0439f12859537b7371b7c90</a> but unfortunately I cannot find corresponding review and discussion.<br>
><br>
> On Tue, Sep 8, 2020 at 6:22 PM Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a>> wrote:<br>
>><br>
>> Thanks Itay for summarizing the discussion on D81911. Directly adding a few folks either involved with the discussion there (Dmitry, who originally ported the gcc implementation to clang/llvm), or who have implemented other patches relating to IFunc support in llvm (Peter).<br>
>><br>
>> Teresa<br>
>><br>
>> On Mon, Sep 7, 2020 at 10:07 AM Itay Bookstein via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>><br>
>>> I was working on <a href="https://reviews.llvm.org/D81911" rel="noreferrer" target="_blank">https://reviews.llvm.org/D81911</a> to try and fix<br>
>>> <a href="https://bugs.llvm.org/show_bug.cgi?id=46340" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=46340</a> . Through the review<br>
>>> process we happened upon a design limitation or perhaps a potential<br>
>>> mis-modelling of GlobalIFunc in the IR object hierarchy, which leads<br>
>>> to some problems in LTO flows.<br>
>>><br>
>>> To summarize, as it currently stands (and in the hopes of faithfully<br>
>>> representing the conclusions of that discussion):<br>
>>> * Calling getBaseObject() on a GlobalAlias whose aliasee is a<br>
>>> GlobalIFunc currently returns null.<br>
>>> * Calling getBaseObject() on a GlobalIFunc returns its resolver function.<br>
>>> * This causes computeAliasSummary in ModuleSummaryAnalysis to crash on<br>
>>> a null dereference for an alias-to-ifunc situation.<br>
>>> * A GlobalIFunc and its resolver are *not* interchangeable: at the<br>
>>> interface level, they have different signatures (conceptually, the<br>
>>> IFunc has the same signature of the function pointer that the resolver<br>
>>> potentially returns, not of the resolver itself).<br>
>>> * It makes sense for the IFunc to be its own base object (which is<br>
>>> GlobalObject-like-behavior), but type-hierarchy-wise it can't. This is<br>
>>> because GlobalIFunc derives from GlobalIndirectSymbol which derives<br>
>>> directly from GlobalValue, and therefore it is not a GlobalObject.<br>
>>><br>
>>> Would it make sense for GlobalIFunc to derive from GlobalObject<br>
>>> instead of GlobalIndirectSymbol? If so, GlobalIndirectSymbol would<br>
>>> lose its purpose somewhat, and could be merged into GlobalAlias. It<br>
>>> would, however, require updating a considerable amount of code.<br>
>>><br>
>>> ~Itay<br>
>>> _______________________________________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>><br>
>><br>
>><br>
>> --<br>
>> Teresa Johnson | Software Engineer | <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |<br>
<br>
<br>
<br>
-- <br>
<br>
<br>
<br>
<br>
Itay Bookstein<br>
<br>
Software Engineer<br>
<br>
<br>
NEXTSILICON<br>
<br>
<br>
T. + 972 50 594 0880<br>
</blockquote></div>