Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/m0081 meja 2367 linear mem and sni review #1186

Open
wants to merge 25 commits into
base: feature/M0081MEJA-2367_managedc
Choose a base branch
from

Conversation

frivieremicroej
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@frivieremicroej frivieremicroej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, it is unclear to me how to configure the linear memory for microej


Given the following Wasm module:

.. code:: wat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When possible, I prefer to keep managed C here instead of wat file.
how to we define the number of pages using clang ?


Wasm linear memory is a contiguous, byte-addressable memory region used in Wasm programs.
It is the main mechanism through which a Wasm module manages its memory and exchanges data with :ref:`the host <managedc.communication.managedc_memory>`.
This memory is represented as an array of bytes, indexed starting at zero, and is :ref:`dynamically resizable <managedc.instructions.partially_supported>`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our case this is false (see memory.grow), and maybe this is in fact a feature and we will let it as-is.
To be reworded in this direction.


To minimize the size of allocated memory, a Wasm module should:

* Export the the Wasm global ``__heap_base``, using the linker option ``-Wl,--export=__heap_base`` like the following Wasm module,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, how to we reduce the page with clang ?
Is it using the clang compiler: -z stack-size=n, but in this case does it only affect the first page ?

(export "__heap_base" (global $heap_base))
)

* Avoid using the ``memory.size`` and ``memory.grow`` instructions (do not use malloc/free function in the Managed C code).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really ? OK maybe only for this example


The boundary between the auxiliary stack + the Static Data regions and the heap region is marked by the special Wasm global ``__heap_base``

Wasm Linear Memory Size
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Wasm Linear Memory Size
Configure the Wasm Linear Memory Size

(export "memory" (memory $mem))
)

This linear memory of this module should have an initial Size of **2 pages** (128 KiB), and a maximum Size of **10 pages** (640 KiB).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This linear memory of this module should have an initial Size of **2 pages** (128 KiB), and a maximum Size of **10 pages** (640 KiB).
This linear memory of this module should have an initial size of **2 pages** (128 KB), and a maximum Size of **10 pages** (640 KB).

Wasm Linear Memory Size
-----------------------

WebAssembly organizes linear memory in pages, where each page is **64 KiB** (65,536 bytes).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WebAssembly organizes linear memory in pages, where each page is **64 KiB** (65,536 bytes).
WebAssembly organizes linear memory in pages, where each page is **64 KB** (65,536 bytes).

"updated": 1736414807618,
"link": null,
"locked": false,
"text": "Grow downward",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"text": "Grow downward",
"text": "Grows downward",

"updated": 1736414789926,
"link": null,
"locked": false,
"text": "Grow upward",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"text": "Grow upward",
"text": "Grows upward",

Build Without The Standard Library
----------------------------------

The ``-nostdlib`` flag is a linker option used to exclude the standard library when building a program.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-nostdlib is not enough
We should put back the full compilet command line here

    [path_to_wasi_sdk]/bin/clang -Wl,--no-entry -Wl,--export-all -Wl,--allow-undefined -nostdlib -o my_app.wasm my_app.o

@@ -34,14 +36,14 @@ In the terminal, navigate to the ``src/main/c`` directory and execute the follow

.. code:: console

[path_to_wasi_sdk]/bin/clang -Wl,--no-entry -Wl,--export-all -Wl,--allow-undefined -nostdlib -o my_app.wasm my_app.o
[path_to_wasi_sdk]/bin/clang -Wl,--export-all -o my_app.wasm my_app.o
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put back --no-entry and -Wl,--allow-undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants