Closed Bug 1284293 Opened 8 years ago Closed 5 years ago

menus and dialogs missing text due to FIX_FPU on 32 bit linux with musl libc

Categories

(Core :: JavaScript Engine, defect, P3)

45 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1342176

People

(Reporter: natanael.copa, Unassigned)

Details

(Keywords: triage-deferred)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0
Build ID: 20160525213134

Steps to reproduce:

build firefox 45esr on 32bit alpine linux (musl libc) and started firefox.


Actual results:

fonts and menus disappeared due to the FIX_FPU function will mess with the floating point precision and then DPI calculation will call libc math function round() which is broken.

details and screenshots reported on alpine bug tracker: http://bugs.alpinelinux.org/issues/4248


Expected results:

fonts and menus should been displayed properly
Moving to JavaScript Engine Component as FIX_FPU is defined in js/src/jsnum.cpp.

https://dxr.mozilla.org/mozilla-central/rev/39dffbba764210b25bfc1e749b4f16db77fa0d46/js/src/jsnum.cpp#1045
> void
> js::FIX_FPU()
> {
> #if (defined __GNUC__ && defined __i386__) || \
>     (defined __SUNPRO_CC && defined __i386)
>     short control;
>     asm("fstcw %0" : "=m" (control) : );
>     control &= ~0x300; // Lower bits 8 and 9 (precision control).
>     control |= 0x2f3;  // Raise bits 0-5 (exception masks) and 9 (64-bit precision).
>     asm("fldcw %0" : : "m" (control) );
> #endif
> }
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
(In reply to Tooru Fujisawa [:arai] from comment #1)
> Moving to JavaScript Engine Component as FIX_FPU is defined in
> js/src/jsnum.cpp.
> 
> https://dxr.mozilla.org/mozilla-central/rev/
> 39dffbba764210b25bfc1e749b4f16db77fa0d46/js/src/jsnum.cpp#1045
> > void
> > js::FIX_FPU()
> > {
> > #if (defined __GNUC__ && defined __i386__) || \
> >     (defined __SUNPRO_CC && defined __i386)
> >     short control;
> >     asm("fstcw %0" : "=m" (control) : );
> >     control &= ~0x300; // Lower bits 8 and 9 (precision control).
> >     control |= 0x2f3;  // Raise bits 0-5 (exception masks) and 9 (64-bit precision).
> >     asm("fldcw %0" : : "m" (control) );
> > #endif
> > }

This is the code that will change precision. Any calls to libc math functions after this will result in undefined behavior. In this specific case it broke round().

I tried to replace the round() call with NS_round() which indeed solves the DPI detection, but there are many more libc math function calls, inclusive in third party libraries, which may or may not work depending on libc implementation and luck.
Not just math functions. Setting the fpu control word to a value that yields non-conforming behavior breaks _any_ code which uses floating point, which could be any third-party library code including any function in libc.

If the JS implementation does not actually depend on this mode setting (e.g. if it's actually using SSE2 for floating point anyway) then the above code should just be removed. If it does depend on this then it needs to switch mode every time control passes in/out of the JS implementation.

Also note that the comment (and most x87 documentation) is incorrect. Bit 9 does not set "64-bit precision" but rather sets "53-bit significand" mode. The exponent is still 15 bits like normal x87 long double. Thus this mode cannot be used to implement correct IEEE double semantics; overflow/underflow do not occur as expected, and values which are nominally denormal actually behave as normal.
Keywords: triage-deferred
Priority: -- → P3

i try to build in Debian by my own and cannot give expected good results.. unless i used the modified sources from debian, but if i download the firefox sources and try to build a vanilla firefox unchanged sources.. got similar problem.

(In reply to Natanael Copa from comment #0)

build firefox 45esr on 32bit alpine linux (musl libc) and started firefox.

i also tyry to make same in my alpine and got same result, no build!

FIX_FPU was removed in bug 1342176, therefore closing as a dup of that one.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE

(In reply to mckaygerhard from comment #4)

i try to build in Debian by my own and cannot give expected good results.. unless i used the modified sources from debian, but if i download the firefox sources and try to build a vanilla firefox unchanged sources.. got similar problem.

If you build Firefox 54 or later, can you file a new bug report for your specific problem?

You need to log in before you can comment on or make changes to this bug.