简体   繁体   中英

Get the C++ member function and the corresponding offset via LLVM IR

I would like to have an overall analysis for c++ classes, and I want to know each member function's offset. Could anyone give me any hint on how to get those information in LLVM IR? I would appreciate any help from you.

A code example could be:

class Circle {
    int radius;
public:
    void setRadius(int _radius){radius = _radius;}
    int getRadius() {return radius;}
};

I would like to know that 1st field is an integer, the 2nd and 3rd field is a member function, and also the definition of the member function.

There's not really such a thing as a "member function's offset". Functions can be totally optimized away as is the case here . You can take a look at the IR here and it's essentially the same thing. Virtual functions will have an offset into a vtable, but that's another matter.

You can force there to be an address by taking a pointer to a function. You could then calculate an "offset", but relative to what exactly? Not sure there's any guarantee from LLVM how member functions are placed in the text segment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM