Skip to content

Adjust initial memory to handle asan shadow size #14631

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

Merged
merged 1 commit into from
Jul 13, 2021
Merged

Adjust initial memory to handle asan shadow size #14631

merged 1 commit into from
Jul 13, 2021

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jul 12, 2021

Without this change any user of ALLOW_MEMORY_GROWTH
with asan would get a rather cryptic error message from
the linker:

wasm-ld: error: initial memory too small, 278278624 bytes needed

This is because asan increases the memory requirements in
proportion to the max memory, and the max memory defaults
to 2Gb with ALLOW_MEMORY_GROWTH enabled.

Also, remove check for MAXIMUM_MEMORY == -1 which is no longer
a thing since #14088.

Fixes: #14621

@sbc100 sbc100 requested a review from kripken July 12, 2021 17:03
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Nice!

Without this change any user of ALLOW_MEMORY_GROWTH
with asan would get a rather cryptic error message from
the linker:

 wasm-ld: error: initial memory too small, 278278624 bytes needed

This is because asan increases the memory requirements in
proportion to the max memory, and the max memory defaults
to 2Gb with `ALLOW_MEMORY_GROWTH` enabled.

Also, remove check for `MAXIMUM_MEMORY` == -1 which is no longer
a thing since #14088.

Fixes: #14621
@sbc100 sbc100 merged commit ffdc688 into main Jul 13, 2021
@sbc100 sbc100 deleted the asan_growth branch July 13, 2021 19:07
sbc100 added a commit that referenced this pull request Dec 16, 2021
This bug was caused by miscalculating the adjustments make to TOTAL_MEMORY
and GLOBAL_BASE and using ASan.  The bug was introduced in #14631 and
was causing ASan to write poison values over static data in some cases.

This bug was really only effecting builds without ALLOW_MEMORY_GROWTH
since when ALLOW_MEMORY_GROWTH is enabled that shadow region is very
large and unless users were use a lot of memory it was unlikely ASan
would write to the end of it (and clobber static data).

As well as fixing the calculations, this change also adds a runtime
assert to ensure these regions never overlap (at least not at startup).
This should catch regressions in these calculations.

In order to test this case I removed ALLOW_MEMORY_GROWTH form several
asan and lsan tests.  It should not longer be necessary to set
`ALLOW_MEMORY_GROWTH` or adjust `TOTAL_MEMORY` when using sanitizers
these days.  The `asan` suite in the core tests still uses
`ALLOW_MEMORY_GROWTH`.  As a followup we might want to look into
removing that too.

Fixes: #15762
sbc100 added a commit that referenced this pull request Dec 16, 2021
This bug was caused by miscalculating the adjustments make to TOTAL_MEMORY
and GLOBAL_BASE and using ASan.  The bug was introduced in #14631 and
was causing ASan to write poison values over static data in some cases.

This bug was really only effecting builds without ALLOW_MEMORY_GROWTH
since when ALLOW_MEMORY_GROWTH is enabled that shadow region is very
large and unless users were use a lot of memory it was unlikely ASan
would write to the end of it (and clobber static data).

As well as fixing the calculations, this change also adds a runtime
assert to ensure these regions never overlap (at least not at startup).
This should catch regressions in these calculations.

In order to test this case I removed ALLOW_MEMORY_GROWTH form several
asan and lsan tests.  It should not longer be necessary to set
`ALLOW_MEMORY_GROWTH` or adjust `TOTAL_MEMORY` when using sanitizers
these days.  The `asan` suite in the core tests still uses
`ALLOW_MEMORY_GROWTH`.  As a followup we might want to look into
removing that too.

Fixes: #15762
sbc100 added a commit that referenced this pull request Dec 16, 2021
This bug was caused by miscalculating the adjustments make to TOTAL_MEMORY
and GLOBAL_BASE and using ASan.  The bug was introduced in #14631 and
was causing ASan to write poison values over static data in some cases.

This bug was really only effecting builds without ALLOW_MEMORY_GROWTH
since when ALLOW_MEMORY_GROWTH is enabled that shadow region is very
large and unless users were use a lot of memory it was unlikely ASan
would write to the end of it (and clobber static data).

As well as fixing the calculations, this change also adds a runtime
assert to ensure these regions never overlap (at least not at startup).
This should catch regressions in these calculations.

In order to test this case I removed ALLOW_MEMORY_GROWTH form several
asan and lsan tests.  It should not longer be necessary to set
`ALLOW_MEMORY_GROWTH` or adjust `TOTAL_MEMORY` when using sanitizers
these days.  The `asan` suite in the core tests still uses
`ALLOW_MEMORY_GROWTH`.  As a followup we might want to look into
removing that too.

Fixes: #15762
sbc100 added a commit that referenced this pull request Dec 17, 2021
This bug was caused by miscalculating the adjustments made to TOTAL_MEMORY
and GLOBAL_BASE and using ASan.  The bug was introduced in #14631 and
causes ASan to write poison values over static data in some cases.

This bug was really only effecting builds without ALLOW_MEMORY_GROWTH
since when ALLOW_MEMORY_GROWTH is enabled that shadow region is very
large and unless users were use a lot of memory it was unlikely ASan
would write to the end of it (and clobber static data).

As well as fixing the calculations, this change also adds a runtime
assert to ensure these regions never overlap (at least not at startup).
This should catch regressions in these calculations.

In order to test this case I removed ALLOW_MEMORY_GROWTH form several
asan and lsan tests.  It should not longer be necessary to set
`ALLOW_MEMORY_GROWTH` or adjust `TOTAL_MEMORY` when using sanitizers
these days.  The `asan` suite in the core tests still uses
`ALLOW_MEMORY_GROWTH`.  As a followup we might want to look into
removing that too.

Fixes: #15762
mmarczell-graphisoft pushed a commit to GRAPHISOFT/emscripten that referenced this pull request Jan 5, 2022
…ten-core#15806)

This bug was caused by miscalculating the adjustments made to TOTAL_MEMORY
and GLOBAL_BASE and using ASan.  The bug was introduced in emscripten-core#14631 and
causes ASan to write poison values over static data in some cases.

This bug was really only effecting builds without ALLOW_MEMORY_GROWTH
since when ALLOW_MEMORY_GROWTH is enabled that shadow region is very
large and unless users were use a lot of memory it was unlikely ASan
would write to the end of it (and clobber static data).

As well as fixing the calculations, this change also adds a runtime
assert to ensure these regions never overlap (at least not at startup).
This should catch regressions in these calculations.

In order to test this case I removed ALLOW_MEMORY_GROWTH form several
asan and lsan tests.  It should not longer be necessary to set
`ALLOW_MEMORY_GROWTH` or adjust `TOTAL_MEMORY` when using sanitizers
these days.  The `asan` suite in the core tests still uses
`ALLOW_MEMORY_GROWTH`.  As a followup we might want to look into
removing that too.

Fixes: emscripten-core#15762
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.

INITIAL_MEMORY option is broken
2 participants