[WebAssembly] Add an import_field function attribute
authorDan Gohman <dan433584@gmail.com>
Fri, 1 Feb 2019 22:25:23 +0000 (22:25 +0000)
committerDan Gohman <dan433584@gmail.com>
Fri, 1 Feb 2019 22:25:23 +0000 (22:25 +0000)
commitcae8459ad2d4cce5806bc8d64ef0020bc20e3252
treee0288d74cb7469061111c40b774224103140e010
parentc9f4d25f269819b5abb38b66a813335c681a76cc
[WebAssembly] Add an import_field function attribute

This is similar to import_module, but sets the import field name
instead.

By default, the import field name is the same as the C/asm/.o symbol
name. However, there are situations where it's useful to have it be
different. For example, suppose I have a wasm API with a module named
"pwsix" and a field named "read". There's no risk of namespace
collisions with user code at the wasm level because the generic name
"read" is qualified by the module name "pwsix". However in the C/asm/.o
namespaces, the module name is not used, so if I have a global function
named "read", it is intruding on the user's namespace.

With the import_field module, I can declare my function (in libc) to be
"__read", and then set the wasm import module to be "pwsix" and the wasm
import field to be "read". So at the C/asm/.o levels, my symbol is
outside the user namespace.

Differential Revision: https://reviews.llvm.org/D57602

llvm-svn: 352930
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/wasm-import-name.c [new file with mode: 0644]
clang/test/Misc/pragma-attribute-supported-attributes-list.test