Very clever compiling error with mangling

kinke noone at nowhere.com
Sat Jun 4 21:02:33 UTC 2022


On Saturday, 4 June 2022 at 20:32:26 UTC, mesni wrote:
> This is a fragment of the string from which the function is 
> generated.
>
> ```d
> mixin({
>     import std.array;
>     string result = q{
>         __gshared extern(C) static void* dpford_funcp_DMANGLE;
>         pragma(mangle, "DMANGLE")
>         void dpford_func_DMANGLE() {
>             asm{
>                 naked;
>                 jmp dpford_funcp_DMANGLE;
>             }
>         }
>     };
>     return result.replace("DMANGLE", n.mangleof);
> }());
> ```
> The function declarations themselves
> ```d
> In api.di
>
> module api;
>
> enum SorrelAPI;
>
> @SorrelAPI
> int testFunc(int, int);
> ```
>
> The other module in the mixin template reads all the changled 
> function names from that module.

Ah okay, you're using a `void()` signature for all wrappers. If 
you don't want to bother with a proper signature (possibly 
derivable from `n`), you need to avoid compiling modules using 
the properly typed declaration and the wrapper module(s) *to a 
single object file*, to prevent LDC from detecting the signature 
mismatch. So if you have one or more wrapper modules containing 
nothing but these mixins, compiling those separately to their own 
object file/static lib should work.


More information about the digitalmars-d-ldc mailing list