Граф коммитов

552 Коммитов

Автор SHA1 Сообщение Дата
JP Camara 8782e02138 KQueue support for M:N threads
* Allows macOS users to use M:N threads (and technically FreeBSD, though it has not been verified on FreeBSD)

* Include sys/event.h header check for macros, and include sys/event.h when present

* Rename epoll_fd to more generic kq_fd (Kernel event Queue) for use by both epoll and kqueue

* MAP_STACK is not available on macOS so conditionall apply it to mmap flags

* Set fd to close on exec

* Log debug messages specific to kqueue and epoll on creation

* close_invalidate raises an error for the kqueue fd on child process fork. It's unclear rn if that's a bug, or if it's kqueue specific behavior

Use kq with rb_thread_wait_for_single_fd

* Only platforms with `USE_POLL` (linux) had changes applied to take advantage of kernel event queues. It needed to be applied to the `select` so that kqueue could be properly applied

* Clean up kqueue specific code and make sure only flags that were actually set are removed (or an error is raised)

* Also handle kevent specific errnos, since most don't apply from epoll to kqueue

* Use the more platform standard close-on-exec approach of `fcntl` and `FD_CLOEXEC`. The io-event gem uses `ioctl`, but fcntl seems to be the recommended choice. It is also what Go, Bun, and Libuv use

* We're making changes in this file anyways - may as well fix a couple spelling mistakes while here

Make sure FD_CLOEXEC carries over in dup

* Otherwise the kqueue descriptor should have FD_CLOEXEC, but doesn't and fails in assert_close_on_exec
2023-12-20 16:23:38 +09:00
Jeremy Evans 7dca6b53a9
Add tool/missing-baseruby.bat, used when BASERUBY not available
Previously, the embedded semicolon in BASERUBY if BASERUBY is
not available breaks tarball builds without BASERUBY when using
OpenBSD make, due to the inability to escape MFLAGS correctly.
This moves the same BASERUBY code into a separate file, avoiding
the MFLAGS quoting issue.

BASERUBY must be passed to build-ext because it is required
by ripper since the introduction of lrama.

