This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Target features section
ClosedPublic

Authored by tlively on Mar 8 2019, 8:09 PM.

Details

Summary

Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.

The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.

Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.

Event Timeline

tlively created this revision.Mar 8 2019, 8:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2019, 8:09 PM
sbc100 added inline comments.Mar 11 2019, 2:15 PM
llvm/include/llvm/BinaryFormat/Wasm.h
262

char?

llvm/lib/Object/WasmObjectFile.cpp
677

Why this?

1621

This formatting looks worse IMHO. Skip clang-format here?

tlively marked 3 inline comments as done.Mar 11 2019, 2:31 PM
tlively added inline comments.
llvm/include/llvm/BinaryFormat/Wasm.h
262

Can do. Out of curiosity, what is the rationale for using char instead of uint8_t? It seems that uint8_t would give more predictable and portable results.

llvm/lib/Object/WasmObjectFile.cpp
677

I was having issues elsewhere with StringRef not owning the storage it references, so the contents of strings were being unexpectedly changed. I decided to retroactively play it safe and change these StringRefs to std::strings as well. From the manual:

StringRef doesn’t own or keep alive the underlying string bytes. As such it can easily lead to dangling pointers, and is not suitable for embedding in datastructures in most cases

1621

I agree. Will do.

sbc100 added inline comments.Mar 11 2019, 2:53 PM
llvm/include/llvm/BinaryFormat/Wasm.h
262

It just seemed more natural because you are using ASCII value here. Alternatively you could just use 0, 1 and 2 as the values? Was there rational for using ASCII values?

llvm/lib/Object/WasmObjectFile.cpp
677

Right, but in this case the strings are all pointing into the binary file (Ctx) IIUC? And what is more they only need to live as long as this function?

Even if the StringRefs outlived this function I believe that would be fine as Ctx is valid as long as this here.

tlively edited the summary of this revision. (Show Details)Mar 11 2019, 8:27 PM
tlively retitled this revision from [WebAssembly][WIP] Target features section to [WebAssembly] Target features section.
tlively updated this revision to Diff 190204.Mar 11 2019, 8:28 PM
tlively marked 3 inline comments as done.
  • address comments, add tests, fix bugs
tlively added inline comments.Mar 11 2019, 8:32 PM
llvm/include/llvm/BinaryFormat/Wasm.h
262

Most of the enums in this file have values that correspond directly to the values found in the binary file, so I wanted to use the exact prefix values that are allowed in the binary. The intent of the spec is reflected by using the ascii literals instead of hex literals. Actually, I think using uint8_t is better here as well because there are exactly eight bits in the binary format.

llvm/lib/Object/WasmObjectFile.cpp
677

Ok, I'll change it back. It's unfortunate that there is no way to tell this is safe by the signature of readString.

@sbc100 Do you have any further comments or concerns with this CL? Are you ok using uint8_t for the BinaryFormat enum?

sbc100 accepted this revision.Mar 13 2019, 6:46 PM
sbc100 added inline comments.
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
231

Doesn't this duplicate the values from Wasm.h?

This revision is now accepted and ready to land.Mar 13 2019, 6:46 PM
This revision was automatically updated to reflect the committed changes.
tlively marked an inline comment as done.
tlively added inline comments.Mar 20 2019, 1:33 PM
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
231

Yes, fixed.