[PATCH] D76547: [WebAssembly] Add `wasm-exported` function attribute

Sam Clegg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 29 11:20:04 PDT 2023


sbc100 added a comment.

In D76547#4231476 <https://reviews.llvm.org/D76547#4231476>, @aaron.ballman wrote:

> In D76547#4231422 <https://reviews.llvm.org/D76547#4231422>, @sbc100 wrote:
>
>> The reason `__attribute__((export_name("foo")))` doesn't work in all use cases is that we have a lot of existing code that uses the `EMSCRIPTEN_KEEPALIVE` macro.     We also have run into other folks who want to include this is some kind of `FOO_API`, or `EXPORT_API` type macros.  Its not possible to have such a macro map to the existing export_name since they don't include the symbol name: e.g:
>>
>>   EMSCRIPTEN_KEEPALIVE int foo();`
>>   
>>   JNI_EXPORT int myfunct();
>>
>> In these cases we need something that uses the llvm symbol name for the export.
>
> I think there's two ways we could address this without adding a new attribute (maybe you've thought of this and have reasons for this to be a bad suggestion):
>
> - It seems that `export_name` doesn't care if you put in an empty string for the argument, so we could treat that case as meaning "export with the name of the symbol this attribute is attached to"
> - We could allow `export_name` to take zero or one argument. The one-argument form is the same as it is today, but the zero argument form exports with the name of the symbol the attribute is attached to.
>
> Do you think either of those could work?

Yes, I think the second one would be ideal.  The first one is slightly less idea because it prevents something being exported with the empty string as its name (wasm allows such things).

Can an attribute take an optional argument?  That would be great solution.   For my initial version of this change I did look into making `export_name(DEFAULT)` work (note the lack of quotes around the word DEFAULT here), but I could not find way to make a single attribute take both a string *or* a constant.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76547/new/

https://reviews.llvm.org/D76547



More information about the cfe-commits mailing list