This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Fix segfault in map file support
ClosedPublic

Authored by tlively on Sep 26 2020, 4:33 PM.

Details

Summary

The code previously assumed that getChunk would return a non-null pointer for
every symbol, but in fact it only returns non-null pointers for DefinedFunction
and DefinedData symbols. This patch fixes the segfault by checking whether
getChunk returns a null for each symbol and skipping the mapping output for
any symbols for which it does.

Diff Detail

Event Timeline

tlively created this revision.Sep 26 2020, 4:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 26 2020, 4:33 PM
tlively requested review of this revision.Sep 26 2020, 4:33 PM

Can you update the mapfile test to tickle this?

I'm not actually sure how to do that in the .s format, since I found this on a real-world project. Do you know what I should add to the test?

Do you know that symbol type that causes the crash?

Maybe a DefinedGlobal would do it? You can define wasm globals in .s files (see lld/test/wasm/globals.s).

sbc100 added inline comments.Nov 4 2020, 11:23 AM
lld/wasm/MapFile.cpp
84

How about if we just have fileOffset default to 0 if chunk is null? I think we still want to include all symbols in the map.

Yes, almost certainly. I actually ran into another null pointer dereference and had to add another workaround to my local branch as well. I haven't pursued this patch upstream because I still have not been able to create a test case :(

sbc100 added a comment.Feb 1 2021, 3:35 PM

Can we get this landed? Did adding a defined global to a .s file work? (I think maybe you can just add a defined global to lld/test/wasm/map-file.s?

Trying again now, but last time I tried that (a while ago) I couldn't reproduce the issue.

tlively updated this revision to Diff 320656.Feb 1 2021, 6:10 PM
  • Add test with wasm global, try to print it

Ok, I was able to reproduce one of the issues by using a wasm global this time. However, I'm having trouble figuring out how to fit printing the global to the map file in with the current infrastructure. Comments would be very appreciated.

tlively marked an inline comment as done.Feb 1 2021, 6:11 PM
sbc100 accepted this revision.Feb 2 2021, 10:14 AM

Seems reasonable to me. Our map file format is relatively arbitrary AFAICT. Its mostly about conveying the final contents of the linked binary IIUC.

This revision is now accepted and ready to land.Feb 2 2021, 10:14 AM
sbc100 added a comment.Feb 8 2021, 8:18 AM

Is this good to go now?

tlively updated this revision to Diff 322506.Feb 9 2021, 2:30 PM
  • Clean up

Yes, I think so. I changed this back to skipping symbols without chunks in the because we don't need to demangle global symbols.

sbc100 accepted this revision.Feb 9 2021, 2:39 PM
This revision was landed with ongoing or failed builds.Feb 9 2021, 2:43 PM
This revision was automatically updated to reflect the committed changes.