llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

cc1as chokes on assembly from clang's `-S` option when WebAssembly is the target

Open Madgen-content opened this issue 9 years ago • 6 comments

Bugzilla Link 34544
Resolution FIXED
Resolved on Aug 01, 2019 11:12
Version trunk
OS Linux
Attachments wasm-main.s, arm-main.s
CC @aardappel,@dschuff,@sbc100

Extended Description

If we have the file main.c with the contents ''' int main() { return 1; } '''

and $CC is a clang built to target wasm32-unknown-unknown-wasm, we can produce assembly with $CC -S main.c. However, clang can't process the resulting main.s file, although it's contents seem perfectly valid. Running $CC main.s results in clang -cc1as: error: unknown target triple 'wasm32-unknown-unknown-wasm', please use -triple or -arch

Doing the same process with a clang set to target aarch64-unknown-linux-gnu results in perfectly fine code built for ARM.

The relevant .s files are attached

Madgen-content avatar Sep 11 '17 01:09 Madgen-content

Have been working on roundtripping a variety of C code thru .s, fixing everything I can across, to the point where this should generally be considered working now. If you come across any particular problems, please file individual bugs for the missing assembler feature against me.

Some of the changes:

Section types: https://reviews.llvm.org/D63947 Allow offsets and p2align in symbol load: https://reviews.llvm.org/D63951 Allow @​object in .type directives: https://reviews.llvm.org/D63955 Support .int16/32/64 directives: https://reviews.llvm.org/D63959 tablegen: distinguish float/int immediate operands: https://reviews.llvm.org/D64039 Negative float constants: https://reviews.llvm.org/D64367 refactored utilities to not depend on MachineInstr: https://reviews.llvm.org/D64643 .init_array: https://reviews.llvm.org/D64602 Infinity / nan: https://reviews.llvm.org/D64770 Call_indirect signatures: https://reviews.llvm.org/D64758

aardappel avatar Aug 01 '19 18:08 aardappel

Once https://reviews.llvm.org/D63901 lands your simple C program now round-trips thru assembly. I suspect there is more to fix though, so I will experiment with round-tripping larger programs :)

aardappel avatar Jun 27 '19 21:06 aardappel

This has a much higher chance of working now, given that we have basic assembler support for wasm assembly in LLVM now. Though it is still not feature complete (e.g. I am only just adding support for data sections), so more complex C files may still run into something unsupported.

But this would be good to test with, I'll have a look sometime soon.

aardappel avatar Feb 26 '19 01:02 aardappel

Wouter, maybe this is one for you to take a look at? Might be fixed already?

sbc100 avatar Feb 22 '19 21:02 sbc100

As far as I know, we haven't done any work on wasm assembly parsing in LLVM. The history is, that before LLVM had any wasm binary support, the only kind of output was the ELF-style assembly format (which is currently what you get when you use the "wasm32-unknown-unknown-elf" triple with -S). Binaryen (https://github.com/WebAssembly/binaryen) has a parser for this format and a simple linker, and it is what we currently use in emscripten. Later on we began the design for wasm binary output and object files, along with the wasm port of lld. Currently it has enough support to link basic C files but is missing some features for C++ (e.g. comdats). We have only really been testing the binary format with the "wasm---wasm triple", and currently there are no parsers for that assembly format that I know of. We do ultimately plan to have a text assembly format for wasm, although it's not yet determined whether it will end up looking more like the current style or more like the "wat" format (the official wasm text format). We've been discussing it here https://github.com/WebAssembly/tool-conventions/issues/17, any input you may have would be welcome.

dschuff avatar Sep 11 '17 16:09 dschuff

assigned to @aardappel

Madgen-content avatar Sep 11 '17 01:09 Madgen-content