This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Remove WasmTagType
ClosedPublic

Authored by aheejin on Oct 4 2021, 11:52 AM.

Details

Summary

This removes WasmTagType. WasmTagType contained an attribute and a
signature index:

struct WasmTagType {
  uint8_t Attribute;
  uint32_t SigIndex;
};

Currently the attribute field is not used and reserved for future use,
and always 0. And that this class contains SigIndex as its property is
a little weird in the place, because the tag type's signature index is
not an inherent property of a tag but rather a reference to another
section that changes after linking. This makes tag handling in the
linker also weird that tag-related methods are taking both WasmTagType and WasmSignature
even though WasmTagType contains a signature
index. This is because the signature index changes in linking so it
doesn't have any info at this point. This instead moves SigIndex to
struct WasmTag itself, as we did for struct WasmFunction in D111104.

In this CL, in lib/MC and lib/Object, this now treats tag types in the
same way as function types. Also in YAML, this removes struct Tag,
because now it only contains the tag index. Also tags set SigIndex in
WasmImport's union, as functions do.

I think this makes things simpler and makes tag handling more in line
with function handling. These two shares similar properties in that both
of them have signatures, but they are kind of nominal so having the same
signature doesn't mean they are the same element.

Also a drive-by fix: the reserved 'attirubute' part's encoding changed
from uleb32 to uint8 a while ago. This was fixed in lib/MC and
lib/Object but not in YAML. This doesn't change object files because the
field's value is always 0 and its encoding is the same for the both
encoding.

This is effectively NFC; I didn't mark it as such just because it
changed YAML test results.

Diff Detail

Event Timeline

aheejin created this revision.Oct 4 2021, 11:52 AM
aheejin requested review of this revision.Oct 4 2021, 11:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2021, 11:52 AM
aheejin edited the summary of this revision. (Show Details)Oct 4 2021, 11:57 AM
aheejin updated this revision to Diff 376978.Oct 4 2021, 12:05 PM

Make incorrect attribute an error

Nice!

lld/wasm/InputFiles.cpp
498

Why have a separate tagTypes() method? Wouldn't be better just add Type o Sig to struct WasmTag?

llvm/include/llvm/BinaryFormat/Wasm.h
121

So is this element of the union is now be used for tags?

aheejin added inline comments.Oct 4 2021, 2:21 PM
lld/wasm/InputFiles.cpp
498

It's not an inherently property of Tag and will become invalidate at linking time. This is the same as how we handle function types now; see one line above.

llvm/include/llvm/BinaryFormat/Wasm.h
121

Yes. Kind above will be different so there will be no way we don't distinguish functions and tags.

sbc100 added inline comments.Oct 4 2021, 4:10 PM
lld/wasm/InputFiles.cpp
498

Just because its going to be re-written/updated by the linker doesn't mean the libObject interface should not expose it directly as part of the Tag.

I'm trying to remember why functionTypes is not part simply embedded the WasmFunction array. Perhaps because there are function types for imported functions as well as defined ones? Actually that is not true since imported functions *do* embed thier signature:

struct WasmImport {                                                                                               
  StringRef Module;                                                              
  StringRef Field;                                                               
  uint8_t Kind;                                                                  
  union {                                                                        
    uint32_t SigIndex;                 <--- here                                             
    WasmGlobalType Global;                                                       
    WasmTableType Table;                                                         
    WasmLimits Memory;                                                           
    WasmTagType Tag;                                                             
  };                                                                             
};

Unless there is some other reason to keep tagTypes separate I suggest you simply embed it them.

aheejin added inline comments.Oct 4 2021, 4:54 PM
lld/wasm/InputFiles.cpp
498

I wondered about that too. Also there are two separate WasmFunctions, to make matters more confusing.. Anyway, I wanted to treat functions and tags consistently. How about doing it for both functions and tags as a followup?

aheejin added inline comments.Oct 4 2021, 5:00 PM
lld/wasm/InputFiles.cpp
498

Oh, you already did that in D111104, thanks. I'll rebase this onto it.

tlively accepted this revision.Oct 5 2021, 11:24 AM

Nice! This looks like a good simplification and matching how function signatures work seems like a good idea.

llvm/lib/Object/WasmObjectFile.cpp
1127–1130

Would it be possible to validate that the signature is within bounds here? I notice the function signatures are not check either, so my guess is that it is not possible to check.

This revision is now accepted and ready to land.Oct 5 2021, 11:24 AM
aheejin updated this revision to Diff 377377.EditedOct 5 2021, 4:06 PM

Rebase onto D111104 and remove WasmObjectFile::tagTypes()

aheejin marked an inline comment as done.Oct 5 2021, 4:14 PM
aheejin added inline comments.
llvm/lib/Object/WasmObjectFile.cpp
1127–1130

I think it's possible. Did that both for functions and tags.

aheejin updated this revision to Diff 377379.Oct 5 2021, 4:15 PM
aheejin marked an inline comment as done.

Check if imported function/tag's sig index is within bounds

sbc100 accepted this revision.Oct 5 2021, 5:01 PM

Not sure if the description needs updating after the simplification?

aheejin edited the summary of this revision. (Show Details)Oct 5 2021, 5:08 PM

Not sure if the description needs updating after the simplification?

The original comment didn't say anything about how we handled SigIndex, so the description is still all valid. I added one sentence:

This instead moves SigIndex to struct WasmTag itself, as we did for struct WasmFunction in D111104.

This revision was automatically updated to reflect the committed changes.