Bug 187701

Summary: [GTK][BUILD] FAILED: lib/libwebkit2gtk-4.0.so.37.31.0 collect2: error: ld returned 1 exit status
Product: WebKit Reporter: karogyoker2+webkit
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WONTFIX    
Severity: Normal CC: bugs-noreply, mcatanzaro
Priority: P2    
Version: WebKit Local Build   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
console output
none
memory usage on host none

Description karogyoker2+webkit 2018-07-16 10:05:09 PDT
Created attachment 345097 [details]
console output

Hello,

I cannot build WebKit.
This is what I've done:
1. I got a snapshot on June 30 (or 29) from the link mentioned here: https://webkit.org/getting-the-code/
2. tar jxvf WebKit-SVN-source.tar.bz2
3. cd webkit
4. $ Tools/gtk/install-dependencies
5. $ Tools/Scripts/update-webkitgtk-libs
6. cd WebKitBuild
7. cmake .. -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS="-march=native" -DCMAKE_CXX_FLAGS="-march=native" -DUSE_WOFF2=OFF -DENABLE_MINIBROWSER=ON -GNinja
8. ninja -j1

Output:
[4/68] Linking CXX shared library lib/libwebkit2gtk-4.0.so.37.31.0
FAILED: lib/libwebkit2gtk-4.0.so.37.31.0 
: && /usr/bin/c++ -fPIC -fdiagnostics-color=always -Wno-expansion-to-defined -Wno-attributes -Wno-noexcept-type -Wno-maybe-uninitialized -Wwrite-strings -Wundef -Wpointer-arith -Wmissing-format-attribute -Wformat-security -Wcast-align -Wextra -Wall -march=native -fno-strict-aliasing -fno-exceptions -fno-rtti -std=c++17 -O2 -g -DNDEBUG  -fuse-ld=gold -Wl,--disable-new-dtags -fuse-ld=gold -Wl,--disable-new-dtags   -Wl,--version-script,/home/oldboi/Downloads/webkit/Source/WebKit/webkitglib-symbols.map -shared -Wl,-soname,libwebkit2gtk-4.0.so.37 -o lib/libwebkit2gtk-4.0.so.37.31.0 Source/WebKit/CMakeFiles/WebKit.dir/NetworkProcess/NetworkActivityTracker.cpp.o Source/WebKit/CMakeFiles/WebKit.dir/NetworkProcess/NetworkCORSPreflightChecker.cpp.o Source/WebKit/CMakeFiles/WebKit.dir/NetworkProcess/NetworkConnectionToWebProcess.cpp.o Source/WebKit/CMakeFiles/WebKit.dir/NetworkProcess/NetworkContentRuleListManager.cpp.o Source/WebKit/CMakeFiles/WebKit.dir
.
.
.
[TRUNCATED, see attachment]
.
.
.
/i386-linux-gnu/libXdamage.so /usr/lib/i386-linux-gnu/libXrender.so /usr/lib/i386-linux-gnu/libXt.so /usr/lib/i386-linux-gnu/libz.so -lwayland-server -lwayland-egl -lwayland-client && :
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Is there any way to know more about why the linker failed?
Comment 1 Michael Catanzaro 2018-07-16 10:19:40 PDT
Could it be OOM?

Builds on i386 are going to be more difficult due to resource limits. Try:

-Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g1
Comment 2 karogyoker2+webkit 2018-07-16 20:48:55 PDT
Sorry, but where should I put these flags? Ninja doesn't recognize them.

I have 10 gigs of swap, and it is not full when the build fails. During the build the peak was around 1GB RAM + 2-3GB swap.
Comment 3 Michael Catanzaro 2018-07-17 08:42:04 PDT
You would put them in CFLAGS and CXXFLAGS, but they're not going to help if you're not running out of memory.

I don't know how we can help with this, since there's not any useful error message from the linker.
Comment 4 karogyoker2+webkit 2018-07-17 11:29:41 PDT
Can't we pass some arguments to something which will run the linker in verbose mode when it gets there?
Comment 5 Michael Catanzaro 2018-07-17 14:04:18 PDT
I don't know what.
Comment 6 karogyoker2+webkit 2018-07-17 22:32:29 PDT
Then I guess it just doesn't work. I might try to build it on other environment, on other machine (in VirtualBox with 32 bit Linux, setting march=pentium3). But before that, I have to ask something. Because the whole purpose of this build for me was to create a version of WebKit which doesn't require SSE2 to run. Is that even possible or in WebKit's source there are hardcoded SSE2 instructions (like in Firefox, Chrome or Basilisk)? All of these browsers explicitly states in their system requirements that SSE2 is a must. But I couldn't find the system requirements for WebKit. Can you help me on this? Slightly off topic, but since you are a master of WebKit, I guess you would know.

Midori works for me, I think because it is using an older version of Webkit, but for example surf or Web (Epiphany-browser), both don't work.
Comment 7 Michael Catanzaro 2018-07-18 07:59:23 PDT
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.
Comment 8 karogyoker2+webkit 2018-07-18 23:02:15 PDT
I created a Virtual Box VM on one of my other machines, it is a 4 core i5@3.5GHz with 8GB RAM. I gave the VM 4GB RAM.

First I used this command:
cmake .. -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS="-march=pentium3" -DCMAKE_CXX_FLAGS="-march=pentium3" -DUSE_WOFF2=OFF -DENABLE_MINIBROWSER=ON -GNinja

Then after ninja -j1 I got:
[4/45] Linking CXX shared library lib/libwebkit2gtk-4.0.so.37.31.0
FAILED: lib/libwebkit2gtk-4.0.so.37.31.0 
...
/usr/bin/i686-linux-gnu-ld.gold: fatal error: lib/libwebkit2gtk-4.0.so.37.31.0: mmap: failed to allocate 1895756280 bytes for output file: Cannot allocate memory
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Which is strange since the VM didn't even use 1GB of RAM, reported by htop. Also the host still had plenty of RAM, see attachment.

So then I used the command:
cmake .. -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS="-march=pentium3 -Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g1" -DCMAKE_CXX_FLAGS="-march=pentium3 -Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g1" -DUSE_WOFF2=OFF -DENABLE_MINIBROWSER=ON -GNinja

Then I got:
[148/2065] Linking CXX executable bin/LLIntOffsetsExtractor
FAILED: bin/LLIntOffsetsExtractor 
: && /usr/bin/c++  -fdiagnostics-color=always -Wno-expansion-to-defined -Wno-attributes -Wno-noexcept-type -Wno-maybe-uninitialized -Wwrite-strings -Wundef -Wpointer-arith -Wmissing-format-attribute -Wformat-security -Wcast-align -Wextra -Wall -march=pentium3 -Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g1 -fno-strict-aliasing -fno-exceptions -fno-rtti -std=c++17 -O2 -g -DNDEBUG  -fuse-ld=gold -Wl,--disable-new-dtags   -rdynamic Source/JavaScriptCore/CMakeFiles/LLIntOffsetsExtractor.dir/llint/LLIntOffsetsExtractor.cpp.o  -o bin/LLIntOffsetsExtractor  lib/libWTFGTK.a lib/libbmalloc.a -ldl -licudata -licui18n -licuuc -lpthread -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lz && :
/usr/bin/i686-linux-gnu-ld.gold: --reduce-memory-overheads: unknown option
/usr/bin/i686-linux-gnu-ld.gold: use the --help option for usage information
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

I copied what you wrote, I don't know why -Wl is there two times, etc, I could do experiment with trial and error but it would take more time, easier to ask. So how to correctly use these parameters? Thanks.

ld -v
GNU ld (GNU Binutils for Ubuntu) 2.30

uname -a
Linux oldboi-VirtualBox 4.15.0-23-generic #25-Ubuntu SMP Wed May 23 17:59:24 UTC 2018 i686 i686 i686 GNU/Linux
Comment 9 karogyoker2+webkit 2018-07-18 23:03:20 PDT
Created attachment 345332 [details]
memory usage on host
Comment 10 Michael Catanzaro 2018-07-19 05:14:22 PDT
Ah, you need to also pass -DUSE_LD_GOLD=OFF to use -Wl,--reduce-memory-overheads. That's probably worth trying anyway, since it's the ld.gold linker that is failing.

(You need it twice because once is for the C compiler, and once is for the C++ compiler.)
Comment 11 karogyoker2+webkit 2018-07-19 22:45:30 PDT
Hi,

OK, now I got this:
Linking CXX shared library lib/libwebkit2gtk-4.0.so.37.31.0
FAILED: lib/libwebkit2gtk-4.0.so.37.31.0
..
/usr/bin/i686-linux-gnu-ld: final link failed: Memory exhausted
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

