PS: I've been looking around a bit, and maybe this is the better solution
(via __attribute__(...)):
__attribute__((visibility("default"))) void foo(void);
This should be the clang equivalent to __declspec(dllimport) in the Visual
Studio compiler, see here:
https://webassembly.org/docs/dynamic-linking/
On Thursday, 2 May 2019 17:06:27 UTC+2, Duan Bing wrote:
>
> Thanks, your new idea works for me. the motivation of doing this is that
> I will call this imported function while I will insert some wasm code to
> the original wasm file later, similar to this project had done
> https://github.com/ewasm/wasm-metering , but by a different PL. so I
> don't want the original wasm developer to use this function(I will insert
> foo dynamically with a mangling name ), and I also occupy the import index
> space by doing this in advance.
>
> Floh <[email protected] <javascript:>> 于2019年5月2日周四 下午10:56写道:
>
>> Ah ok, I misunderstood your question, apologies. I don't know how one
>> would add a function declaration to the WASM imports table like this.
>> EMSCRIPTEN_KEEPALIVE and the "-s EXPORTED_FUNCTIONS" linker option would
>> work for the "other side" (some WASM module exporting functions to the
>> outside).
>>
>> Complete guess, but maybe you need some "dummy code" that's guaranteed to
>> stay in the importing WASM module, even though this is never called? So
>> that the linker would recognize the function as an "import".
>>
>> Something like this:
>>
>> extern "C" void foo();
>> // dummy_imports() is never called, but will not be removed because of
>> EMSCRIPTEN_KEEPALIVE
>> EMSCRIPTEN_KEEPALIVE void dummy_imports(void) {
>> foo();
>> }
>>
>> But as I said, this is complete guess.
>>
>> On Thursday, 2 May 2019 16:22:28 UTC+2, Duan Bing wrote:
>>>
>>> Thanks, Floh. it works when the function is defined.
>>> Actually, my function is an external function declaration, like
>>> extern "C" void foo();
>>>
>>> It doesn't work even I declare like this:
>>> extern "C" void EMSCRIPTEN_KEEPALIVE foo().
>>>
>>> Do you have any idea for this situation?
>>>
>>> Floh <[email protected]> 于2019年5月2日周四 下午10:13写道:
>>>
>>>> Have a look at EMSCRIPTEN_KEEPALIVE:
>>>> https://emscripten.org/docs/api_reference/emscripten.h.html#c.EMSCRIPTEN_KEEPALIVE,
>>>>
>>>> this prevents a C/C++ function from being removed even when it isn't
>>>> referenced by other C/C++ code (normally this is used to call C functions
>>>> from the JS side).
>>>>
>>>> On Thursday, 2 May 2019 08:16:43 UTC+2, Duan Bing wrote:
>>>>>
>>>>> I declare an external function in C source file, but never used by the
>>>>> code, then compile it to wasm by EMCC. there is no doubt the external
>>>>> function will be eliminated by the compiler.
>>>>>
>>>>> Is there any approach to keep this external function and then be
>>>>> compiled to an import function in wasm?
>>>>>
>>>>> The motivation to remain the external function is that I want to
>>>>> insert some wasm code in the wasm file after it's generated.
>>>>>
>>>>> Thanks all!
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "emscripten-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.