From 45b4344c56d7e6fad726b73fc407f8b75f579fe4 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Thu, 19 Jan 2023 15:13:22 -0800 Subject: [PATCH] (PA-4844) Patch the autogenerated selinux C extension Calling into selinux from Ruby 3.2 generates a warning: selinux.so: warning: undefining the allocator of T_DATA class swig_runtime_data This is because ruby 3.2 requires C extensions to "either use rb_define_alloc_func() to overwrite it or rb_undef_alloc_func() to delete it."[1] The selinux C extension selinuxswig_ruby_wrap.c is autogenerated by swig from the selinuxswig_i template. swig 4.1.1 contains the fix for this[2] but we are using an older version on RHEL7. So patch the autogenerated C extension, which needs to happen after the code is generated and before it's compiled. [1] https://github.com/ruby/ruby/blob/6963f8f743b42f9004a0879cd66c550f18987352/doc/extension.rdoc#label-Write+the+C+Code [2] https://github.com/swig/swig/commit/962f0900018ecb10287b327d261e424fa5ccb755 --- configs/components/_base-ruby-selinux.rb | 15 ++++++++++++--- .../ruby-selinux/selinuxswig_ruby_wrap.patch | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 resources/patches/ruby-selinux/selinuxswig_ruby_wrap.patch diff --git a/configs/components/_base-ruby-selinux.rb b/configs/components/_base-ruby-selinux.rb index 82d314471..e13753d74 100644 --- a/configs/components/_base-ruby-selinux.rb +++ b/configs/components/_base-ruby-selinux.rb @@ -3,6 +3,8 @@ # load it with instance_eval. See ruby-x.y-selinux.rb configs. # +pkg.add_source("file://resources/patches/ruby-selinux/selinuxswig_ruby_wrap.patch") + # These can be overridden by the including component. ruby_version ||= settings[:ruby_version] host_ruby ||= settings[:host_ruby] @@ -42,16 +44,23 @@ end pkg.build do - [ + steps = [ "export RUBYHDRDIR=$(shell #{ruby} -e 'puts RbConfig::CONFIG[\"rubyhdrdir\"]')", "export VENDORARCHDIR=$(shell #{ruby} -e 'puts RbConfig::CONFIG[\"vendorarchdir\"]')", "export ARCHDIR=$${RUBYHDRDIR}/$(shell #{ruby} -e 'puts RbConfig::CONFIG[\"arch\"]')", "export INCLUDESTR=\"-I#{settings[:includedir]} -I$${RUBYHDRDIR} -I$${ARCHDIR}\"", "cp -pr src/{selinuxswig_ruby.i,selinuxswig.i} .", - "swig -Wall -ruby #{system_include} -o selinuxswig_ruby_wrap.c -outdir ./ selinuxswig_ruby.i", + "swig -Wall -ruby #{system_include} -o selinuxswig_ruby_wrap.c -outdir ./ selinuxswig_ruby.i" + ] + + if ruby_version =~ /^3/ + steps << "#{platform.patch} --strip=0 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../selinuxswig_ruby_wrap.patch" + end + + steps.concat([ "#{cc} $${INCLUDESTR} #{system_include} #{cflags} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -fPIC -DSHARED -c -o selinuxswig_ruby_wrap.lo selinuxswig_ruby_wrap.c", "#{cc} $${INCLUDESTR} #{system_include} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -shared -o _rubyselinux.so selinuxswig_ruby_wrap.lo -lselinux -Wl,-z,relro,-z,now,-soname,_rubyselinux.so", - ] + ]) end pkg.install do diff --git a/resources/patches/ruby-selinux/selinuxswig_ruby_wrap.patch b/resources/patches/ruby-selinux/selinuxswig_ruby_wrap.patch new file mode 100644 index 000000000..28b7999a5 --- /dev/null +++ b/resources/patches/ruby-selinux/selinuxswig_ruby_wrap.patch @@ -0,0 +1,10 @@ +--- selinuxswig_ruby_wrap.c.orig 2023-01-18 22:38:21.527547362 -0800 ++++ selinuxswig_ruby_wrap.c 2023-01-18 22:38:26.887569066 -0800 +@@ -1724,6 +1724,7 @@ + { + /* register a new class */ + VALUE cl = rb_define_class("swig_runtime_data", rb_cObject); ++ rb_undef_alloc_func(cl); + /* create and store the structure pointer to a global variable */ + swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer); + rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);