[rubygems/rubygems] Generate native gems with -fvisibility=hidden

I recently ran into very nasty issues with dynamic symbols clashing between
two native gems.

I believe the overwhelming majority of native gems don't want to export
their symbols, so hidding them by default would make sense to me.

https://github.com/rubygems/rubygems/commit/449624aa54
This commit is contained in:
Jean Boussier 2023-03-24 14:30:19 +01:00 committed by git
parent c08fe40872
commit 276f4be96d
3 changed files with 10 additions and 1 deletions

View File

@ -2,4 +2,9 @@
require "mkmf"
# Makes all symbols private by default to avoid unintended conflict
# with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
# selectively, or entirely remove this flag.
$CFLAGS << " -fvisibility=hidden "
create_makefile(<%= config[:makefile_path].inspect %>)

View File

@ -2,7 +2,7 @@
VALUE rb_m<%= config[:constant_array].join %>;
void
RUBY_FUNC_EXPORTED void
Init_<%= config[:underscored_name] %>(void)
{
rb_m<%= config[:constant_array].join %> = rb_define_module(<%= config[:constant_name].inspect %>);

View File

@ -9,5 +9,9 @@ Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes
Style/GlobalVars:
Exclude:
- ext/**/extconf.rb
Layout/LineLength:
Max: 120