From: shyouhei@... Date: 2021-03-02T06:30:46+00:00 Subject: [ruby-core:102697] [Ruby master Bug#17540] A segfault due to Clang/LLVM optimization on 32-bit ARM Linux Issue #17540 has been updated by shyouhei (Shyouhei Urabe). This is my take: ```patch From 7fb39b1138dfaa3a1502673ac82d6b75401e8f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 2 Mar 2021 15:22:22 +0900 Subject: [PATCH] fix strict aliasing --- internal/object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/object.h b/internal/object.h index aa820128c7..6a5dfcda63 100644 --- a/internal/object.h +++ b/internal/object.h @@ -47,8 +47,8 @@ MJIT_SYMBOL_EXPORT_END static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass) { - struct { VALUE flags; VALUE klass; } *ptr = (void *)obj; - ptr->klass = klass; + VALUE *ptr =(/* const cast */VALUE *) & RBASIC(obj)->klass; + memcpy(ptr, &klass, sizeof(klass)); } static inline void -- 2.17.1 ``` I would like to reflain from fixing this issue by adding compiler-specific `__asm__` or `__attreibute__`, because that does not help everyone... The world is not built on top of LLVM. I don't want to kill support for other compiler infrastructures. It sounds like a nice idea to have `-fno-strict-aliasing`, though. That is just a matter of compiler flag. Must not hurt the codebase. ---------------------------------------- Bug #17540: A segfault due to Clang/LLVM optimization on 32-bit ARM Linux https://bugs.ruby-lang.org/issues/17540#change-90692 * Author: xtkoba (Tee KOBAYASHI) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [armv7a-linux-eabi] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- When built with `optflags=-O3` (which is the default), `ruby -e "pp Thread.main"` causes a segfault, which seems to be worked around by the following change: ``` --- a/include/ruby/internal/fl_type.h +++ b/include/ruby/internal/fl_type.h @@ -231,7 +231,7 @@ RBIMPL_ATTR_PURE_UNLESS_DEBUG() RBIMPL_ATTR_ARTIFICIAL() static inline VALUE -RB_FL_TEST_RAW(VALUE obj, VALUE flags) +RB_FL_TEST_RAW(volatile VALUE obj, VALUE flags) { RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); return RBASIC(obj)->flags & flags; ``` There might be a bug in the optimizer of Clang/LLVM (version 11.0.1). -- https://bugs.ruby-lang.org/ Unsubscribe: