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

601 Коммитов

Автор SHA1 Сообщение Дата
KJ Tsanaktsidis 731805ddde Add an explicit check for broken libunwind builds
Libunwind as packaged in MacOS cannot actually unwind code which has
pointer authentication on, because _LIBUNWIND_IS_NATIVE_ONLY is not
defined. Add a check for this, and prefer building with working
unwinding over pointer authentication if we must make a choice.
2024-09-06 16:51:19 -04:00
Peter Zhu 2865148a5a Revert "Check for both aarch64 and arm64 arch's for pac-ret"
This reverts commit 6a746e1bc9.

This patch breaks the C level backtrace on macOS ARM machines.
2024-09-06 16:51:19 -04:00
KJ Tsanaktsidis 6a746e1bc9 Check for both aarch64 and arm64 arch's for pac-ret
Linux calls it aarch64, but MacOS calls it arm64; pac-ret works on both.
2024-08-22 17:35:43 +10:00
Nobuyoshi Nakada 6ab591f80a
[Bug #20687] Check if base ruby provides necessary libraries 2024-08-21 16:56:44 +09:00
Raed Rizqie 703305bd03 Revert soname changes
- only i386-ucrt soname is changed to fix building on x86 clang
- fix detection of x86intrin.h on x86 system
- mingw does not have LIBRUBY_SONAME
2024-08-16 17:42:59 +09:00
Lars Kanis eedf6c35b3
Revert change of "mingw-ucrt" platform string
... of commit 00176cd40f.

The reverted change was made only for constistency, as discussed in
  https://github.com/ruby/ruby/pull/11358#issuecomment-2282222369

But the platform string "mingw-ucrt" should not be changed.
It is used as RUBY_PLATFORM and as the rubygems platform, so that there should
be a good reason to change the name of an established platform.
"mingw-ucrt" was introduced intentionally in commit
576b2e64cd.

Related to GH-11358
2024-08-12 21:48:29 -04:00
Raed Rizqie 00176cd40f fix ucrt arch 2024-08-11 00:10:28 +09:00
Takashi Kokubun 2de8b5b805
YJIT: Allow dev_nodebug to disasm release-mode code (#11198)
* YJIT: Allow dev_nodebug to disasm release-mode code

* Revert "YJIT: Squash canary before falling back"

This reverts commit f05ad373d8.
The stray canary issue should have been solved by
def7023ee4, alleviating this codegen
accommodation.

* s/runtime_assertions/runtime_checks/

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2024-07-18 13:01:47 -07:00
Nobuyoshi Nakada e722f4c57f Stop using `sigsetjmp` to hijack SIGCHLD handler
It already has been dead code.
Follow up of 65d3eacc80.
2024-07-16 18:41:42 +09:00
Kazuhiro NISHIYAMA b01cf8ccde
Fix a typo
[Misc #20636]
2024-07-16 11:40:50 +09:00
KJ Tsanaktsidis b940de83de Revert autoconf macros defining RUBY_AARCH64_{BTI|PAC}_ENABLED
This partially reverts https://github.com/ruby/ruby/pull/10944; now that
we decided to pass CFLAGS to $(CC) when assembling .S files, we don't
need these autoconf macros that capture the state of
__ARM_FEATURE{PAC|BTI}_DEFAULT.

[Bug #20601]
2024-07-07 20:14:44 +10:00
KJ Tsanaktsidis b18701a7ae Remove $(ASFLAGS) from build system and assemble with $(CFLAGS) instead
We already assemble our assembly files using the $(CC) compiler driver,
rather than the actual $(AS) assembler. This means that

* The C preprocessor gets run on the assembly file
* It's valid to pass gcc-style flags to it, like e.g.
  -mbranch-protection or -fcf-protection
* If you do so, the relevant preprocessor macros like __CET__ get set
* If you really wanted to pass assembler flags, you would need to do
  that using -Wa,... anyway

So I think it makes sense to pass "$(XCFLAGS) $(CFLAGS) $(CPPFLAGS)" to
gcc/clang/etc when assembling, rather than passing $(ASFLAGS) (since
the flags are not actually passed to `as`, but `cc`!).

The side effect of this is that if there are mitigation flags like
-fcf-protection in $CFLAGS, then the relevant macros like __CET__ will
be defined when assembling the files.

[Bug #20601]
2024-07-07 20:14:44 +10:00
Peter Zhu e2ceded2c6 Change external GC to use directory at configure
This commit changes the external GC API to use `--with-shared-gc=DIR` at
configure time with a directory of the external GC and uses
`RUBY_GC_LIBRARY` environment variable to load the external GC at
runtime.
2024-07-05 14:05:58 -04:00
Ivo Anjo 64fef3b870 Add explicit compiler fence when pushing frames to ensure safe profiling
**What does this PR do?**

This PR tweaks the `vm_push_frame` function to add an explicit compiler
fence (`atomic_signal_fence`) to ensure profilers that use signals
to interrupt applications (stackprof, vernier, pf2, Datadog profiler)
can safely sample from the signal handler.

**Motivation:**

The `vm_push_frame` was specifically tweaked in
https://github.com/ruby/ruby/pull/3296 to initialize the a frame
before updating the `cfp` pointer.

But since there's nothing stopping the compiler from reordering
the initialization of a frame (`*cfp =`) with the update of the cfp
pointer (`ec->cfp = cfp`) we've been hesitant to rely on this on
the Datadog profiler.

In practice, after some experimentation + talking to folks, this
reordering does not seem to happen.

But since modern compilers have a way for us to exactly tell them
not to do the reordering (`atomic_signal_fence`), this seems even
better.

I've actually extracted `vm_push_frame` into the "Compiler Explorer"
website, which you can use to see the assembly output of this function
across many compilers and architectures: https://godbolt.org/z/3oxd1446K

On that link you can observe two things across many compilers:
1. The compilers are not reordering the writes
2. The barrier does not change the generated assembly output
   (== has no cost in practice)

**Additional Notes:**

The checks added in `configure.ac` define two new macros:
* `HAVE_STDATOMIC_H`
* `HAVE_DECL_ATOMIC_SIGNAL_FENCE`

Since Ruby generates an arch-specific `config.h` header with
these macros upon installation, this can be used by profilers
and other libraries to test if Ruby was compiled with the fence enabled.

**How to test the change?**

As I mentioned above, you can check https://godbolt.org/z/3oxd1446K
to confirm the compiled output of `vm_push_frame` does not change
in most compilers (at least all that I've checked on that site).
2024-07-03 18:08:57 +09:00
Nobuyoshi Nakada d122a68863
Exported symbols in DLL on Windows are managed by win32/mkexports.rb 2024-06-22 18:48:14 +09:00
Yuta Saito 73b7eebf07 build: fix crossruby build by handling empty `ac_abs_builddir`
`ac_abs_builddir` can be empty when the build is top-level (not
subdirs, and Ruby is usually the case). In such case, the MINIRUBY is
expanded to `$RUBY -I -r'$(arch)-fake'`, which interprets `-r$(arch)-fake`
as an argument to `-I` option. This led to:
- Not loading the fake config file
- Then not setting `CROSS_COMPILING` constant during extmk.rb execution
- Then misusing cross-compiled `./miniruby` instead of baseruby to generate
  files used in exts.

This commit fixes the issue by handling the empty `ac_abs_builddir` case
properly.
2024-06-22 15:12:00 +09:00
Nobuyoshi Nakada cab0d03037
Get rid of nesting backquotes
Also executing variable containing an option may not be portable.
Follow up of dd378c5a24.
2024-06-22 10:58:32 +09:00
Nobuyoshi Nakada dd378c5a24
Expand --with-opt-dir arguments 2024-06-22 02:16:16 +09:00
Yusuke Endoh ac9e84df3d Support LCOV 2.0
LCOV 2.0, a GCOV frontend, seems to have stricter error checking
2024-06-21 14:48:44 +09:00
ydah 2eb31a6254 Fix a typo
s/sepcifier/specifier/
2024-06-12 15:45:06 +09:00
KJ Tsanaktsidis 0ccb80d6bf Extract hardening CFLAGS to a special $hardenflags variable
This changes the automatic detection of -fstack-protector,
-D_FORTIFY_SOURCE, and -mbranch-protection to write to $hardenflags
instead of $XCFLAGS. The definition of $cflags is changed to
"$hardenflags $orig_cflags $optflags $debugflags $warnflags" to match.

Furthermore, these flags are _prepended_ to $hardenflags, rather than
appended.

The implications of doing this are as follows:

* If a CRuby builder specifies cflags="-mbranch-protection=foobar" at
  the ./configure script, and the configure script detects that
  -mbranch-protection=pac-ret is accepted, then GCC will be invoked as
  "gcc -mbranch-protection=pac-ret -mbranch-protection=foobar". Since
  the last flags take precedence, that means that user-supplied values
  of these flags in $cflags will take priority.
* Likewise, if a CRuby builder explicitly specifies
  "hardenflags=-mbranch-protection=foobar", because we _prepend_ to
  $hardenflags in our autoconf script, we will still invoke GCC as
  "gcc -mbranch-protection=pac-ret -mbranch-protection=foobar".
* If a CRuby builder specifies CFLAGS="..." at the configure line,
  automatic detection of hardening flags is ignored as before.
* C extensions will _also_ be built with hardening flags now as well
  (this was not the case by default before because the detected flags
  went into $XCFLAGS).

Additionally, as part of this work, I changed how the detection of
PAC/BTI in Context.S works. Rather than appending the autodetected
option to ASFLAGS, we simply compile a set of test programs with the
actual CFLAGS in use to determine what PAC/BTI settings were actually
chosen by the builder. Context.S is made aware of these choices through
some custom macros.

The result of this work is that:

* Ruby will continue to choose some sensible defaults for hardening
  options for the C compiler
* Distributors are able to specify CFLAGS that are consistent with their
  distribution and override these defaults
* Context.S will react to whatever -mbranch-protection is actually in
  use, not what was autodetected
* Extensions get built with hardening flags too.

[Bug #20154]
[Bug #20520]
2024-06-11 20:48:55 +10:00
Nobuyoshi Nakada 906a86e4de
Use `dllexport` as `RUBY_FUNC_EXPORTED` on Windows 2024-06-09 16:55:27 +09:00
Jeremy Evans 029d92b898 Disable __builtin_setjmp usage on linux-aarch64
It is questionable whether __builtin_setjmp should default to yes
at all, but since it appears to still have problems on this platform,
it seems safest to disable it.

Fixes [Bug #14480]
2024-06-06 15:46:41 -07:00
Nobuyoshi Nakada 5308da5e1c
Add dependencies of configure.ac 2024-06-01 14:21:45 +09:00
Nobuyoshi Nakada a41e6f3873
GCC LD does not support `.debug_macinfo` yet
Lower debug info level if it is warned, not checks with werror_flag to
fail due to this warning.
2024-05-29 17:40:59 +09:00
Nobuyoshi Nakada 5fa6ba9568 [Bug #20500] Search non-default directories for jemalloc
Co-Authored-by: lish82 (Hiroki Katagiri)
2024-05-23 13:16:48 +09:00
Nobuyoshi Nakada 1e08a9f0e9 [Bug #20499] Use Xcode owned tools for Xcode clang
Xcode has its own version tools that may be incompatible with genuine
LLVM tools, use the tools in the same directory.
2024-05-22 13:49:05 +09:00
Hiroshi SHIBATA f8e6752219
Revert "[Bug #20499] Use consistent version tools with CC"
This reverts commit 8277cf0799.

This change break to build with `rbenv install ruby-dev` with the following error.

```
touch yjit/target/release/libyjit.a
transdb.h updated
./tool/darwin-ar: line 6: /nm: No such file or directory
./tool/darwin-ar: line 6: exec: /nm: cannot execute: No such file or directory
partial linking yjit/target/release/libyjit.a into yjit/target/release/libyjit.o
```
2024-05-22 10:45:02 +09:00
Nobuyoshi Nakada 8277cf0799
[Bug #20499] Use consistent version tools with CC
As Apple Xcode is relocatable and selectable with `xcode-select`, use
consistent versions of commands in the same location.
2024-05-21 17:03:34 +09:00
Nobuyoshi Nakada fa26ef5bf7 Fix the end of "compiler section" 2024-05-20 13:54:08 +09:00
Nobuyoshi Nakada 18eaf0be90 [Bug #20494] Search non-default directories for GMP
Co-Authored-by: lish82 (Hiroki Katagiri)
2024-05-20 13:54:08 +09:00
卜部昌平 bb5a538207 use of stdckdint.h
C23 is going to have this header.  The industry is already moving
towards accepting it; OSes and compilers started to implement theirs.

Why not detect its presence and if any, prefer over other ways.

See also:

- https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf
- https://reviews.freebsd.org/D41734
- https://reviews.llvm.org/D157331
- https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8441841a1b985d68245954af1ff023db121b0635
2024-04-27 21:55:28 +09:00
Nobuyoshi Nakada 7951b349ab
Suppress useless linker warnings totally on macOS 2024-04-19 16:33:16 +09:00
Matt Valentine-House a2ea4ec30c Add --with-shared-gc build flag 2024-04-15 19:50:47 +01:00
Nobuyoshi Nakada 66bfcba587 Not all `nm`s support the `--help` option 2024-04-16 01:57:22 +09:00
Nobuyoshi Nakada 3ac6a03b2e
Revert "hijack SIGCHLD handler for internal use"
This reverts commit 054a412d54.
SIGCHLD `waidpid`, `waitpid_lock` and related code, have been removed
at ruby/ruby#7527.
2024-04-04 21:48:14 +09:00
Matt Valentine-House 5903fdf43e
[DOC] Fix wheather -> whether typos in configure. 2024-04-02 21:53:56 +09:00
Nobuyoshi Nakada 376ae22235
Manage required baseruby version in one place
Add a Ruby script mode to `tool/missing-baseruby.bat` that checks if
`RUBY_VERSION` meets the required version.  This will enable similar
checks on mswin as well.
2024-03-31 00:54:38 +09:00
Nobuyoshi Nakada f697d3242f
Manage required baseruby version in one place 2024-03-30 18:34:45 +09:00
Nobuyoshi Nakada 0fb39ab1b9
Clean intermediate files and debug info for each target
By replacing `ALLOBJS` suffix with intermediate file suffixes instead
of roughly removing by wildcards.  Made `cleanlibs` append `.dSYM`
suffix for each word in `TARGET_SO`, not the end of the entire list.
2024-03-10 22:12:00 +09:00
Nobuyoshi Nakada b543a4e9da
Remove `-f` option for `codesign`
Recent `codesign` seems to emit a "replacing existing signature"
warning even if it was an adhoc signature added by the linker.  Since
"adhoc" signatures do not cause a failure when replaced, it is just
unnecessary and noisy.
2024-03-06 20:17:44 +09:00
Yuta Saito b000e7bb74 configure.ac: Append `POSTLINK` to `LINK_SO` for all platforms
The `POSTLINK` variable had been used only for darwin platforms, but
it's now used for WebAssembly/WASI as well. To make shared extension
libraries properly post-processed, we need to append `POSTLINK` to
`LINK_SO` but it was done only for darwin platforms. This commit
generalizes the appending to all platforms.
2024-03-02 17:07:37 +09:00
Yuta Saito 6e2880b388 [wasm-pic] Add `LDSHARED` definition for WASI platform
We are going to add dynamic linking support for WASI platform. The
`LDSHARED` definition is used to link shared libraries for building ruby
binaries and extensions.
2024-03-01 03:16:59 +09:00
Yuta Saito 3f633e57ac [wasm-pic] Remove --pass-arg=asyncify-ignore-imports from POSTLINK
Before PIC era, we could assume that the stack is not unwound by
imported functions since all imported functions are WASI syscalls and
they don't use Asyncify at all. However, PIC binary can import functions
from other modules and we cannot guarantee that they won't unwind
the stack.
2024-02-29 19:57:49 +09:00
Nobuyoshi Nakada 87c4c6c082
Install binary executable files to architecture dependent path 2024-02-18 15:07:42 +09:00
Takashi Kokubun bc7266c5ce
Bump the required BASERUBY version to 3.0 (#9976) 2024-02-15 23:13:45 -08:00
Takashi Kokubun b4ed5b7dfe
Bump the required BASERUBY version to 2.7 (#9566)
[[Misc #16671]](https://bugs.ruby-lang.org/issues/16671)
2024-01-16 15:54:17 -08:00
Yuta Saito 02973b78f4 [Bug #20085] Use consistent default options for `-mbranch-protection`
We need to use the same options for both C compiler and assembler
when `-mbranch-protection` is guessed by configure. Otherwise,
`coroutine/arm64/Context.{h,S}` will use incompatible PAC strategies.
2023-12-28 12:20:50 +09:00
Nobuyoshi Nakada 2a4a84664a [Bug #20088] Fix ARCH_FLAG for cross compiling 2023-12-27 19:11:54 +09:00
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