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

aot: avoid possible relocations around "stack_sizes" for indirect mode #2322

Merged
merged 4 commits into from Jun 29, 2023

Conversation

yamt
Copy link
Collaborator

@yamt yamt commented Jun 27, 2023

Fixes #2316

Lightly tested on riscv64 qemu.

== 13 * sizeof(uint64) + 128 + 11 * sizeof(uint64));
bh_static_assert(offsetof(AOTModuleInstance, global_table_data)
== 13 * sizeof(uint64) + 128 + 12 * sizeof(uint64));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'm not happy to break offsets.
should i add the new member after the variable parts of the structure?

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding new fields in the WASMModuleInstance/AOTModuleInstance may cause compatibility issue: the AOT code also use pre-calculated offsets to access the global data and table instance (which are at the end of AOTModuleInstance and are allocated together with AOTModuleInstance), these offsets will change if new field is inserted, and the old AOT file (generated by older wamrc) won't run well with the new runtime.

How about adding the aot_stack_sizes into exec_env, after field native_stack_top_min:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/common/wasm_exec_env.h#L91

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is there a longer term plan about compatibility breakage?
like having a flag day for #2144 when we can clean up these things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i moved it to aot inst extra.

Copy link
Contributor

Choose a reason for hiding this comment

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

is there a longer term plan about compatibility breakage? like having a flag day for #2144 when we can clean up these things?

Yes, we hope to upgrade the AOT file format in the GC AOT feature and don't support the old AOT file format again after the feature is implemented. The GC AOT is supposed to be finished in this year, and we may merge it into main branch sometime this year.

yamt added 2 commits June 28, 2023 15:38
by moving aot_stack_sizes from aot inst to inst extra
@@ -88,6 +88,7 @@ typedef struct AOTFunctionInstance {
} AOTFunctionInstance;

typedef struct AOTModuleInstanceExtra {
const uint32 *stack_sizes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Had better use DefPointer(const uint32 *, stack_sizes)? Suppose the aot code may access more fields here in the future, we can ensure the offsets of these fields are fixed, and are the same in compilation time and execution time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 346 to 350
LLVMValueRef offset = I32_CONST(offset_u32);
if (!offset) {
goto fail;
}
LLVMValueRef stack_sizes_p =
Copy link
Contributor

Choose a reason for hiding this comment

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

Had better declare the variables at the beginning of code piece { ... }. And had better add empty lines if needed. We usually keep that coding style to make the code easier to read.
For example, there is no empty line from L342 to L402, a little intensive:)

Copy link
Collaborator Author

@yamt yamt Jun 29, 2023

Choose a reason for hiding this comment

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

i generally feel less lines are easier to read. but ok. i will follow your style.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

yamt added 2 commits June 29, 2023 13:49
not really necessary at this point. but just in case.
Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

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

LGTM

@no1wudi
Copy link
Collaborator

no1wudi commented Jun 29, 2023

LGTM

@wenyongh wenyongh merged commit 03418ef into bytecodealliance:main Jun 29, 2023
368 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

an alternate "indirect" way to find "stack_sizes" is necessary for xip
3 participants