Bug 187889 - Hard dependency on SSE2 instruction set
Summary: Hard dependency on SSE2 instruction set
Status: RESOLVED DUPLICATE of bug 188145
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: PC All
: P1 Blocker
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-22 04:39 PDT by karogyoker2+webkit
Modified: 2018-07-29 02:01 PDT (History)
0 users

See Also:


Attachments
Lubuntu installer WebKit bug (83.58 KB, image/png)
2018-07-22 12:33 PDT, karogyoker2+webkit
no flags Details
Crash report (1.47 MB, application/x-zip-compressed)
2018-07-22 16:12 PDT, karogyoker2+webkit
no flags Details
Crash report as text (1.51 MB, text/plain)
2018-07-22 16:14 PDT, karogyoker2+webkit
no flags Details
WebKit running on Athlon XP (1.13 MB, image/png)
2018-07-23 14:52 PDT, karogyoker2+webkit
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description karogyoker2+webkit 2018-07-22 04:39:36 PDT
Hello,

On my Athlon XP both surf or Epiphany-Browser (Web) is unusable, they cannot display any websites, they just remain white and the loading takes forever, but nothing happens, no CPU activity.
If I try them in a 32 bit VM on my 64 bit host, both works fine.

I did a quick search for hardcoded assembly instructions in WebKit's source, and I found this:
movsd %xmm0, (%esp)

It is in ThunkGenerators.cpp, below this part:
#elif CPU(X86) && COMPILER(GCC_OR_CLANG) && (OS(DARWIN) || OS(LINUX))
#define defineUnaryDoubleOpWrapper(function) \

MOVSD was introduced in SSE2:
http://softpixel.com/~cwright/programming/simd/sse2.php
https://en.wikibooks.org/wiki/X86_Assembly/SSE

Athlon XP or Pentium 3 don't have SSE2 (Pentium 4 was the first to have it), I think this is the issue.

I couldn't obtain any crash logs or something (sometimes there is no crash, just nothing happens), but I'm willing to try it somehow if needed.
I would also test the fix on my Athlon XP if somebody fixes this and created a package on a PPA (debian). I cannot fix it myself because the reasons below:

Currently, I'm not even able to run my own built WebKit on my Athlon XP. On Athlon XP I cannot build it because the linking process requires more than 4 GB memory. I was able to cross-complie it on a 64 bit VM inside a 32 bit LXC container with pentium3 arch, I got the resulted files in the lib folder, but I don't know yet how to use them with surf browser for example to try them on my Athlon XP.
When I was building WebKit on a 64 bit VM, after sudo ninja install, I could compile surf with sudo make clean install, and it was working, but I don't know how to reuse the already compiled files without sudo ninja install (which can be ran only after a build, which I cannot do because the memory limitation).
Comment 1 karogyoker2+webkit 2018-07-22 07:28:10 PDT
Of course the 32 bit LXC container was inside the 64 bit VM. A missing comma can change a lot :)
Comment 2 karogyoker2+webkit 2018-07-22 10:41:38 PDT
The last two paragraph of the first comment is now obsolete.
I'm gonna try to build on my Athlon XP with -DCMAKE_BUILD_TYPE=Release and -DENABLE_JIT=OFF. See what happens. Since the SSE2 code is in the JIT folder (JavaScriptCore/jit/), maybe it will fix it, I don't know.
Comment 3 karogyoker2+webkit 2018-07-22 12:27:09 PDT
I decided to reinstall Lubuntu 18.04 on my Athlon XP machine. I saw it again that Ubuntu has encountered some issue.. blah blah, the usual error reporting window. When I click show details the window is closing so fast I cannot read the text, but one thing I could read: WebKit Process. Also where the marketing bullshit should be during the installation, I cannot see anything, just a white background. This must be something with SSE2 because if I install Lubuntu 18.04 32bit edition in a VM on my 64 bit machine (all 64bit CPUs have SSE2), I don't have this issue.
Comment 4 karogyoker2+webkit 2018-07-22 12:33:19 PDT
Created attachment 345542 [details]
Lubuntu installer WebKit bug

The area marked with red rectangle where I have only a white background, nothing else
Comment 5 karogyoker2+webkit 2018-07-22 16:12:58 PDT
Created attachment 345545 [details]
Crash report

I was able to catch the crash and I made screenshots about it. It is now obvious that it is crashing because of SSE2. SIGILL happened because of LFENCE which is introduced by SSE2.
Comment 6 karogyoker2+webkit 2018-07-22 16:14:00 PDT
Created attachment 345546 [details]
Crash report as text