There were still more than 1.5GB space in the swap, also the host had 3GB physical free RAM too.

Isn't this happening because on a 32 bit OS a process can use maximum 4GB memory?
I could put 16GB extra RAM into this machine so I would have 24GB, but I think it might not help.

Do I need to cross-compile then? Are there any instructions how to do it for WebKit?
Comment 12 Michael Catanzaro 2018-07-20 05:53:55 PDT
I don't know what to tell you... in Fedora we use -Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g1. Since that didn't work for you, I guess attempting to cross compile would be reasonable. There are some instructions for cross-compiling for ARM (not what you want to do) at the bottom of https://trac.webkit.org/wiki/BuildingGtk. Good luck....

You might want to look up how Gentoo handles this.
Comment 13 karogyoker2+webkit 2018-07-20 14:20:53 PDT
Just for the record, on the host I have 24GB RAM now, in the VM 17.8GB, the linking failed just like before, at that moment RAM utilization was around 3.8GB. So that's it, it is not possible to build 32 bit version of WebKit without cross-compile. Maybe I'll try with Fedora, but there shouldn't be a difference regarding this.
Comment 14 Michael Catanzaro 2018-07-20 17:57:50 PDT
I can assure you that all major Linux distributions are successfully building it without cross compiling, so you might want to investigate what they're doing.
Comment 15 karogyoker2+webkit 2018-07-21 06:09:05 PDT
I installed Fedora 28 32bit but its kernel is not PAE so RAM is maxed at 3.5GB and I couldn't find a PAE kernel for it.
I installed Lubuntu 64 bit, and WebKit compiled OK. I got a 2GB large .so file. Is this normal? Then I downloaded and compiled surf, it is working fine.
Comment 16 Michael Catanzaro 2018-07-21 06:22:42 PDT
(In reply to karogyoker2+webkit from comment #15)
> I installed Fedora 28 32bit but its kernel is not PAE so RAM is maxed at
> 3.5GB and I couldn't find a PAE kernel for it.
> I installed Lubuntu 64 bit, and WebKit compiled OK. I got a 2GB large .so
> file. Is this normal? Then I downloaded and compiled surf, it is working
> fine.

Yes, that is normal. You can reduce it using -g1. Or -g0, if you're desperate.

I don't think we have anything actionable here, so I'm going to close this.
Comment 17 karogyoker2+webkit 2018-07-22 10:23:41 PDT
OK, the problem was -DCMAKE_BUILD_TYPE=RelWithDebInfo.
It should be -DCMAKE_BUILD_TYPE=Release
This way it is possible to compile it on 32 bit systems.

So the steps are:
1. Go to https://webkitgtk.org/releases/
2. download the newest stable, extract, go into extracted folder
3. cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-march=pentium3 -Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g0 -Os" -DCMAKE_CXX_FLAGS="-march=pentium3 -Wl,--no-keep-memory -Wl,--reduce-memory-overheads -g0 -Os" -DUSE_WOFF2=OFF -DUSE_LD_GOLD=OFF -DENABLE_MINIBROWSER=OFF -DENABLE_JIT=OFF -GNinja
4. ninja
5. sudo make install

Maybe it could work with GOLD too without the reduce memory overheads stuffs.
Comment 18 karogyoker2+webkit 2018-07-22 10:34:42 PDT
Just for the record, I forgot one step, it is between step #2 and step #3:
./Tools/gtk/install-dependencies
Comment 19 karogyoker2+webkit 2018-07-22 10:58:51 PDT
(In reply to Michael Catanzaro from comment #16)
> (In reply to karogyoker2+webkit from comment #15)
> > I installed Fedora 28 32bit but its kernel is not PAE so RAM is maxed at
> > 3.5GB and I couldn't find a PAE kernel for it.
> > I installed Lubuntu 64 bit, and WebKit compiled OK. I got a 2GB large .so
> > file. Is this normal? Then I downloaded and compiled surf, it is working
> > fine.
> 
> Yes, that is normal. You can reduce it using -g1. Or -g0, if you're
> desperate.
> 
> I don't think we have anything actionable here, so I'm going to close this.

Or it can be reduced to ~52MB by using -DCMAKE_BUILD_TYPE=Release instead of -DCMAKE_BUILD_TYPE=RelWithDebInfo

Just if somebody finds this in the future.