Fixes [Bug #19683]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-12-19 21:30:47 -08:00
Takashi Kokubun eb872d1752 RJIT: Share rb_vm_insns_count for vm_insns_count 2023-12-18 23:55:40 -08:00
Nobuyoshi Nakada 2c2c6bc3fa
Fix `ARCH_FLAG` when cross-compiling on macOS 2023-12-15 15:19:16 +09:00
Takashi Kokubun 0f1c7e3bcb
RJIT: Just skip generating code for aarch64/arm64 (#9221) 2023-12-13 09:36:06 -08:00
Nobuyoshi Nakada 75f4a687ed
Fix a typo for `RJIT_TARGET_OK` (#8222) 2023-12-12 23:28:22 -08:00
Nobuyoshi Nakada 1cba1b3992
Check `windres` message using the found `windres` only if needed 2023-11-24 20:00:13 +09:00
Pierrick Bouvier 784fdecc4c
windows-arm64 support (#8995)
* [win32] fix compilation for windows-arm64

Credits to MSYS2 Ruby package using this patch.

* [win32] nm use full options

Fix compilation error when using MSYS2 environment.
Credits to MSYS2 Ruby package using this patch.

* [win32] detect llvm-windres (used for windows-arm64)

When adding preprocessor option for llvm-windres (using clang as
parameter), it fails. Thus, do not add this.

It's needed to be able to compile windows-arm64 version, because MSYS2
toolchain is LLVM based (instead of GCC/binutils).

* [win32] pioinfo detection for windows-arm64

This fixes "unexpected ucrtbase.dll" for native windows-arm64 ruby
binary. It does not solve issue with x64 version emulated on this
platform.

Value of pioinfo pointer can be found in ucrtbase.dll at latest adrp/add
sequence before return of _isatty function. This works for both release
and debug ucrt.

Due to the nature of aarch64 ISA (vs x86 or x64), it's needed to
disassemble instructions to retrieve offset value, which is a bit more
complicated than matching specific string patterns.

Details about adrp/add usage can be found in this blog post:
https://devblogs.microsoft.com/oldnewthing/20220809-00/?p=106955
For instruction decoding, the Arm documentation was used as a reference.
2023-11-23 17:17:28 +09:00
Hiroshi SHIBATA f100c6477a
[Bug #20004] Revert "[Feature #19422] Enable shared by default on macOS"
This reverts commit 9694445051.

  This change broke our release CI.

  https://github.com/ruby/actions/actions/runs/6599016994/job/17927644579#step:16:44

  Invoking `/Users/runner/work/actions/actions/snapshot-master/ruby -rrubygems /Users/runner/work/actions/actions/snapshot-master/bin/gem --backtrace build lib/bundler/bundler.gemspec` failed with output:
  ----------------------------------------------------------------------
  dyld[42417]: Library not loaded: '/usr/local/lib/libruby.3.3.dylib'
    Referenced from: '/Users/runner/work/actions/actions/snapshot-master/ruby'
    Reason: tried: '/usr/local/lib/libruby.3.3.dylib' (no such file), '/usr/lib/libruby.3.3.dylib' (no such file)
  ----------------------------------------------------------------------
2023-11-21 20:21:18 +09:00
Nobuyoshi Nakada 22939382a8 [Bug #18286] Make builtin binary if sharable in universal binaries 2023-11-09 16:01:01 +09:00
Nobuyoshi Nakada 40d40a651e Revert "Disable iseq-dumped builtin module for universal x86_64/arm64 binaries"
This reverts commit 1d5598fe0d.
2023-11-09 16:01:01 +09:00
Ben Hamilton 1d5598fe0d Disable iseq-dumped builtin module for universal x86_64/arm64 binaries
During the build, Ruby has special logic to serialize its own builtin
module to disk using the binary iseq format during the build (I assume
for speed so it doesn't have to parse builtin every time it starts
up).

However, since iseq format is architecture-specific, when building on
x86_64 for universal x86_64 + arm64, the serialized builtin module is
written with the x86_64 architecture of the build machine, which fails
this check whenever ruby imports the builtin module on arm64:

1fdaa06660/compile.c (L13243)

Thankfully, there's logic to disable this feature for cross-compiled builds:

1fdaa06660/builtin.c (L6)

This disables the iseq logic for universal builds as well.

Fixes [Bug #18286]
2023-11-09 12:24:01 +09:00
Nobuyoshi Nakada 6031fdc632
Select proper dsymutil for gcc 13 2023-11-07 23:19:51 +09:00
Nobuyoshi Nakada f8456b650b
Ignore duplicate libraries warnings from gcc 13 2023-11-07 23:19:50 +09:00
Nobuyoshi Nakada 642875e474
[Bug #19967] Revert "configure.ac: LIBPATHENV on macOS"
This reverts commit 1961c786aa.  These
environment variables should no longer propagate to child processes.
2023-10-21 14:05:21 +09:00
Nobuyoshi Nakada aee1bfd88e
Get rid of `set` with empty argument which dumps all definitions 2023-10-17 15:48:05 +09:00
Koichi Sasada 55c5ebe0a0 disable MN threads on s390s-linux
I check the s390s-linux/Ubuntu system and I found that MN threads
doesn't work with:

* function inlining (-O0 doesn't repro)
* Thread local specifier (`_Thread_local`.
  With `pthread_get_specific works)
  (it is not an issue of `__tls_get_addr()` written in thread.c)
* swap context with ucontext (coroutine/ucontext)

I couldn't find out what is the root cause of this issue but
disable MN threads to make CI healthy.
2023-10-15 04:35:17 +09:00
Nobuyoshi Nakada 96cd73d78f
Ignore symbols even in empty shared library
On some platforms, such as FreeBSD and Oracle Linux, symbols defined
in the crt0 setup routine are exported from shared libraries.  So
ignore the symbols that would be exported even in an empty shared
library.
2023-10-14 18:38:24 +09:00
Nobuyoshi Nakada 9694445051
[Feature #19422] Enable shared by default on macOS 2023-10-12 19:26:07 +09:00
Koichi Sasada be1bbd5b7d M:N thread scheduler for Ractors
This patch introduce M:N thread scheduler for Ractor system.

In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.

From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.

Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.

There are additional settings by environment variables:

`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).

`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).

This patch will be reverted soon if non-easy issues are found.

[Bug #19842]
2023-10-12 14:47:01 +09:00
Nobuyoshi Nakada bcb3247072
[Bug #19778] Pass additional include options to INCFLAGS in common.mk 2023-09-17 19:18:23 +09:00
Jean Boussier efe2822708 Process.warmup: invoke `malloc_trim` if available
Similar to releasing free GC pages, releasing free malloc pages
reduce the amount of page faults post fork.
2023-09-15 17:45:21 +02:00
Nobuyoshi Nakada fe0225ff4d [Bug #19778] Add `-I` options for opt-dir to `$INCFLAGS`
These options have been separated from `$CFLAGS` already in the
other places.
2023-09-15 13:27:19 +09:00
Nobuyoshi Nakada abd0b9b28a
Exclude `-Wmisleading-indentation` when `-save-temps`
That option may be triggered wrongly by pre-processed files.
2023-09-06 14:06:26 +09:00
Nobuyoshi Nakada 5c98ee02d2
Define bounds-checking interfaces macro for each file 2023-08-27 00:12:03 +09:00
Jeremy Evans b635388a90 Check that __builtin_mul_overflow can handle long long
Fixes [Bug #17646]

Patch from xtkoba (Tee KOBAYASHI)
2023-08-24 20:47:23 -07:00
Nobuyoshi Nakada d26b015e83 [Bug #19831] Remove duplicate library options
`$(LIBRUBYARG_SHARED)` is included in `$(LIBS)` in extension
libraries.
2023-08-17 16:30:01 +09:00
Nobuyoshi Nakada f339937abb RJIT: Remove macros inherited from MJIT but no longer used 2023-08-17 08:33:52 +09:00
Nobuyoshi Nakada 47b1a52826
Split installation from build section 2023-08-16 08:40:43 +09:00
Nobuyoshi Nakada d9d4ae511a
Group configure outputs on GitHub Actions 2023-08-15 23:30:41 +09:00
Hiroshi SHIBATA a642a94b68
llvm-objcopy is not provided by Xcode Command Line Tools.
Revert "Disable YJIT if objcopy command is old"

  This reverts commit 75f8781c08.
2023-07-07 09:28:27 +09:00
Nobuyoshi Nakada 75f8781c08
Disable YJIT if objcopy command is old
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-07-06 21:16:00 +09:00
Jemma Issroff 9614a61379 Fixed build scripts for YARP 2023-07-05 16:58:55 -04:00
Takashi Kokubun f2c367734f Introduce --enable-rjit=disasm 2023-04-27 14:27:51 -07:00
Takashi Kokubun 0bf10dfd25 Avoid linking capstone by default
Workaround for https://github.com/ruby/setup-ruby/pull/501#issuecomment-1520722486
2023-04-24 12:54:33 -07:00
Nobuyoshi Nakada 038f9ade3c
Use tools appropriate with CC
To get rid of mysterious errors such as:

```
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: error: libruby.3.3-static.a(/): The end of the file was unexpectedly encountered
```

and

```
ld: warning: ignoring file ../../libruby.3.3-static.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture x86_64:
  "_rb_rational_num", referenced from:
```
2023-04-09 22:47:26 +09:00
Nobuyoshi Nakada 08324ab9eb
Include `--no-llvm-bc` option in `NM` macro only if usable 2023-04-08 12:47:27 +09:00
Nobuyoshi Nakada f99af43980 [Bug#19161] Detect thread local storage specifier
Checking by `__STDC_VERSION__` is unreliable because old gcc 4.8
supports `-std=gnu11` option but does not implement `_Thread_local`.
Check the implementation directly instead.
2023-04-07 13:42:48 +09:00
Jeremy Evans 466ca7ae20 Add Dir.fchdir
This is useful for passing directory file descriptors over UNIX
sockets or to child processes to avoid TOCTOU vulnerabilities.

The implementation follows the Dir.chdir code.

This will raise NotImplementedError on platforms not supporting
both fchdir and dirfd.

Implements [Feature #19347]
2023-03-24 11:18:57 -07:00
Nobuyoshi Nakada ed4dc1c33d
Fix ENABLE_MULTIARCH
This macro is used in `ruby_init_loadpath()`, but was removed
mistakenly at 31f4b2d86b.
2023-03-24 01:46:59 +09:00
Takashi Kokubun 51834ff2ec
YJIT: Make dev_nodebug closer to dev (#7570) 2023-03-20 13:03:22 -07:00
Takashi Kokubun 39cd74d2a0 RJIT: Use RJIT_STATS on --enable-rjit=dev
RUBY_DEBUG is too slow.
2023-03-17 23:17:26 -07:00
Takashi Kokubun ac47b8df8f
Bump the required BASERUBY version to 2.5 (#7504)
[Misc #16671]

I'd like to bump it to 2.7 to use pattern matching in
tool/mk_builtin_loader.rb.

However, I experienced a few blockers. 2.5 seems like the closest
version that is easy enough to use on CIs, so let me bump the version to
it as an intermediate step for it. I want to use &. and <<~ in 2.3 too.

Known blockers:
* AppVeyor Visual Studio 2015 doesn't have Ruby 2.7. You'd need to bump
  the version to Visual Studio 2019.
* GitHub Actions windows-2019 doesn't have Ruby 2.7 either. You
  can use ruby/setup-ruby, but configure doesn't seem to work with it.
* For ruby/ruby-ci-imaage, bionic doesn't have Ruby 2.7. I tried using
  ruby-build to build Ruby 2.7 from package, but the build on its CI
  seems to somehow loop forever when I do that. So I gave it up for now.
  We might want to wait until bionic becomes EOL.

Note:
* AppVeyor Visual Studio 2015 has Ruby <= 2.6.3
  https://www.appveyor.com/docs/windows-images-software/#ruby
* GitHub Actions windows-2019 uses Ruby 2.5.9
  https://github.com/actions/runner-images/blob/main/images/win/Windows2019-Readme.md
2023-03-10 23:40:22 -08:00
Takashi Kokubun d5b7c8a972 RJIT: Always enable --rjit-dump-disasm 2023-03-10 11:29:25 -08:00
Nobuyoshi Nakada 96d1acfdf6
[Bug #19161] Check for TLS usability
On all platforms using GCC, even other than darwin.
2023-03-09 13:54:50 +09:00
Takashi Kokubun 9df1f58e01 Link libcapstone no matter what cargo does
libcapstone used to break when it's linked from C and Rust at the same
time, but it doesn't seem to happen anymore. Maybe it's related to
recent symbol hygiene changes. Thank you if that's the case.

This commit allows you to make both --enable-rjit=dev and
--enable-yjit=dev work in the same binary.
2023-03-07 22:58:11 -08:00
Takashi Kokubun 6d91df08b5
Allow enabling YJIT and RJIT independently (#7474)
We used to require MJIT is supported when YJIT is supported. However,
now that RJIT dropped some platforms that YJIT supports, it no longer
makes sense. We should be able to enable only YJIT, and vice versa.
2023-03-07 22:43:37 -08:00
Takashi Kokubun 23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun b2130d5f5d Remove obsoleted tool/mjit_tabs.rb 2023-03-06 22:53:38 -08:00