英文:
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.
英文:
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.
答案1
得分: 2
不真正存在所谓的“成员函数的偏移量”。函数可以被完全优化掉,就像这里一样。您可以在此处查看IR,本质上是相同的。虚函数将具有进入vtable的偏移量,但那是另一回事。
您可以通过获取函数的指针来强制存在一个地址。然后,您可以计算一个“偏移量”,但相对于什么呢?不确定LLVM是否保证将成员函数放置在文本段中。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论