This is an archive of the discontinued LLVM Phabricator instance.

Write DWARF data into WASM object file
ClosedPublic

Authored by yurydelendik on Mar 6 2018, 6:35 PM.

Diff Detail

Event Timeline

yurydelendik created this revision.Mar 6 2018, 6:35 PM
sbc100 added inline comments.Mar 7 2018, 2:56 PM
lib/MC/WasmObjectWriter.cpp
405

No curly braces here.

934

There should be one reloc section for each wasm section that contains relocs.

So I think this should generate multiple relocations sections with names like reloc.debug_strings etc..

Each of the reloc sections starts by specifying the target section, then each relocation entry doesn't need to specify the target section.

See: https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md

Maybe there is some reason why this doesn't work for you?

1024

remove curlys

1034

remove comment

Record relocatations per custom section
Add section symbols
Add special code, data, custom section relocation records

yurydelendik marked 4 inline comments as done.Mar 12 2018, 11:33 AM

Update llvm-readobj to support reading section symbols and new relocations.

sbc100 added inline comments.Mar 15 2018, 10:28 AM
include/llvm/BinaryFormat/Wasm.h
150

Could we just use the the section index here and reuse the existing ElementIndex? (Or at last move the Section inside the union?)

lib/MC/WasmObjectWriter.cpp
919

Is there anything debug specific here? How about writeCustomRelocSections()?

Or better still factor out the duplicate code in writeCodeRelocSection and writeDataRelocSection in single writeRelocSection(Name, Relocations);, then call that in a loop?

lib/Object/WasmObjectFile.cpp
1080

ELF uses ST_Debug for STT_SECTION symbols. (see include/llvm/Object/ELFObjectFile.h)

yurydelendik added inline comments.Mar 15 2018, 10:42 AM
include/llvm/BinaryFormat/Wasm.h
150

at last move the Section inside the union?

I moved it here due to compiler complaining about StringRef not being a trivial type.

Update obj2yaml/yaml2obj support for custom DWARF sections

yurydelendik marked 2 inline comments as done.Mar 15 2018, 12:28 PM
dschuff added inline comments.Mar 15 2018, 2:43 PM
include/llvm/Object/Wasm.h
264

This could probably be llvm::StringSet

lib/MC/WasmObjectWriter.cpp
1052

should this be indented?

1055

What is the section offset in this case? Are we just stuffing the offset from the beginning of the function in there?

We probably will need to coordinate with: https://reviews.llvm.org/D43097

Changes std::unordered_set to StringSet
Comment for patching XXX_OFFSET_I32 relocations
Minor fixes for reading section symbols

yurydelendik marked 3 inline comments as done.Mar 15 2018, 6:36 PM
yurydelendik added inline comments.
lib/MC/WasmObjectWriter.cpp
1055

Are we just stuffing the offset from the beginning of the function in there

That's correct -- added this in a comment

yurydelendik marked an inline comment as done.

Fix patching relocations for custom/debug sections.
Fix code style

Use proper symbol offset when hoisting symbols.

Fixes llvm-dwarfdump tools for wasm files w/DWARF sections

sbc100 added inline comments.Apr 5 2018, 4:01 PM
lib/MC/WasmObjectWriter.cpp
489

Can you just write these 6 lines as:

CustomSectionsRelocations[FixupSectionName].push_back(Rec);
tools/yaml2obj/yaml2wasm.cpp
449

Indentation looks strange here and a few other places too. git clang-format?

