Bug 1402516

Summary: boost spirit lexer is broken on ppc64
Product: Red Hat Enterprise Linux 7 Reporter: Jaroslav Škarvada <jskarvad>
Component: boostAssignee: Jonathan Wakely <jwakely>
Status: CLOSED ERRATA QA Contact: Arjun Shankar <ashankar>
Severity: unspecified Docs Contact: Vladimír Slávik <vslavik>
Priority: high    
Version: 7.4CC: ashankar, fzdarsky, jskarvad, jwakely, mcermak, mnewsome, vslavik
Target Milestone: rcKeywords: Patch
Target Release: ---   
Hardware: ppc64   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 16:47:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jaroslav Škarvada 2016-12-07 17:35:40 UTC
Description of problem:
The char type on ppc64 is unsigned thus the signed magic the boost implementation do doesn't work on ppc64 which results in the lexer not working or the application crashing (with e.g. the spirit debug mode enabled).

Version-Release number of selected component (if applicable):
boost-1.53.0-26.el7.ppc64

How reproducible:
Always

Steps to Reproduce:
1. E.g. try to compile uhd-3.10.1.0
2. Run make test

Actual results:
'make test' fails

Expected results:
'make test' pass

Additional info:
I think the boost lexer is quite unusable at the moment on ppc64 and maybe on other platforms as well.

Upstream ticket including the patch that worked for me:
https://svn.boost.org/trac/boost/ticket/8291

It's possible to come up with stripped down reproducer, but I haven't time to prepare it :)

Comment 2 Jaroslav Škarvada 2016-12-08 15:54:01 UTC
TLDR: the fix consists in replacing the following non portable code:

  CharT curr_char_ = sizeof (CharT) == 1 ? -128 : 0; 

by the portable code:

  CharT curr_char_ = (std::numeric_limits<CharT>::min)();

Comment 3 Jonathan Wakely 2016-12-14 14:57:11 UTC
That change apparently causes other problems when wchar_t is signed, see

https://github.com/boostorg/spirit/commit/c480d6c7fcadf3cb5fbaad756ac370275a75e601

That commit only fixes one of the places that the fix for ticket 8291 changed. It would be nice to know what on earth that code is actually trying to do. Surely fixing it properly and portably can't be difficult.

Comment 4 Jonathan Wakely 2016-12-14 15:00:34 UTC
The original change was https://github.com/boostorg/spirit/commit/2b4c331e70f1f8eaae33537df12c5744dd8e8b09

Comment 5 Frank Zdarsky 2016-12-15 16:47:07 UTC
That code fills a lookup table mapping characters to discrete finite automaton states for the lexer. Depending on the token_._negated flag, it either maps all characters in the token's charset or all possible characters _except_ for those in the charset.

So iterating curr_char_ from std::numeric_limits<CharT>::min)() would actually be correct.

A proper upstream fix would then either cast the index into the lookup table (ptr_[static_cast<typename Traits::index_type>(curr_char_)]) to unsigned or shift it by -std::numeric_limits<CharT>::min)()... consistently everywhere the
the lookup table is used. A bit more involved.

The kludge from https://github.com/boostorg/spirit/commit/c480d6c7fcadf3cb5fbaad756ac370275a75e601
starts with curr_char_=0, which works correctly on platforms on which wchar_t is unsigned int. On platforms where it's signed, it should work, too, as long as we're processing only characters >=0... which on >=32 bit platforms should encompass all relevant ones.

Comment 6 Jonathan Wakely 2016-12-15 16:50:43 UTC
Thanks! Now that bug 1404781 is fixed I'll have another try at applying those two patches and building a new package.

Comment 7 Jonathan Wakely 2016-12-20 10:53:34 UTC
Scratch build with those two patches:
https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12254351

Comment 8 Frank Zdarsky 2017-02-10 20:23:40 UTC
Any movement on this? In particular, is there a chance to get this async into 7.3 as work with one of our partners depends on this?

Comment 9 Jonathan Wakely 2017-02-10 22:25:19 UTC
I have the patch ready to go, but making a change for rhel7 needs to be acked.

Did anyone test the scratch build I did?

Comment 10 Frank Zdarsky 2017-02-13 11:28:11 UTC
I'm afraid I didn't get to test before the scratch build expired. I'm sorry, would you mind kicking off a build again?

Can test only on x86_64, not ppc64, though.

Comment 11 Jaroslav Škarvada 2017-02-13 12:05:04 UTC
(In reply to Jonathan Wakely from comment #9)
> I have the patch ready to go, but making a change for rhel7 needs to be
> acked.
> 
> Did anyone test the scratch build I did?

Sorry I was on PTO, so I missed it and now the scratch build is gone. Could you rebuild it? I am going to test it with UHD.

Comment 12 Jonathan Wakely 2017-02-13 13:59:48 UTC
Hi, thanks for offering to test. Any testing is useful, even if not on ppc64. There's a new scratch build at https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12533685

x86_64 RPMs are at:
https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12533691

and ppc64 at:
https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12533697

Thanks for checking them!

Comment 13 Jaroslav Škarvada 2017-02-13 18:41:58 UTC
(In reply to Jonathan Wakely from comment #12)
> Hi, thanks for offering to test. Any testing is useful, even if not on
> ppc64. There's a new scratch build at
> https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12533685
> 
> x86_64 RPMs are at:
> https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12533691
> 
> and ppc64 at:
> https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=12533697
> 
> Thanks for checking them!

The scratch build works for me, the problem seems fixed, thanks.

Comment 25 errata-xmlrpc 2017-08-01 16:47:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:1973