[cfe-dev] Thunks for MS ABI.

Eli Friedman eli.friedman at gmail.com
Fri Feb 3 03:04:00 PST 2012


On Fri, Feb 3, 2012 at 2:10 AM, r4start <r4start at gmail.com> wrote:
> Hi all.
>
> While I implementing vf-tables for MS ABI I met a problem.
> In MS ABI vf-table defines by pair of CXXRecordDecl, for example
>
> class first{
> public:
>   virtual void asdf() {}
> };
> class second : public virtual first {
> public :
>   int q;
>     virtual void asdf() { q = 90; }
> };
> class third : public virtual second {
> public:
>   virtual void ff(){}
> };

A quick explanation of how thunks work in the Itanium ABI:

Given the following:
struct first {
  virtual void asdf() = 0;
};
struct second : public virtual first {
public :
  int q;
  virtual void asdf();
};
void second::asdf() { q = 90; }

For this code, clang generates exactly one thunk: the one that lets a
call which is syntactically a call to first::asdf to forward to
second::asdf.  No other thunk is necessary: any call which dynamically
resolves to second::asdf is either calling second::asdf or
first::asdf.  Unless some other class defines an asdf method, clang
will never generate any other thunks for asdf, no matter what the
inheritance structure looks like.

> If I want emit thunk , then I need to know record class(third) and base
> class(first).
> But getThunkInfo function has one parameter CXXMethodDecl and getParent
> function returns first class.
> How can I get third class record declaration?

For thunks like those in the Itanium ABI, the question you're asking
makes no sense: "third" is irrelevant to thunk emission.  For a given
CXXMethodDecl, the set of necessary thunks is fixed; there is
precisely one thunk for "second::asdf" no matter how any other class
inheriting from "second" is defined.

If MS ABI thunks do actually require generating thunks upon the
definition of "third", you're going to have to essentially start from
scratch; the existing thunk code can only handle Itanium-style thunks.

-Eli




More information about the cfe-dev mailing list