Here is the original file if you want to copy something from it.
Comment 7 karogyoker2+webkit 2018-07-22 17:13:42 PDT
In wtf\Atomics.h I found this:
inline void x86_lfence()
{
#if !OS(WINDOWS)
    asm volatile("lfence" ::: "memory");
#endif
}

Well, this won't work on every x86, it should be !OS(WINDOWS) && CPU(X86_64) because every 64bit CPU has SSE2. Pentium 4 users would lose Spectre V2 mitigation here.
Comment 8 karogyoker2+webkit 2018-07-22 17:21:38 PDT
(In reply to karogyoker2+webkit from comment #7)
> In wtf\Atomics.h I found this:
> inline void x86_lfence()
> {
> #if !OS(WINDOWS)
>     asm volatile("lfence" ::: "memory");
> #endif
> }
> 
> Well, this won't work on every x86, it should be !OS(WINDOWS) && CPU(X86_64)
> because every 64bit CPU has SSE2. Pentium 4 users would lose Spectre V2
> mitigation here.

This way Pentium 4 users will be saved: !OS(WINDOWS) && CPU(X86_SSE2)
Comment 9 karogyoker2+webkit 2018-07-22 17:31:39 PDT
I also found PAUSE which require SSE2 (in ToyLocks.h, but it is maybe just for benchmarking, not critical), and stmxcsr and ldmxcsr which require SSE (Pentium 3 at least).
Comment 10 karogyoker2+webkit 2018-07-22 23:21:01 PDT
> This way Pentium 4 users will be saved: !OS(WINDOWS) && CPU(X86_SSE2)

Sorry, this was bad, obviously it should be !OS(WINDOWS) && (CPU(X86_SSE2) || CPU(X86_64))
Comment 11 karogyoker2+webkit 2018-07-23 12:51:48 PDT
(In reply to karogyoker2+webkit from comment #10)
> > This way Pentium 4 users will be saved: !OS(WINDOWS) && CPU(X86_SSE2)
> 
> Sorry, this was bad, obviously it should be !OS(WINDOWS) && (CPU(X86_SSE2)
> || CPU(X86_64))

Ah, I it seems X86_SSE2 is not everywhere available and it covers X86_64 too, anyways, if it is just __SSE2__ it is OK too, but I think you know it better, I'm not familiar with the codebase. By the way, I checked the SVN and it seems this bug got introduced in 2.19.90 (released on February 5), must be part of the Spectre V2 mitigation. By the way, I think this is why I can't boot Windows 7 anymore on my Athlon XP machine since 2018 February patch rollup. I think MS used hardcoded LFENCE too in that cumulative patch. So I switched to Linux but there isn't any web browser which can run without SSE2, only Firefox ESR 52 which will be end of life in August.

Quote from Michael Catanzaro:
"For WebKitGTK+, SSE2 instructions are forbidden (except when building for x86_64) because that's what our distributors require. But I doubt all developers are aware of this, and I also doubt anybody ever tests on such old hardware. So it might require some effort to audit the codebase for unwanted SSE2 instructions to make sure they're not there and fix them if so."

So this is obviously a bug.
Comment 12 karogyoker2+webkit 2018-07-23 14:52:22 PDT
Created attachment 345610 [details]
WebKit running on Athlon XP

I fixed the LFENCE issue, now I can open webpages, so far so good, works well on my Athlon XP!

This is what I've changed in wtf\Atomics.h:
From:
inline void x86_lfence()
{
#if !OS(WINDOWS)
    asm volatile("lfence" ::: "memory");
#endif
}
To:
inline void x86_lfence()
{
#if !OS(WINDOWS) && defined(__SSE2__)
    asm volatile("lfence" ::: "memory");
#endif
}

So, I've just added " && defined(__SSE2__)". Easy fix.
Comment 13 karogyoker2+webkit 2018-07-27 21:07:58 PDT
To sum up everything:
WebKit cannot run on X86 processors without SSE2 (most of them).
To fix this 2 things needs to be done:
1. Add defined(__SSE2__) to that #if above lfence, shown in my previous comment
2. Compile it with JIT disabled: -DENABLE_JIT=OFF
Comment 14 karogyoker2+webkit 2018-07-29 02:01:04 PDT
I'm closing this bug as duplicate because I created a new one with a patch. This bug is about more than one issue, so I close this one, and I'll create a separate bug for each issue mentioned here with a patch to fix them.

*** This bug has been marked as a duplicate of bug 188145 ***