-
Notifications
You must be signed in to change notification settings - Fork 221
dlmalloc: require __heap_end #394
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
Changes from 4 commits
2f59c61
f5f2d77
1cc8c8f
adc74d7
01cac38
fd9a8ce
aa35d19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5215,7 +5215,7 @@ static void internal_inspect_all(mstate m, | |
|
||
/* Symbol marking the end of data, bss and explicit stack, provided by wasm-ld. */ | ||
extern char __heap_base; | ||
extern char __heap_end __attribute__((__weak__)); | ||
extern char __heap_end; | ||
|
||
/* Initialize the initial state of dlmalloc to be able to use free memory between __heap_base and initial. */ | ||
static void try_init_allocator(void) { | ||
|
@@ -5227,23 +5227,16 @@ static void try_init_allocator(void) { | |
|
||
char *base = &__heap_base; | ||
// Try to use the linker pseudo-symbol `__heap_end` for the initial size of | ||
// the heap, but if that's not defined due to LLVM being too old perhaps then | ||
// round up `base` to the nearest `PAGESIZE`. The initial size of linear | ||
// memory will be at least the heap base to this page boundary, and it's then | ||
// assumed that the initial linear memory image was truncated at that point. | ||
// While this reflects the default behavior of `wasm-ld` it is also possible | ||
// for users to craft larger linear memories by passing options to extend | ||
// beyond this threshold. In this situation the memory will not be used for | ||
// dlmalloc. | ||
// | ||
// Note that `sbrk(0)`, or in dlmalloc-ese `CALL_MORECORE(0)`, is specifically | ||
// not used here. That captures the current size of the heap but is only | ||
// correct if the we're the first to try to grow the heap. If the heap has | ||
// grown elsewhere, such as a different allocator in place, then this would | ||
// incorrectly claim such memroy as our own. | ||
// the heap. | ||
char *end = &__heap_end; | ||
if (end == NULL) | ||
end = (char*) page_align((size_t) base); | ||
if (end == NULL) { | ||
// This can happen when 1. you are using an old wasm-ld which doesn't | ||
|
||
// provide `__heap_end` and 2. something (other libraries or maybe | ||
// your app?) provide a weak reference to `__heap_end`. | ||
|
||
// | ||
// Note: This is a linker bug: https://github.com/llvm/llvm-project/issues/60829 | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just remove this block and assume llvm/llvm-project#60829 has been closed (and its really inconceivable to me that somebody would provide a weak definition of this (internal) symbol). If you want to keep some kind of check then perhaps just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
i actually have seen such a code. dump these values for diagnostic purposes.
it's rare for users to use wasi-libc w/o NDEBUG. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But I don't think we want to support that configuration, right? Why would somebody weakly define a linker-internal symbol? Can you point to the place where you have seen this? Maybe just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
diagnostic purposes.
not open source.
i feel it's too early to assume https://reviews.llvm.org/D144747 |
||
size_t initial_heap_size = end - base; | ||
|
||
/* Check that initial heap is long enough to serve a minimal allocation request. */ | ||
|
Uh oh!
There was an error while loading. Please reload this page.