summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2023-02-23 13:31:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2023-11-09 12:24:01 +0900
commit1d5598fe0d3470e7cab06a756d40a9221fcd501b (patch)
tree61f2e96db175d16ddd1bbc140e6235a3fd46b830
parenta168426881480e0f07d75c5f830fb749c3b05249 (diff)
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: https://github.com/ruby/ruby/blob/1fdaa0666086529b3aae2d509a2e71c4247c3a12/compile.c#L13243 Thankfully, there's logic to disable this feature for cross-compiled builds: https://github.com/ruby/ruby/blob/1fdaa0666086529b3aae2d509a2e71c4247c3a12/builtin.c#L6 This disables the iseq logic for universal builds as well. Fixes [Bug #18286]
-rw-r--r--builtin.c2
-rw-r--r--common.mk2
-rw-r--r--configure.ac2
-rw-r--r--template/Makefile.in1
-rw-r--r--template/builtin_binary.inc.tmpl2
5 files changed, 6 insertions, 3 deletions
diff --git a/builtin.c b/builtin.c
index aef5b2c2d4..ba412dddbc 100644
--- a/builtin.c
+++ b/builtin.c
@@ -3,7 +3,7 @@
#include "iseq.h"
#include "builtin.h"
-#ifdef CROSS_COMPILING
+#if defined(CROSS_COMPILING) || defined(UNIVERSAL_BINARY)
#define INCLUDED_BY_BUILTIN_C 1
#include "mini_builtin.c"
diff --git a/common.mk b/common.mk
index 2732a1ea4a..15226654dd 100644
--- a/common.mk
+++ b/common.mk
@@ -1303,7 +1303,7 @@ preludes: {$(srcdir)}golf_prelude.c
builtin_binary.inc: $(PREP) $(BUILTIN_RB_SRCS) $(srcdir)/template/builtin_binary.inc.tmpl
$(Q) $(MINIRUBY) $(tooldir)/generic_erb.rb -o $@ \
- $(srcdir)/template/builtin_binary.inc.tmpl -- --cross=$(CROSS_COMPILING)
+ $(srcdir)/template/builtin_binary.inc.tmpl -- --cross=$(CROSS_COMPILING) --universal=$(UNIVERSAL_BINARY)
$(BUILTIN_RB_INCS): $(top_srcdir)/tool/mk_builtin_loader.rb
diff --git a/configure.ac b/configure.ac
index bf6d9af1f1..2ac47609fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4367,6 +4367,8 @@ AS_IF([test "${universal_binary-no}" = yes ], [
AC_DEFINE_UNQUOTED(RUBY_PLATFORM_OS, "${target_os}")
AC_DEFINE_UNQUOTED(RUBY_ARCH, "universal-" RUBY_PLATFORM_OS)
AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "universal." RUBY_PLATFORM_CPU "-" RUBY_PLATFORM_OS)
+ AC_DEFINE(UNIVERSAL_BINARY, 1)
+ AC_SUBST(UNIVERSAL_BINARY, yes)
], [
AS_IF([test "${target_os}-${rb_cv_msvcrt}" = "mingw32-ucrt" ], [
arch="${target_cpu}-mingw-ucrt"
diff --git a/template/Makefile.in b/template/Makefile.in
index 93fa02d9d7..e06834e4ca 100644
--- a/template/Makefile.in
+++ b/template/Makefile.in
@@ -65,6 +65,7 @@ rubyarchhdrdir = @rubyarchhdrdir@
ruby_version = @ruby_version@
RUBY_VERSION_NAME = @RUBY_VERSION_NAME@
UNIVERSAL_ARCHNAMES = @UNIVERSAL_ARCHNAMES@
+UNIVERSAL_BINARY = @UNIVERSAL_BINARY@
TESTUI = console
TESTS =
diff --git a/template/builtin_binary.inc.tmpl b/template/builtin_binary.inc.tmpl
index 2c2f071705..86ea34970b 100644
--- a/template/builtin_binary.inc.tmpl
+++ b/template/builtin_binary.inc.tmpl
@@ -2,7 +2,7 @@
// DO NOT MODIFY THIS FILE DIRECTLY.
// auto-generated file by tool/generic_erb.rb
// with template/builtin_binary.inc.tmpl
-% unless ARGV.include?('--cross=yes')
+% unless ARGV.include?('--cross=yes') || ARGV.include?('--universal=yes')
% ary = RubyVM.enum_for(:each_builtin).to_a
% ary.each{|feature, iseq|