Adjustor thunks and variadic arguments.

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 9 00:10:04 PDT 2015


Hi,

How does LDC handle emitting thunks to external modules that accept
variadic parameters?

If under the same object file, you can happily emit:

sub    offset, %thisreg
jmp    method

But if doing separate compilation, many targets to not support doing
such operations across section boundaries.  So a more general/agnostic
way to go about it is by copying all arguments, adjusting the 'this'
pointer and calling target method at the codegen level.  This works so
long as you are not dealing with a variadic method (ie:
std.stream.Stream.printf)

Example code below:

A.d
---
module A;

interface I_A
{
    bool a(...);
}

class C_A : I_A
{
    bool a(...) { return false; }
}


B.d
---
module B;

import A;

interface I_B : I_A
{
    void b();
}

abstract class C_B : C_A, I_B
{
    abstract void b();
}

void main() { }


More information about the Digitalmars-d mailing list