[llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

Bruce Hoult via llvm-dev

Hi,

 

I have been implementing a CallGraphSCCPass that analyzes each function invocation. Direct calls are not a problem, but currently I also need to retrieve the name of the function in the case of virtual method calls. For example:

 

struct A {

    A() {}

    virtual foo() {}

    virtual ~A() {}

};

 

int main() {

    A* a = new A;

    a->foo();

}

 

In the pass, I can determine the name of the indirect call by using CallInst::getCalledValue(), but that doesn’t give any information on the actual method that is being called, which should be foo(). The only “name” I can get is the type of the class, in which this case is class.A.

 

Is there any way I can get the name of the virtual method (foo) that is being invoked? It isn’t in the bitcode except for when it is defined. I tried taking a look at the whole-program-devirt source but can’t find where they are actually finding the names of the functions when building the virtual tables for each class.

 

I would greatly appreciate any help on this and if it is possible at all.

 

Thanks,

 

Ben Fu

 


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

Bruce Hoult via llvm-dev
Sounds like maybe you're trying to do something at a level where it's not going to be practical - what's your overall goal?

But no, at the LLVM IR level you can't get the name of a virtual function being called - as you've seen, it's a dynamic call through a table of function pointers & at LLVM's level, those functions could have any names (or none at all - or at least none that makes sense in this translation unit/module because it's a local symbol in some other module).

On Thu, Jun 7, 2018 at 9:40 AM via llvm-dev <[hidden email]> wrote:

Hi,

 

I have been implementing a CallGraphSCCPass that analyzes each function invocation. Direct calls are not a problem, but currently I also need to retrieve the name of the function in the case of virtual method calls. For example:

 

struct A {

    A() {}

    virtual foo() {}

    virtual ~A() {}

};

 

int main() {

    A* a = new A;

    a->foo();

}

 

In the pass, I can determine the name of the indirect call by using CallInst::getCalledValue(), but that doesn’t give any information on the actual method that is being called, which should be foo(). The only “name” I can get is the type of the class, in which this case is class.A.

 

Is there any way I can get the name of the virtual method (foo) that is being invoked? It isn’t in the bitcode except for when it is defined. I tried taking a look at the whole-program-devirt source but can’t find where they are actually finding the names of the functions when building the virtual tables for each class.

 

I would greatly appreciate any help on this and if it is possible at all.

 

Thanks,

 

Ben Fu

 

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

Bruce Hoult via llvm-dev

The goal is to create a function call graph with the names of the functions, and the graph should include indirect calls too. I looked and saw that LLVM supports a metadata type called ‘callees’, but I don’t see that it’s currently being implemented by clang. Will this eventually be used?

 

Thanks,

Ben

 

From: David Blaikie <[hidden email]>
Sent: Friday, June 8, 2018 1:06 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

 

Sounds like maybe you're trying to do something at a level where it's not going to be practical - what's your overall goal?

But no, at the LLVM IR level you can't get the name of a virtual function being called - as you've seen, it's a dynamic call through a table of function pointers & at LLVM's level, those functions could have any names (or none at all - or at least none that makes sense in this translation unit/module because it's a local symbol in some other module).

 

On Thu, Jun 7, 2018 at 9:40 AM via llvm-dev <[hidden email]> wrote:

Hi,

 

I have been implementing a CallGraphSCCPass that analyzes each function invocation. Direct calls are not a problem, but currently I also need to retrieve the name of the function in the case of virtual method calls. For example:

 

struct A {

    A() {}

    virtual foo() {}

    virtual ~A() {}

};

 

int main() {

    A* a = new A;

    a->foo();

}

 

In the pass, I can determine the name of the indirect call by using CallInst::getCalledValue(), but that doesn’t give any information on the actual method that is being called, which should be foo(). The only “name” I can get is the type of the class, in which this case is class.A.

 

Is there any way I can get the name of the virtual method (foo) that is being invoked? It isn’t in the bitcode except for when it is defined. I tried taking a look at the whole-program-devirt source but can’t find where they are actually finding the names of the functions when building the virtual tables for each class.

 

I would greatly appreciate any help on this and if it is possible at all.

 

Thanks,

 

Ben Fu

 

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

Bruce Hoult via llvm-dev


On Fri, Jun 8, 2018 at 2:59 PM <[hidden email]> wrote:

The goal is to create a function call graph with the names of the functions, and the graph should include indirect calls too.


That's not possible in general - functions being called could come from external code, for example. (dlsym, for instance)
 

I looked and saw that LLVM supports a metadata type called ‘callees’, but I don’t see that it’s currently being implemented by clang. Will this eventually be used?


Not sure - I guess maybe if there were a constrained set of callees - but that's not true of a polymorphic class hierarchy (there could always be another derived class in some external code - it's not a closed group/set/collection/thing).
 

 

Thanks,

Ben

 

From: David Blaikie <[hidden email]>
Sent: Friday, June 8, 2018 1:06 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass

 

Sounds like maybe you're trying to do something at a level where it's not going to be practical - what's your overall goal?

But no, at the LLVM IR level you can't get the name of a virtual function being called - as you've seen, it's a dynamic call through a table of function pointers & at LLVM's level, those functions could have any names (or none at all - or at least none that makes sense in this translation unit/module because it's a local symbol in some other module).

 

On Thu, Jun 7, 2018 at 9:40 AM via llvm-dev <[hidden email]> wrote:

Hi,

 

I have been implementing a CallGraphSCCPass that analyzes each function invocation. Direct calls are not a problem, but currently I also need to retrieve the name of the function in the case of virtual method calls. For example:

 

struct A {

    A() {}

    virtual foo() {}

    virtual ~A() {}

};

 

int main() {

    A* a = new A;

    a->foo();

}

 

In the pass, I can determine the name of the indirect call by using CallInst::getCalledValue(), but that doesn’t give any information on the actual method that is being called, which should be foo(). The only “name” I can get is the type of the class, in which this case is class.A.

 

Is there any way I can get the name of the virtual method (foo) that is being invoked? It isn’t in the bitcode except for when it is defined. I tried taking a look at the whole-program-devirt source but can’t find where they are actually finding the names of the functions when building the virtual tables for each class.

 

I would greatly appreciate any help on this and if it is possible at all.

 

Thanks,

 

Ben Fu

 

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev