Skip to content

Native BE compatibility #1417

Closed
Closed

Description

@saghul

After we removed cross-endian bytecode support in #1412, I tested native builds with Docker (s930x) and looks like native BE is currently broken, due to the bytecode checksum?

src/quickjs # ./build/qjs
SyntaxError: checksum error

Supporting cross-endian builds is no longer a goasl, but I guess native BE builds are, so we should fix it I guess.

Activity

  1. saghul commented on Mar 21, 2026

    @saghul
    ContributorAuthor
  2. added a commit that references this issue on Mar 21, 2026
  3. past-due commented on Mar 21, 2026

    @past-due
    Contributor

    My two cents:

    I know there is reluctance to taking the “defining the endianness of the bytecode format as little-endian and handling for big-endian targets” approach (as @chqrlie mentioned in option 1 here). I do think it’s a shame, although I understand the maintainability concern.

    For some background: we cross-compile an open source game that embeds QuickJS for a number of scenarios. Fortunately, and perhaps expectedly, all of our current cross-compilation scenarios are little-endian hosts and little-endian targets. However I do want to raise some general concerns:

    1. Even if cross-compiling between different-endian architectures is officially not supported going forward, I’d hope that general cross-compiling continues to be considered a fully supported scenario.

    2. We do have some people compiling our project for big-endian architectures, and thus we want to ensure that there isn’t any sort of undetected-at-compile-time failure here due to using the pre-generated codegen files in this scenario.

    Right now, it appears as though codegen only happens if using the make codegen command (?), and not as part of the CMake or Meson buildsystems. At a minimum, assuming the decision remains to not support cross-endian compilation, I think that compilation of targets including pre-compiled bytecode should fail if the pre-compiled bytecode files do not match the target endianness.

    However, what about the scenario where the QuickJS compiler executable, which is required to generate the pre-compiled bytecode, itself increasingly relies on pre-compiled bytecode?

  4. saghul commented on Mar 21, 2026

    @saghul
    ContributorAuthor
    1. Even if cross-compiling between different-endian architectures is officially not supported going forward, I’d hope that general cross-compiling continues to be considered a fully supported scenario.

    Yes, nothing has changed there. Bytecode is not host dependent, but it is endian dependent.

    2. We do have some people compiling our project for big-endian architectures, and thus we want to ensure that there isn’t any sort of undetected-at-compile-time failure here due to using the pre-generated codegen files in this scenario.

    You'd have a problem there. You'd need to regenerate the codegen for BE.

    Right now, it appears as though codegen only happens if using the make codegen command (?), and not as part of the CMake or Meson buildsystems. At a minimum, assuming the decision remains to not support cross-endian compilation, I think that compilation of targets including pre-compiled bytecode should fail if the pre-compiled bytecode files do not match the target endianness.

    Not sure how we'd do that at compile time. Any ideas?

    However, what about the scenario where the QuickJS compiler executable, which is required to generate the pre-compiled bytecode, itself increasingly relies on pre-compiled bytecode?

    It doesn't and likely won't, otherwise we'd have a bootstrapping issue regardless of endianness, since bytecode versions are not compatible.

  5. barracuda156 commented on Mar 21, 2026

    @barracuda156
    Contributor

    Not sure how we'd do that at compile time. Any ideas?

    If what is meant are official releases, then it is trivial, since endianness of included bytecode is known. The same would apply to packaging by downstream distributions. Are there any scenarios where inputs are unknown?

  6. added a commit that references this issue on Mar 21, 2026
  7. saghul commented on Mar 21, 2026

    @saghul
    ContributorAuthor

    Not sure how we'd do that at compile time. Any ideas?

    If what is meant are official releases, then it is trivial, since endianness of included bytecode is known. The same would apply to packaging by downstream distributions. Are there any scenarios where inputs are unknown?

    I don't think so.

    Btw master now properly works on BE. You need to run make codegen before make to have the bytecode regenerated and that's it.

  8. barracuda156 commented on Mar 22, 2026

    @barracuda156
    Contributor

    Great, thank you

  9. barracuda156 commented on Jun 13, 2026

    @barracuda156
    Contributor

    @saghul I was going to update to the latest release, and now got a question: does codegen target depend on quickjs itself?

    quickjs/Makefile

    Lines 76 to 85 in 66adc82

    codegen: $(QJSC)
    $(QJSC) -ss -o gen/repl.c -m repl.js
    $(QJSC) -ss -o gen/standalone.c -m standalone.js
    $(QJSC) -e -o gen/function_source.c tests/function_source.js
    $(QJSC) -e -o gen/hello.c examples/hello.js
    $(QJSC) -e -o gen/hello_module.c -m examples/hello_module.js
    $(QJSC) -e -o gen/test_fib.c -m examples/test_fib.js
    $(QJSC) -C -ss -o builtin-array-fromasync.h builtin-array-fromasync.js
    $(QJSC) -C -ss -o builtin-iterator-zip.h builtin-iterator-zip.js
    $(QJSC) -C -ss -o builtin-iterator-zip-keyed.h builtin-iterator-zip-keyed.js

    How to build it correctly? I cannot require quickjs-ng to build quickjs-ng, obviously, though it is possible in principle to have a bootstrap port. But then, bootstrap port will need to be pegged to some old version which can be compiled without running codegen. And perhaps eventually it will not be able to generate current sources.
    Or do I get this wrong?

    Also, it will be nice – though not necessary – to have the thing working with CMake directly.

  10. barracuda156 commented on Jun 13, 2026

    @barracuda156
    Contributor

    Upd. I guess codegen can be inserted after building quickjsc manually, and before building quickjs.

  11. saghul commented on Jun 13, 2026

    @saghul
    ContributorAuthor

    Yep codegen just needs the compiler, which uses the engine, but doesn't depend on generated bytecode itself.

  12. barracuda156 commented on Jun 13, 2026

    @barracuda156
    Contributor

    Thanks. Does something prevent adding this into CMake logic, conditional on platform being BE? I.e. so that nothing changes for LE, but on BE direct build without manual steps works correctly?

  13. saghul commented on Jun 13, 2026

    @saghul
    ContributorAuthor

    I'd review a PR, but last I tried it made things too complex for cross compiling, for example.

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