emscripten-core / emscripten-core/emscripten
{{{ GLOBAL_BASE }}} is incorrect when building with STACK_FIRST enabled
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
`lib.js`
```js
mergeInto(LibraryManager.library, {
get_global_base: function() {
return {{{ GLOBAL_BASE }}};
}
});
```
`test.cpp`
```c
#include
#include
const int data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
const int zero[128] = {};
extern "C" void *emscripten_global_base();
int main()
{
printf("GLOBAL_BASE: %p\n", emscripten_global_base());
printf("data: %p\n", (void*)&data[0]);
printf("zero: %p\n", (void*)&zero[0]);
printf("emscripten_stack_get_base: %p\n", (void*)emscripten_stack_get_base());
printf("emscripten_stack_get_end: %p\n", (void*)emscripten_stack_get_end());
}
```
```
em++ --js-library lib.js test.cpp -o test.js
```
prints
```
GLOBAL_BASE: 0x400
data: 0x5000a0
zero: 0x5000e0
emscripten_stack_get_base: 0x500000
emscripten_stack_get_end: 0
```
i.e. showing that `GLOBAL_BASE` would be in the middle of the program stack. Looks like `GLOBAL_BASE` is not getting adjusted for stack_first case properly?
Contributor guide
Assessment
This issue has not been assessed yet.