Itay Bookstein via llvm-dev
2020-Sep-07 17:06 UTC
[llvm-dev] [IR] Modelling of GlobalIFunc
I was working on https://reviews.llvm.org/D81911 to try and fix https://bugs.llvm.org/show_bug.cgi?id=46340 . Through the review process we happened upon a design limitation or perhaps a potential mis-modelling of GlobalIFunc in the IR object hierarchy, which leads to some problems in LTO flows. To summarize, as it currently stands (and in the hopes of faithfully representing the conclusions of that discussion): * Calling getBaseObject() on a GlobalAlias whose aliasee is a GlobalIFunc currently returns null. * Calling getBaseObject() on a GlobalIFunc returns its resolver function. * This causes computeAliasSummary in ModuleSummaryAnalysis to crash on a null dereference for an alias-to-ifunc situation. * A GlobalIFunc and its resolver are *not* interchangeable: at the interface level, they have different signatures (conceptually, the IFunc has the same signature of the function pointer that the resolver potentially returns, not of the resolver itself). * It makes sense for the IFunc to be its own base object (which is GlobalObject-like-behavior), but type-hierarchy-wise it can't. This is because GlobalIFunc derives from GlobalIndirectSymbol which derives directly from GlobalValue, and therefore it is not a GlobalObject. Would it make sense for GlobalIFunc to derive from GlobalObject instead of GlobalIndirectSymbol? If so, GlobalIndirectSymbol would lose its purpose somewhat, and could be merged into GlobalAlias. It would, however, require updating a considerable amount of code. ~Itay
Teresa Johnson via llvm-dev
2020-Sep-08 17:22 UTC
[llvm-dev] [IR] Modelling of GlobalIFunc
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). Teresa On Mon, Sep 7, 2020 at 10:07 AM Itay Bookstein via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I was working on https://reviews.llvm.org/D81911 to try and fix > https://bugs.llvm.org/show_bug.cgi?id=46340 . Through the review > process we happened upon a design limitation or perhaps a potential > mis-modelling of GlobalIFunc in the IR object hierarchy, which leads > to some problems in LTO flows. > > To summarize, as it currently stands (and in the hopes of faithfully > representing the conclusions of that discussion): > * Calling getBaseObject() on a GlobalAlias whose aliasee is a > GlobalIFunc currently returns null. > * Calling getBaseObject() on a GlobalIFunc returns its resolver function. > * This causes computeAliasSummary in ModuleSummaryAnalysis to crash on > a null dereference for an alias-to-ifunc situation. > * A GlobalIFunc and its resolver are *not* interchangeable: at the > interface level, they have different signatures (conceptually, the > IFunc has the same signature of the function pointer that the resolver > potentially returns, not of the resolver itself). > * It makes sense for the IFunc to be its own base object (which is > GlobalObject-like-behavior), but type-hierarchy-wise it can't. This is > because GlobalIFunc derives from GlobalIndirectSymbol which derives > directly from GlobalValue, and therefore it is not a GlobalObject. > > Would it make sense for GlobalIFunc to derive from GlobalObject > instead of GlobalIndirectSymbol? If so, GlobalIndirectSymbol would > lose its purpose somewhat, and could be merged into GlobalAlias. It > would, however, require updating a considerable amount of code. > > ~Itay > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Teresa Johnson | Software Engineer | tejohnson at google.com | -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200908/6e5d9ed9/attachment.html>
Dmitry Polukhin via llvm-dev
2020-Sep-10 12:15 UTC
[llvm-dev] [IR] Modelling of GlobalIFunc
> * Calling getBaseObject() on a GlobalIFunc returns its resolver function.I still don't understand how it can happen looking to the code ( https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Globals.cpp#L430). I believe it should return nullptr (the same as if you call it from GlobalAlias that refers to GlobalIFunc). 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 https://reviews.llvm.org/rG95549497ec8b5269f0439f12859537b7371b7c90 but unfortunately I cannot find corresponding review and discussion. On Tue, Sep 8, 2020 at 6:22 PM Teresa Johnson <tejohnson at google.com> wrote:> 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). > > Teresa > > On Mon, Sep 7, 2020 at 10:07 AM Itay Bookstein via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I was working on https://reviews.llvm.org/D81911 to try and fix >> https://bugs.llvm.org/show_bug.cgi?id=46340 . Through the review >> process we happened upon a design limitation or perhaps a potential >> mis-modelling of GlobalIFunc in the IR object hierarchy, which leads >> to some problems in LTO flows. >> >> To summarize, as it currently stands (and in the hopes of faithfully >> representing the conclusions of that discussion): >> * Calling getBaseObject() on a GlobalAlias whose aliasee is a >> GlobalIFunc currently returns null. >> * Calling getBaseObject() on a GlobalIFunc returns its resolver function. >> * This causes computeAliasSummary in ModuleSummaryAnalysis to crash on >> a null dereference for an alias-to-ifunc situation. >> * A GlobalIFunc and its resolver are *not* interchangeable: at the >> interface level, they have different signatures (conceptually, the >> IFunc has the same signature of the function pointer that the resolver >> potentially returns, not of the resolver itself). >> * It makes sense for the IFunc to be its own base object (which is >> GlobalObject-like-behavior), but type-hierarchy-wise it can't. This is >> because GlobalIFunc derives from GlobalIndirectSymbol which derives >> directly from GlobalValue, and therefore it is not a GlobalObject. >> >> Would it make sense for GlobalIFunc to derive from GlobalObject >> instead of GlobalIndirectSymbol? If so, GlobalIndirectSymbol would >> lose its purpose somewhat, and could be merged into GlobalAlias. It >> would, however, require updating a considerable amount of code. >> >> ~Itay >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > > -- > Teresa Johnson | Software Engineer | tejohnson at google.com | >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200910/4e833871/attachment.html>
Duncan P. N. Exon Smith via llvm-dev
2021-Sep-08 17:03 UTC
[llvm-dev] [IR] Modelling of GlobalIFunc
For the specific problem hit below, it feels like another available approach would be to change GlobalIndirectSymbol to behave correctly for both GlobalAlias and GlobalIFunc, without changing the class hierarchy, by reducing its scope and deferring more to its derived classes (e.g., change getBaseObject() to do the right thing). Can you comment further on the tradeoffs vs. the refactoring you’re proposing? (I see your argument that globalifunc shares some properties globalobject, but it’s not obvious to me that it’s more similar to globalobject than it is to globalalias, or that in aggregate code dealing with these classes will be cleaner after moving globalifunc over to the globalobject bucket.)> On 2020-09-07, at 13:06, Itay Bookstein via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I was working on https://reviews.llvm.org/D81911 to try and fix > https://bugs.llvm.org/show_bug.cgi?id=46340 . Through the review > process we happened upon a design limitation or perhaps a potential > mis-modelling of GlobalIFunc in the IR object hierarchy, which leads > to some problems in LTO flows. > > To summarize, as it currently stands (and in the hopes of faithfully > representing the conclusions of that discussion): > * Calling getBaseObject() on a GlobalAlias whose aliasee is a > GlobalIFunc currently returns null. > * Calling getBaseObject() on a GlobalIFunc returns its resolver function. > * This causes computeAliasSummary in ModuleSummaryAnalysis to crash on > a null dereference for an alias-to-ifunc situation. > * A GlobalIFunc and its resolver are *not* interchangeable: at the > interface level, they have different signatures (conceptually, the > IFunc has the same signature of the function pointer that the resolver > potentially returns, not of the resolver itself). > * It makes sense for the IFunc to be its own base object (which is > GlobalObject-like-behavior), but type-hierarchy-wise it can't. This is > because GlobalIFunc derives from GlobalIndirectSymbol which derives > directly from GlobalValue, and therefore it is not a GlobalObject. > > Would it make sense for GlobalIFunc to derive from GlobalObject > instead of GlobalIndirectSymbol? If so, GlobalIndirectSymbol would > lose its purpose somewhat, and could be merged into GlobalAlias. It > would, however, require updating a considerable amount of code. > > ~Itay > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Possibly Parallel Threads
- [IR] Modelling of GlobalIFunc
- RFC: Absolute or "fixed address" symbols as immediate operands
- RFC: Absolute or "fixed address" symbols as immediate operands
- RFC: Absolute or "fixed address" symbols as immediate operands
- [RFC][LLVM] New Constant type for representing function PLT entries