question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data section offsets

See original GitHub issue

Problem

There are currently two methods of encoding a Data Section entry into the binary. These are

  • const hello: i32 = 'Hello World!'; - static strings
  • const array: i32[] = [1, 2, 3, 4]; - static array/raw data regions

In both cases the data is encoded into the data section such that it’ll take up the first available offset in memory.

The data sections in the WASM spec allow for an explicit offset. An example of this can be seen in the reference spec tests for data section here.

Goal

Define and implement a syntax for allowing an explicit offset to be defined when defining data sections in Walt.

Possible syntax:

A pseudo function call

const memory: Memory = { initial: 1 };
const string: i32 = memory.data(1024 /* offset */, 'Hello World!' /* value */);

This would require for altering the grammar to allow for top-level function calls, as well as some guards on calling non memory.data() function calls.

A static object

const string: i32 = { offset: 1024, value: 'Hello World!' };

This would work great for strings but not so well for static arrays. Also, having an object property(offset) not be part of the object is very odd.

???

Maybe there is an additional way to define this which would make sense, but it does seem like having the memory involved in some way makes the most sense. Especially since in the future it will be possible to have N > 1 memories in a single binary.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
elifarleycommented, Nov 2, 2018

And here’s another suggestion…

const memory: Memory = Memory.allocate({ initial: 1, number: 1 });
const hello32: i32[] = memory.view({offset: 40}); // starts at position 40
const array64: i64[] = memory.view(); // starts at 0

hello32 = 'Hello!';

array64 = [1, 2, 3, 4];

0reactions
ballercatcommented, Nov 23, 2018

Yup, the compiler already supports extensions. All of the current features are written as internal (enabled by default) language extensions and grammar. There is a reference implementation of closures as a plugin to demonstrate how a complex extension could be made and injected into a compiler.

I’ll probably make a package (similar to babel presents) for all experimental-* features for these type of changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Segments and Offsets - UMBC Computer Science
The linker forces all of the code (.CODE directive), all of the data (.DATA directive) and stack (.STACK) portions into a single segment...
Read more >
How can I get the offset and data from the text section of a ...
There must be a way to find the offset of this data section (local label .LAES_Te and .LAES_Td) from global label AES_cbc_encrypt so...
Read more >
Offset data and attribute - IBM
Offset data is used exclusively with area variables. The value of an offset variable indicates the location of a based variable within an...
Read more >
In IDA what does db and dd offset means in data section?
dd means “define double-word” (4 bytes of memory). The offset prefix means to fill the reserved byte(s) not with the mentioned data itself...
Read more >
Offset (computer science) - Wikipedia
In computer science, an offset within an array or other data structure object is an integer indicating the distance (displacement) between the beginning...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found