Skip to content

Conversation

@pinotree
Copy link
Contributor

@pinotree pinotree commented Jun 3, 2025

This PR fixes the build of quickjs on GNU/Hurd:

  • use malloc_usable_size() when using glibc
  • use ftello() & fseeko() when using glibc (they could be used more, I took a conservative approach)
  • use JS__PATH_MAX instead of PATH_MAX in common code
  • implement os.exePath
  • set os.platform as hurd

See the messages of the various commits for longer explanations.

A couple of changes are cherry-picked (with the needed changes) from bellard/quickjs#316.

pinotree added 5 commits June 3, 2025 07:53
malloc_usable_size() is a GNU extension in GNU libc; hence, use it
every time GNU libc is used, rather than only on Linux.

Cherry-pick of bellard/quickjs@3489493.
Strictly speaking, they are available in POSIX.1-2008 [1][2], so they
could be used on more platforms/OSes. To be cautious, enable them when
using GNU libc, since they have been available with that libc for a
very long time.

Cherry-pick of bellard/quickjs@8624b5c.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftell.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
PATH_MAX is optional in POSIX, and it is not available on GNU/Hurd.
There is already a fallback definition called JS__PATH_MAX, so switch
all the common code (i.e. not the bits specific to a certain OS) to use
it.
There is a Linux-like procfs that provides /proc/self/exe, so use the
Linux implementation of js_exepath() also on GNU/Hurd.
This makes it possible to detect quickjs is running on GNU/Hurd.
Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

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

These changes will break musl. I suggest chaging #if defined(__linux__) || defined(__GLIBC__) to #if defined(__linux__) && !defined(__GNU__)

@pinotree
Copy link
Contributor Author

pinotree commented Jun 3, 2025

These changes will break musl.

Not sure why they would. __GLIBC__ is defined by the headers of GNU libc, and my changes add additional OR'ed cases to allow what's currently under Linux to also any OS based on GNU libc.

I suggest chaging #if defined(__linux__) || defined(__GLIBC__) to #if defined(__linux__) && !defined(__GNU__)

This is exactly the opposite of what is needed for GNU/Hurd. The current Linux paths for js__malloc_usable_size are actually for GNU libc (musl implements them for compatibility, IIRC), and thus they apply to GNU/Hurd as well (which uses GNU libc).

Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

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

Sorry for the noise, I misread the code! LGTM!

@saghul saghul merged commit 9d0380b into quickjs-ng:master Jun 4, 2025
127 checks passed
@pinotree pinotree deleted the hurd branch June 4, 2025 06:24
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.

2 participants