Skip to content

Defines with \0 included in them are incorrect in memory starting with 6.0.4 #27619

Description

@rsielken

Please include the following in your bug report:

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 6.0.8 (aeb6792)
Copyright (C) 2026 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

But working back through https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md, this started in 6.0.4. Therefore, I'd suspect it is caused by "llvm-libc was updated to LLVM 22.1.8. (#27374)"

Failing command line in full:
Runtime failure.

Full link command and output with -v appended:

em++ -DEMSDK -DMOBILE -DOPENGL -DREACT_INFOBOX -DNO_DYNAMIC_LOADING -DMOBILE_NSL -DMOBILE_NFL -pthread -s PROXY_TO_PTHREAD=1 -s PTHREAD_POOL_SIZE=16 -s FETCH=1 -s FETCH_SUPPORT_INDEXEDDB=0 -s FULL_ES2=1 -s USE_FREETYPE=1 -s USE_LIBPNG=1 -s DISABLE_EXCEPTION_CATCHING=0 -s INITIAL_MEMORY=268435456 -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s OFFSCREEN_FRAMEBUFFER=1 -s ABORT_ON_WASM_EXCEPTIONS=1 -s EXIT_RUNTIME=1 -s LEGACY_RUNTIME=1 -s MIN_SAFARI_VERSION=-1 -s STACK_SIZE=5MB -s EXPORTED_RUNTIME_METHODS='HEAPU8,HEAPU32,lengthBytesUTF8,stringToUTF8' -s WASMFS  -DGCC3 -DGCC4 -fno-strict-aliasing -DGCC_LBLB_NOT_SUPPORTED -Wno-int-conversion -Wno-dynamic-exception-spec -Wno-register -Wno-incompatible-function-pointer-types -g2 -r   -Wl,--whole-archive,--unresolved-symbols=ignore-all

Note: Where possible, please avoid attaching screen shots of code or console
logs. Instead, please include them as text so that they may be copied /
searched. To make code blocks more readable and syntax highlighted, please
escape them with three backticks before and after, like this:

#define NEWUSER_LOOKUPITEMS "MailServer\0MailFile\0MailDomain\0MailSystem\0Profiles"
#define NEWUSER_MAILSERVERITEM	0
#define NEWUSER_MAILFILEITEM	1
#define NEWUSER_MAILDOMAINITEM  2
#define NEWUSER_MAILSYSTEMITEM	3
#define NEWUSER_PROFILEITEM		4
#define NEWUSER_LOOKUPITEMCOUNT 5

But at runtime, when I look at the memory at NEWUSER_LOOKUPITEMS, I have "MailServer\0" as expected, but the memory that follows is other stuff and not the "MailFile\0MailDomain\0MailSystem\0Profiles" it should be. The callee is expecting these other values (and that is what the caller thinks it is passing when it passes NEWUSER_LOOKUPITEMS), and doesn't return the expected items which then causes other problems done the line.

In the code there are multiple defines like NEWUSER_LOOKUPITEMS that start with "MailServer\0" but then have other values after that. It is as if some optimization (although I'm using -O0 to try to avoid any of that in my testing) thinks that it only needs "MailServer\0" and the rest after the zero can be ignored. So, it points all my defines that start with "MailServer\0" to the same memory which is incorrect.

If I run with 6.0.3, the memory looks as expected.

I spent hours and plenty of CoPilot tokens trying to create a recreateable scenario, but it continually failed. I'm sure it is related to our real project being quite large with many .o files and libs are eventually linked together. I tried all sorts of combinations of breaking up the defines across models, but I couldn't get it to fail. So, I'm giving up on that path (at least for now) and just reporting what I know. It recreates consistently for me, so I could test an EMSDK build to debug, but I can't give you our whole product's source code which is the only way I can recreate the issue at this point.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions