Skip to content

Commit

Permalink
internal/wasm: stub linking section
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Nov 30, 2024
1 parent 7482c5c commit fdd3c77
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions internal/wasm/section.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package wasm

import (
"bytes"

"go.bytecodealliance.org/internal/wasm/uleb128"
)

// SectionID represents a WebAssembly [section SectionID].
//
// [section SectionID]: https://webassembly.github.io/spec/core/binary/modules.html#sections
Expand Down Expand Up @@ -47,6 +53,34 @@ func (*CustomSection) SectionID() SectionID {

// SectionContents implements the [Section] interface.
func (s *CustomSection) SectionContents() ([]byte, error) {
// TODO: encode name correctly
return append([]byte(s.Name), s.Contents...), nil
var buf bytes.Buffer
_, err := WriteString(&buf, s.Name)
if err != nil {
return nil, err
}
_, err = buf.Write(s.Contents)
return buf.Bytes(), err
}

type LinkingSection struct{}

// SectionID implements the [Section] interface.
func (*LinkingSection) SectionID() SectionID {
return SectionCustom
}

// SectionContents implements the [Section] interface.
func (s *LinkingSection) SectionContents() ([]byte, error) {
var buf bytes.Buffer
custom := &CustomSection{Name: "linking"}
contents, err := custom.SectionContents()
if err != nil {
return nil, err
}
_, err = buf.Write(contents)
if err != nil {
return nil, err
}
_, err = uleb128.Write(&buf, 2) // linking section version 2
return buf.Bytes(), err
}

0 comments on commit fdd3c77

Please sign in to comment.