aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-19 18:27:48 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-11-09 16:01:01 +0900
commite2ef85b1090d8806f6b68e2fa93d929d02e543b5 (patch)
tree65aa532df0d37659f71bdd6ae7358d892f29529a /compile.c
parent61bb5c0572cf8c35fb8f3b3accfb301df13d61da (diff)
downloadruby-e2ef85b1090d8806f6b68e2fa93d929d02e543b5.tar.gz
Finer granularity IBF dependendency
It depends on only `VALUE` definition. Check for endianness and word size instead of the platform name.
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index 970ab45fbe..e2ab0075d6 100644
--- a/compile.c
+++ b/compile.c
@@ -11076,6 +11076,14 @@ typedef uint32_t ibf_offset_t;
#define IBF_MINOR_VERSION ISEQ_MINOR_VERSION
#endif
+static const char IBF_ENDIAN_MARK =
+#ifdef WORDS_BIGENDIAN
+ 'b'
+#else
+ 'l'
+#endif
+ ;
+
struct ibf_header {
char magic[4]; /* YARB */
uint32_t major_version;
@@ -11087,6 +11095,8 @@ struct ibf_header {
uint32_t global_object_list_size;
ibf_offset_t iseq_list_offset;
ibf_offset_t global_object_list_offset;
+ uint8_t endian;
+ uint8_t wordsize; /* assume no 2048-bit CPU */
};
struct ibf_dump_buffer {
@@ -13211,7 +13221,6 @@ rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
ibf_dump_setup(dump, dump_obj);
ibf_dump_write(dump, &header, sizeof(header));
- ibf_dump_write(dump, RUBY_PLATFORM, strlen(RUBY_PLATFORM) + 1);
ibf_dump_iseq(dump, iseq);
header.magic[0] = 'Y'; /* YARB */
@@ -13220,6 +13229,8 @@ rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
header.magic[3] = 'B';
header.major_version = IBF_MAJOR_VERSION;
header.minor_version = IBF_MINOR_VERSION;
+ header.endian = IBF_ENDIAN_MARK;
+ header.wordsize = (uint8_t)SIZEOF_VALUE;
ibf_dump_iseq_list(dump, &header);
ibf_dump_object_list(dump, &header.global_object_list_offset, &header.global_object_list_size);
header.size = ibf_dump_pos(dump);
@@ -13355,8 +13366,11 @@ ibf_load_setup_bytes(struct ibf_load *load, VALUE loader_obj, const char *bytes,
rb_raise(rb_eRuntimeError, "unmatched version file (%u.%u for %u.%u)",
header->major_version, header->minor_version, IBF_MAJOR_VERSION, IBF_MINOR_VERSION);
}
- if (strcmp(load->global_buffer.buff + sizeof(struct ibf_header), RUBY_PLATFORM) != 0) {
- rb_raise(rb_eRuntimeError, "unmatched platform");
+ if (header->endian != IBF_ENDIAN_MARK) {
+ rb_raise(rb_eRuntimeError, "unmatched endian: %c", header->endian);
+ }
+ if (header->wordsize != SIZEOF_VALUE) {
+ rb_raise(rb_eRuntimeError, "unmatched word size: %d", header->wordsize);
}
if (header->iseq_list_offset % RUBY_ALIGNOF(ibf_offset_t)) {
rb_raise(rb_eArgError, "unaligned iseq list offset: %u",