This is an archive of the discontinued LLVM Phabricator instance.

[lld/WebAssembly] Slightly nicer error message for malformed input files
ClosedPublic

Authored by loladiro on Jun 23 2019, 3:16 PM.

Details

Summary

Before:

wasm-ld: error: Relocations not in offset order

After

wasm-ld: error: While processing `libjulia.so`: Relocations not in offset order

At least this way you get to find out which input file is malformed.

Event Timeline

loladiro created this revision.Jun 23 2019, 3:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2019, 3:16 PM

Thanks!

lld/wasm/InputFiles.cpp
56

I think just MB.getBufferIdentifier() should be enough. Our other error message don't include the "While processing" prefix, but the filename is certainly useful.

We should find a way to make a test. Perhaps you can do something like " echo <WASM_MAGIC>foo" > "test.o" in order to generate a bad object file.

loladiro updated this revision to Diff 206547.Jun 25 2019, 4:21 PM

Remove extraneous output from error message and add test case.

Ideally I'd rather see the invalid file be generated on the fly, but this is also ok since it should never really change.

What about the actual test that checks for the error string? I imagine the binary would go in "Inputs" and the .test would be a text file that checks for the error.

Ideally I'd rather see the invalid file be generated on the fly, but this is also ok since it should never really change.

What about the actual test that checks for the error string? I imagine the binary would go in "Inputs" and the .test would be a text file that checks for the error.

The test file is just

\00asm
; RUN: not wasm-ld -o %t.wasm.out %s %s 2>&1 | FileCheck %s
; This file is an invalid input file with wasm magic (\00asm).
; We test that the filename is printed in the error path.
; CHECK: error:
; CHECK: corrupted.wasm.test: Bad version number

I suppose fabricator has some sort of binary detection that doens't like the leading zero byte.

sbc100 accepted this revision.Jun 25 2019, 5:28 PM

Oh cool, I totally didn't think of that. I find it a bit strange to have the test script within the invalid binary wasm file, but hey if it works its kinda cool.

This revision is now accepted and ready to land.Jun 25 2019, 5:28 PM
This revision was automatically updated to reflect the committed changes.