dschuff added inline comments.Apr 5 2018, 4:18 PM
lib/DebugInfo/DWARF/DWARFContext.cpp
1146 ↗(On Diff #140889)

Debug print should go back out or go behind DEBUG()

lib/MC/WasmObjectWriter.cpp
52

If we always reserve 5 bytes for the section size, couldn't the payload offset always be size offset + 5? We don't rewrite those in MC, right?

139

MCSection *Section (here and 141)

Update style via clang-format
Review fixes

yurydelendik added inline comments.Apr 5 2018, 6:01 PM
lib/MC/WasmObjectWriter.cpp
52

Would you like to express it as invariant / debug only field, and add related asserts in the code?

sbc100 added inline comments.Apr 5 2018, 6:49 PM
lib/MC/WasmObjectWriter.cpp
52

I think are you right Derek. Its not strictly related to this change but i guess we never really needed ContentsOffset.

sbc100 added inline comments.Apr 5 2018, 6:58 PM
include/llvm/ObjectYAML/WasmYAML.h
143

Can we reuse the existing name field here? i.e. can section symbols avoid storing a name at all?

Or how about dropping SectionType and simply using ElementIndex to store the index of the section as it appears in the file. That way there is no ambiguity (e.g. when two custom sections have the same name) and you don't need the SectionName field, since it can be looked up by finding the corresponding section. I know we don't really have section index space yet, but I think it might make sense to use that here.

yurydelendik added inline comments.Apr 5 2018, 7:06 PM
include/llvm/ObjectYAML/WasmYAML.h
143

The decision to go with such section reference was made based on the pattern we used in the "reloc."-section header. Will this bring some inconsistency in the linker spec?

sbc100 added a comment.Apr 9 2018, 4:03 PM

Can you rebase now that https://reviews.llvm.org/D45297 has landed?

Rebase on top of D45297

Fix tests at test/MC/WebAssembly/

sbc100 added inline comments.Apr 11 2018, 2:41 PM
include/llvm/Object/RelocVisitor.h
323

Where is this RelocVistor change used? Can this be a separate change perhaps?

lib/MC/WasmObjectWriter.cpp
175

How about just a bool here? isDebug?

484

Could we move this down the end of the function and just have an .isMetadata() before the final else?

Do we need the above error?

lib/Object/WasmObjectFile.cpp
1087

Seems like ELF always return ST_Debug for STT_SECTION type symbols: ELFObjectFile.h:536

1225

Is this needed as part of this change?

On thing to note is that Rel.Index is not always a symbol. For the TYPE_INDEX relocation types its a type index. We might want to revisit this in order to be consistent.

When I patched this change in I got a failure in test/tools/llvm-objdump/wasm.txt

Also, can you update the test/MC/WebAssembly/debug-info.ll test? In my local version I changed the first line to

; RUN: llc -filetype=obj %s -o - | llvm-readobj -r -s | FileCheck %s

Then added the entire output of readobj as CHECK-NEXT: lines.

yurydelendik added inline comments.Apr 12 2018, 11:17 AM
include/llvm/Object/RelocVisitor.h
323

This is needed to make llvm-dwarfdump not fail. It can be added in the separate change.

lib/Object/WasmObjectFile.cpp
1225

The change is needed for llvm-dwarfdump tool to not fail.

sbc100 added inline comments.Apr 12 2018, 11:26 AM
lib/Object/WasmObjectFile.cpp
1166

I think you can revert this part once https://reviews.llvm.org/D45579 lands

Fix test/tools/llvm-objdump/wasm.txt and test/MC/WebAssembly/debug-info.ll tests

Addresses recordRelocation review
Removes WasmCustomSectionKind

yurydelendik marked 3 inline comments as done.Apr 12 2018, 3:50 PM
yurydelendik added inline comments.
lib/MC/WasmObjectWriter.cpp
484

Yes. But I adjusted named symbols check to ignore R_WEBASSEMBLY_*_OFFSET_I32:

sbc100 added inline comments.Apr 13 2018, 9:31 AM
include/llvm/Object/RelocVisitor.h
323

I guess we should add a test for llvm-dwarfdump too?

yurydelendik marked an inline comment as done.

Rebase at D45579

Add dwarfdump test

Both test files can have the "Debug information is currently not supported" comment remove now I guess?

Remove "Debug information is not supported" comment.

sbc100 added inline comments.Apr 18 2018, 10:05 PM
lib/MC/WasmObjectWriter.cpp
177

Looks like this field isn't used. Remove?

401

Make this into a single condition?

In my simple test it looks like ".comment" is the only other section.. maybe we should allow that and just remove this condition? Or that can be a followup CL.

1236

Can we check for isMetadata here as well and perhaps copy the TODO about allowing all metadata sections from above?

1242

Is this what ELF calls these? I thought it was just ".data" etc. perhaps you can just use SectionName for this symbol name since it already starts with "." so can't conflict with a C/C++ symbol?

Remove isDebug and simplify SectionName

yurydelendik marked 4 inline comments as done.Apr 19 2018, 10:04 AM

Remove .Lsection_start from obj reader
Fix debug section filter

Fix debug-info.ll test -- custom section sizes

Rebase to D45980 attempt.

sbc100 added inline comments.Apr 25 2018, 3:40 PM
include/llvm/ObjectYAML/WasmYAML.h
141

Just reuse ElementIndex?

sbc100 added inline comments.Apr 25 2018, 4:12 PM
include/llvm/Object/RelocVisitor.h
339

Presumably we should be returning something useful here?

Looks like COFF and Mach-O just "return Value" and don't see "HasError" in the success case.

lib/ObjectYAML/WasmYAML.cpp
408

I would drop the suffix "Index" since we don't use it above in Function, or Global

Replace SectionIndex (with ElementIndex)

yurydelendik marked 2 inline comments as done.Apr 25 2018, 4:38 PM
yurydelendik added inline comments.
include/llvm/Object/RelocVisitor.h
339

Whatever passed as Value to RelocVisitor as SymInfo address (https://github.com/llvm-mirror/llvm/blob/0c191c5e264b8cab92b7fe720a1173f54cd4c9b2/lib/DebugInfo/DWARF/DWARFContext.cpp#L1430) is not suitable for DWARFContext

sbc100 accepted this revision.Apr 26 2018, 10:25 AM

LGTM. Lets get this landed!

lib/Object/WasmObjectFile.cpp
1053

You can remove this TODO. My understanding is that sections symbols always have value 0. At least on ELF they seem to

This revision is now accepted and ready to land.Apr 26 2018, 10:25 AM

Remove TODOs
Rebase on top of D46092

yurydelendik marked an inline comment as done.Apr 26 2018, 11:39 AM

Do you have llvm commit access to land this?

This revision was automatically updated to reflect the committed changes.

That commit broke lld build.
I have committed the obvious fix, please check that it is indeed the expected fix.

That commit broke lld build.
I have committed the obvious fix, please check that it is indeed the expected fix.

Thanks Roman