Skip to content

Fix ruby.h behaviour in old compilers: __builtin_choose_expr is different before 4.8.5 - #1778

Closed
silviofdez wants to merge 1 commit into
ruby:trunkfrom
silviofdez:trunk
Closed

silviofdez wants to merge 1 commit into
ruby:trunkfrom
silviofdez:trunk

Conversation

@silviofdez

Copy link
Copy Markdown

When trying to install some native gems in a ruby-25-rc1 compiled using 4.8.5 (Centos 7 or Ubuntu 14.04) you get this error related to new functions in ruby.h

gem install nokogiri
Building native extensions. This could take a while...
ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.
    current directory: /bitnami/rubystackDev-linux-x64/output/ruby/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.1/ext/nokogiri
/bitnami/rubystackDev-linux-x64/output/ruby/bin/ruby -r ./siteconf20171218-47665-bs04dc.rb extconf.rb
checking if the C compiler accepts -fPIC -I/bitnami/rubystackDev-linux-x64/output/common/include -fPIC -I/bitnami/rubystackDev-linux-x64/output/common/include -I/bitnami/rubystackDe
v-linux-x64/output/common/include -fPIC -m64 -I/bitnami/rubystackDev-linux-x64/output/ImageMagick/include/ImageMagick-6 -I/bitnami/rubystackDev-linux-x64/output/ImageMagick/include/
ImageMagick-6/wand/ -I/bitnami/rubystackDev-linux-x64/output/ImageMagick/include/ImageMagick-6/MagickCore/ -I/bitnami/rubystackDev-linux-x64/output/ImageMagick/include/ImageMagick-6
 -I/bitnami/rubystackDev-linux-x64/output/ImageMagick/include/ImageMagick-6/wand/ -I/bitnami/rubystackDev-linux-x64/output/ImageMagick/include/ImageMagick-6/MagickCore/... yes
Building nokogiri using system libraries.
checking for xmlParseDoc() in libxml/parser.h... yes
checking for xsltParseStylesheetDoc() in libxslt/xslt.h... yes
checking for exsltFuncRegister() in libexslt/exslt.h... yes
checking for xmlHasFeature()... yes
checking for xmlFirstElementChild()... yes
checking for xmlRelaxNGSetParserStructuredErrors()... yes
checking for xmlRelaxNGSetParserStructuredErrors()... yes
checking for xmlRelaxNGSetValidStructuredErrors()... yes
checking for xmlSchemaSetValidStructuredErrors()... yes
checking for xmlSchemaSetParserStructuredErrors()... yes
creating Makefile
current directory: /bitnami/rubystackDev-linux-x64/output/ruby/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.1/ext/nokogiri
make "DESTDIR=" clean
current directory: /bitnami/rubystackDev-linux-x64/output/ruby/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.1/ext/nokogiri
make "DESTDIR="
compiling html_document.c
In file included from /bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby.h:33:0,
                 from ./nokogiri.h:33,
                 from ./html_document.h:4,
                 from html_document.c:1:
html_document.c: In function ‘new’:
/bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby/ruby.h:2222:12: warning: conversion to ‘int’ from ‘long unsigned int’ may alter its value [-Wconversion]
     ((varc)/(rb_scan_args_count(fmt, varc)))
            ^
/bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby/ruby.h:2230:11: note: in expansion of macro ‘rb_scan_args_verify_count’
  verify = rb_scan_args_verify_count(fmt, varc); \
           ^
/bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby/ruby.h:2345:9: note: in expansion of macro ‘rb_scan_args_verify’
        (rb_scan_args_verify(fmt, varc), vars))
         ^
/bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby/ruby.h:2172:9: note: in expansion of macro ‘rb_scan_args0’
         rb_scan_args0(argc,argvp,fmt,\
         ^
html_document.c:16:3: note: in expansion of macro ‘rb_scan_args’
   rb_scan_args(argc, argv, "0*", &rest);
   ^
In file included from /bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby.h:33:0,
                 from ./nokogiri.h:33,
                 from ./html_document.h:4,
                 from html_document.c:1:
html_document.c: In function ‘read_io’:
/bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby/ruby.h:1767:5: error: first argument to ‘__builtin_choose_expr’ not a constant
     __builtin_choose_expr(__builtin_constant_p(argc), \
     ^
/bitnami/rubystackDev-linux-x64/output/ruby/include/ruby-2.5.0/ruby/ruby.h:2464:6: note: in expansion of macro ‘rb_varargs_argc_check’
      rb_varargs_argc_check(rb_funcall_argc, rb_funcall_nargs), \
      ^
html_document.c:66:28: note: in expansion of macro ‘rb_funcall’
     VALUE encoding_found = rb_funcall(io, id_encoding_found, 0);
                            ^
make: *** [html_document.o] Error 1
make failed, exit code 2
Gem files will remain installed in /bitnami/rubystackDev-linux-x64/output/ruby/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.1 for inspection.
Results logged to /bitnami/rubystackDev-linux-x64/output/ruby/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.1/gem_make.out

This patch just check GCC version and undef the conflicting part.

@shyouhei

Copy link
Copy Markdown
Member

Not tested but seemingly related GCC bug that was fixed in 4.9.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449

@hsbt

hsbt commented Dec 22, 2017

Copy link
Copy Markdown
Member

@silviofdez Can you file this issue with our tracker?

@nurse

nurse commented Dec 22, 2017

Copy link
Copy Markdown
Member

I don't reproduce this with gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16).
https://rubyci.org/logs/rubyci.s3.amazonaws.com/centos7/ruby-trunk/log/20171222T050003Z.log.html.gz

Maybe yum update gcc can solve this.

@silviofdez

Copy link
Copy Markdown
Author

Ticket open on Redmine: https://bugs.ruby-lang.org/issues/14221 @hsbt
I tested it on Centos 7.3 with gcc 4.8.5-11, testing with 7.4 and gcc 4.8.5-16 to check same environments.

@silviofdez

Copy link
Copy Markdown
Author

@nurse I update our environment to Centos 7.4 and gcc 4.8.5-16 and still getting the same error. Both systems and gcc are affected by @shyouhei bug
Given the following code:

#define SHIFTLEFT(a,b) __builtin_choose_expr(__builtin_constant_p(b), \
      ((a) << (b)), \
      ((a) << (MIN(31,MAX(-31,(b))))))

int foo(int a, int b) { return SHIFTLEFT (a, b); }

the compiler will error:

gcc -O4 gcctest.c 
gcctest.c: In function `foo':
gcctest.c:5: error: first argument to __builtin_choose_expr not a constant

@nurse

nurse commented Dec 23, 2017

Copy link
Copy Markdown
Member

I understand this issue is because the compiler which is used to build ruby (and config.h) is different from gcc 4.8.x which is now using to build nokogiri.
How to avoid this issue is under consideration...

matzbot pushed a commit that referenced this pull request Dec 23, 2017
GCC 4.8 with optimization causes error if it compiles following code.
[Bug #14221]

```c
__builtin_choose_expr(__builtin_constant_p(b),0,1)
```

#1778

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
@nurse

nurse commented Dec 23, 2017

Copy link
Copy Markdown
Member

98bddfe fixes this issue

@nurse nurse closed this Dec 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants