Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Chromium build #3

Closed
dmik opened this issue Feb 21, 2020 · 57 comments
Closed

Make Chromium build #3

dmik opened this issue Feb 21, 2020 · 57 comments
Assignees

Comments

@dmik
Copy link
Contributor

dmik commented Feb 21, 2020

This is a continuation of bitwiseworks/qtwebengine-os2#1 dedicated to building the original Chromium source code.

Note that the build process itself is intended to be started using qmake makefiles from within the qtwebengine repository. But qmake does no more than simply runs gn to generate ninja build files and then runs ninja. I.e. prepares and starts a native Chromium build process. While this process can be then started manually from $(BLDROOT)/qtwebengine/src/core/debug (or release) by calling ninja like this:

cd "$(BLDROOT)"/qtwebengine/src/core && "$(BLDROOT)"/qtwebengine/src/3rdparty/ninja/ninja.exe -v  -C "$(BLDROOT)"/qtwebengine/src/core/$(BUILD_TYPE) QtWebEngineCore

it's still recommended to use qmake makefiles to avoid any de-synchronization with Qt sources.

dmik added a commit that referenced this issue Feb 21, 2020
dmik added a commit that referenced this issue Feb 21, 2020
@dmik
Copy link
Contributor Author

dmik commented Feb 21, 2020

Then next rather big step is to port the message_pump machinery. I actually already did that when porting Mozilla (check https://github.com/bitwiseworks/mozilla-os2/commits/master/ipc/chromium/src/base and around) but Mozilla uses a very old version of Chromium and a lot has changed since then so some aligning is needed.

@dmik
Copy link
Contributor Author

dmik commented Feb 26, 2020

The message_pump machinery is mostly done (a commit will follow). Then ext task is thread_local_storage. In old Chromium in Mozilla we used pthread but now I have to do it natively as pthread destructor handling is not perfect (and will not work in some cases). And Chromium performs its own processing anyway.

dmik added a commit that referenced this issue Feb 28, 2020
Based on a (much) older version of the port from Mozilla.

Needed for #3.
@dmik
Copy link
Contributor Author

dmik commented Feb 28, 2020

I'm getting build issues in utf_string_conversions.cc because std::is_integral<wchar_t>::value is false with the new GCC 9.x although it must be true of course. This might require more some more GCC work within bitwiseworks/gcc-os2#16, sigh...

@dmik
Copy link
Contributor Author

dmik commented Mar 5, 2020

With LIBC and GCC fixed, the string functions build fine now. Next stops besides pthread TLS are these (all expected):

  • LaunchProcess (launch_posix.cc), need to use spawn2 instead of fork there.
  • UnixDomainSocket (unix_domain_socket.cc, sync_socket_posix.cc, some alignments to features missing on OS/2).
  • URandomFD (rand_util_posix.cc)
  • Condition and lock variables (condition_variable_posix.cc, lock_impl_posix.cc, might be related to pthread as well).
  • Metrics code (histogram.cc, process_metrics.cc)

@dmik
Copy link
Contributor Author

dmik commented Mar 6, 2020

LaunchProcess requires some tricks to be done. In POSIX, they sometimes want the child to inherit a specific FD of the parent. Sometimes this FD is required to be inherited under a specific file number in the child (i.e. not the original one). All this is achievable (with dup2) but not out of the box. The main problem is thread safety. I fear Chromium starts processes from many threads. So doing it w/o locking might mix things up. Also, inheritance is a big question. On OS/2 all file handles are inherited by default and this is surely not what Chromium wants. In spawn2 inheritance may be completely suppressed with P_2_NOINHERIT flag, but this makes it impossible to inherit specific descriptors. I think that the simplest way to go here is to extend LIBCx spawn2 to allow for selective inheritance of specified file handles.

@dmik
Copy link
Contributor Author

dmik commented Mar 14, 2020

With the new LIBCx spawn2 update, doing LaunchProcess was quite easy (and much easier than Unix or even Windows code!).

I've also stumbled upon psmedley/gcc#34 when building histogram code:

D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/metrics/histogram.cc:350:34: error: 'round' is not a member of 'std'; did you mean 'round'?
  350 |     next = static_cast<int>(std::round(exp(log_next)));
      |                                  ^~~~~
In file included from C:/usr/include/c++/9/math.h:30,
                 from C:/usr/include/c++/9/cmath:45,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/numerics/checked_math_impl.h:12,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/numerics/checked_math.h:13,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/numerics/safe_math.h:8,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/time/time.h:63,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/metrics/histogram_base.h:20,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/metrics/bucket_ranges.h:30,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/metrics/histogram.h:81,
                 from D:/Coding/qt5/qt5/qtwebengine/src/3rdparty/chromium/base/metrics/histogram.cc:10,
                 from gen/base/base_jumbo_12.cc:5:
C:/usr/include/math.h:289:8: note: 'round' declared here
  289 | double round(double);
      |        ^~~~~

It can be worked around the way I did it in QtDeclarative but I guess it's time to fix GCC instead as it should be easy and will free us from working around these bits in other software.

@SilvanScherrer
Copy link

bitwiseworks/gcc-os2#15 weil known id say

@dmik
Copy link
Contributor Author

dmik commented Mar 16, 2020

With bitwiseworks/gcc-os2#15 closed, histogram code builds fine. I will rebuild QtDeclarative too.

dmik added a commit that referenced this issue Mar 16, 2020
dmik added a commit that referenced this issue Mar 20, 2020
dmik added a commit that referenced this issue Mar 20, 2020
dmik added a commit to bitwiseworks/libc that referenced this issue Mar 23, 2020
These are in POSIX since long. Taken from FreeBSD whose numeric values
match OS/2 TCP/IP 4.21 PR.

Needed for bitwiseworks/qtwebengine-chromium-os2#3.
@dmik
Copy link
Contributor Author

dmik commented Mar 24, 2020

Just as a side note. It's kind of hard to work on things because there is basically a single Chromium "makefile" which builds everything in parallel and in random order. There is no way to tell "build me only threading sources" etc. So I have to grab individual gcc calls and run them manually if I want to work specifically on them. This is very inconvenient. Takes too much time to sort these things out.

There is some level of control via build.ninja's build statements but it also requires some manual lookup and execution. Not very helpful.

dmik added a commit that referenced this issue Mar 25, 2020
dmik added a commit that referenced this issue Mar 25, 2020
dmik added a commit that referenced this issue Mar 25, 2020
dmik added a commit that referenced this issue Mar 25, 2020
System versions always contain latest OS/2 fixes maintained in their
own repositories and it doesn't make sense to do monkey work by
applying them to the Chromium tree.

Needed for #3.
@dmik
Copy link
Contributor Author

dmik commented Mar 25, 2020

Moved a bit further. With latest pthread fixes TLS code also builds fine out of the box (and should be thread-safe). I'm seeing lots of small build breaks here and there. Will commit them next once done.

dmik added a commit to bitwiseworks/libc that referenced this issue Mar 26, 2020
This is necessary to avoid -Wsign-compare warnings (enabled with -Wall)
in C++ code that does comparisons like `siginfo.si_code == BUS_ADRALN`
because si_code member of siginfo is defined as int (per POSIX) while
BUS_ADRALN and many other constants are defined as 0x8xxxxxxx which
produces an unsigned int literal (since it won't fit in signed int).

Needed for bitwiseworks/qtwebengine-chromium-os2#3.
@dmik
Copy link
Contributor Author

dmik commented Jun 3, 2020

Moved to a separate issue. Theseus is great but not very useful under heavy load.

@StevenLevine
Copy link

StevenLevine commented Jun 4, 2020 via email

@dmik
Copy link
Contributor Author

dmik commented Jun 4, 2020

I wonder then how to run Theseus at time-critical priority... Some nice-like command line tool?

I worked around the OOM condition in EMXOMF but this didn't solve all the problems. Now I'm hitting OOM in CC1PLUS.EXE while compiling (i.e. generating that huge assembly):

g++ -MMD -MF obj/content/browser/browser/render_frame_devtools_agent_host.o.d -DUSE_VIZ_DEVTOOLS -DUSE_AURA=1 -DNO_TCMALLOC -DCHROMIUM_BUILD -DTOOLKIT_QT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -DCONTENT_IMPLEMENTATION -DWEBP_EXTERN=extern -DUSING_SYSTEM_ICU=1 -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -DHAVE_PTHREAD -DSK_HAS_PNG_LIBRARY -DSK_HAS_WEBP_LIBRARY -DSK_HAS_JPEG_LIBRARY -DSK_SUPPORT_GPU=1 -DSK_GPU_WORKAROUNDS_HEADER=\"gpu/config/gpu_driver_bug_workaround_autogen.h\" -DLEVELDB_PLATFORM_CHROMIUM=1 -DLEVELDB_PLATFORM_CHROMIUM=1 -DOPENSSL_NO_ASM -DWEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0 -DWEBRTC_CHROMIUM_BUILD -DWEBRTC_POSIX -DWEBRTC_OS2 -DWEBRTC_NO_INET6 -DABSL_ALLOCATOR_NOTHROW=1 -DNO_MAIN_THREAD_WRAPPING -DV8_ENABLE_CHECKS -DV8_DEPRECATION_WARNINGS -DUSING_SYSTEM_ICU=1 -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC -DSQLITE_ENABLE_FTS3 -DSQLITE_DISABLE_FTS3_UNICODE -DSQLITE_DISABLE_FTS4_DEFERRED -DSQLITE_ENABLE_ICU -DSQLITE_SECURE_DELETE -DSQLITE_THREADSAFE=1 -DSQLITE_MAX_WORKER_THREADS=0 -DSQLITE_MAX_MMAP_SIZE=268435456 -DSQLITE_DEFAULT_FILE_PERMISSIONS=0600 -DSQLITE_DEFAULT_MEMSTATUS=1 -DSQLITE_DEFAULT_PAGE_SIZE=4096 -DSQLITE_DEFAULT_PCACHE_INITSZ=0 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_USE_ALLOCA -DSQLITE_OMIT_ANALYZE -DSQLITE_OMIT_AUTOINIT -DSQLITE_OMIT_AUTORESET -DSQLITE_OMIT_COMPILEOPTION_DIAGS -DSQLITE_OMIT_COMPLETE -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_EXPLAIN -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_LOOKASIDE=0,0 -DSQLITE_OMIT_LOOKASIDE -DSQLITE_OMIT_TCL_VARIABLE -DSQLITE_OMIT_REINDEX -DSQLITE_OMIT_TRACE -DSQLITE_OMIT_UPSERT -DSQLITE_OMIT_WINDOWFUNC -DSQLITE_HAVE_ISNAN -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_ENABLE_API_ARMOR -DUSE_SYSTEM_ZLIB=1 -Igen -I../../../../../qt5/qtwebengine/src/3rdparty/chromium -Igen -Igen -Igen -Igen -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/libwebp/src -Igen -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/khronos -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/gpu -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/libyuv/include -Igen -Igen -Igen -Igen -Igen -Igen -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/ced/src -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/protobuf/src -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/skia/config -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/skia/ext -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/c -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/config -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/core -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/docs -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/effects -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/encode -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/gpu -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/pathops -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/ports -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/utils -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/include/codec -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/src/gpu -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/src/sksl -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/skia/modules/skottie/include -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/leveldatabase -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/leveldatabase/src -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/leveldatabase/src/include -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/protobuf/src -Igen/protoc_out -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/boringssl/src/include -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/webrtc_overrides -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/webrtc -Igen/third_party/webrtc -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/abseil-cpp -Igen/third_party/metrics_proto -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/libwebm/source -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/mesa_headers -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/v8/include -Igen/v8/include -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/angle/src/common/third_party/base -Igen/angle -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/brotli/include -I../../../../../qt5/qtwebengine/src/3rdparty/chromium/third_party/re2/src -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -funwind-tables -Zomf -m32 -msse2 -mfpmath=sse -mmmx -Wall -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-dangling-else -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -O0 -fno-omit-frame-pointer -g2 -std=gnu++14 -Wno-narrowing -Wno-attributes -Wno-class-memaccess -Wno-subobject-linkage -Wno-invalid-offsetof -fno-exceptions -fno-rtti -c ../../../../../qt5/qtwebengine/src/3rdparty/chromium/content/browser/devtools/render_frame_devtools_agent_host.cc -o obj/content/browser/browser/render_frame_devtools_agent_host.o

cc1plus.exe: out of memory allocating 65536 bytes after a total of 65536 bytes

I will look at that in Theseus. But I already noticed earlier that CC1PLUS.EXE was taking more than 1G of "shared" memory on heavy source files. Quite expectable I would say.

BTW, as source file locations show, all the OOM problems started to happen when I came to building the browser component of Chromium. I guess it is its major component so no surprise here. Its sources drag LOTS of stuff from all other support libraries.

@dmik
Copy link
Contributor Author

dmik commented Jun 4, 2020

The above was solved by changing VAL from 1536 to 3072. Going further.

@StevenLevine
Copy link

StevenLevine commented Jun 4, 2020 via email

@dmik
Copy link
Contributor Author

dmik commented Jun 4, 2020

With about 2900 compilation units left to go after some source changes, I'm starting getting kernel panic (and reboots) again. Sigh. Here is the postmortem (or almost postmortem) screenshot:

Снимок экрана 2020-06-04 в 21 40 23

My guess is that it's OOM again from CC1PLUS.EXE (there are 6 processes again as this is what NINJA does by default here). I will try to lower it to 3 processes...

@dmik
Copy link
Contributor Author

dmik commented Jun 4, 2020

@StevenLevine yes, I second your thoughts about 64/32 bits and compiler optimization. It's clear that current GCC builds target 64-bit systems and Chromium compilation failing on a 32-bit Linux wouldn't make me surprised either.

Refactoring Chromium sources? Yes, that's an option but given how numerous and complex these these sources are and also further merging problems you mentioned this might become a real head ache. Frankly, I would invest this (potentially big) amount of time & effort into optimizing GCC instead. By using temporary on-disk "caches" or whatever. This will of course slow down compilation further but will make it at least possible. Another option (which I'm currently exploiting) is reducing parallelism (to make sure there is no more than 1-2 heavy processes at a time). But this is going to slow down compilation time even more...

@dmik
Copy link
Contributor Author

dmik commented Jun 10, 2020

With a few bits fixed (and a few changes still pending — collecting more patches) the number of compilation units left to go is around 1200.

As part of this process I need to add PM support to some of the remaining parts.

dmik added a commit to bitwiseworks/qtwebengine-os2 that referenced this issue Jun 12, 2020
This also includes usual DLL name shortening with TARGET_SHORT.

Needed for #1 and for bitwiseworks/qtwebengine-chromium-os2#3.
dmik added a commit that referenced this issue Jun 12, 2020
This is required with ICU >= 65.

Needed for #3.
dmik added a commit that referenced this issue Jun 12, 2020
dmik added a commit that referenced this issue Jun 12, 2020
Zygote process is a parent for all worker processes which is intended to optimize some resource usage in case of forking.
Since OS/2 will use spawn rather than fork, it's not really needed.

See docs/linux_zygote.md for more info about zygote.

Needed for #3.
dmik added a commit that referenced this issue Jun 12, 2020
@dmik
Copy link
Contributor Author

dmik commented Jun 12, 2020

With a bunch of the above commits I got all 15k compilation units built! I'm pretty sure there will be a bunch of unresolved externals (platform specific parts of C++ classes intended to reside in separate source files which we miss on OS/2 yet). I expect it several dozen of missing exports. A link stage will show the exact list but I'm stuck there due to too long command line. Will continue in bitwiseworks/qtwebengine-os2#1 with that as it belongs to the Qt side of things (this command is generated by qmake).

dmik added a commit that referenced this issue Jul 9, 2020
APIENTRY is _System on OS/2 but this definition only appears if <os2.h>
("base/os2/os2_toolkit.h") is included before OpenGL headers. Otherwise
many things will have a different sgnature and both compiling and
execution will break. Always define APIENTRY in OpenGL headers to avoid
this (just like Windows does).

Needed for #3.
dmik added a commit that referenced this issue Jul 9, 2020
On OS/2, we use fontconfig and freetype just as Linux does.

Needed for #3.
dmik added a commit that referenced this issue Jul 9, 2020
C calling convention used for these exports requires this.

Needed for #3.
dmik added a commit that referenced this issue Jul 9, 2020
dmik added a commit that referenced this issue Jul 9, 2020
On OS/2, we use modern CUPS for printing in cross platform software and
ChromeOS uses it as well.

Needed for #3.
dmik added a commit that referenced this issue Jul 9, 2020
dmik added a commit that referenced this issue Jul 9, 2020
Stubs are mostly based on stubs made for Fuchsia OS.

Needed for #3.
dmik added a commit that referenced this issue Jul 9, 2020
This is due to out of memory problems of the EMX toolchain that seems
to be unable to handle extremely large amount of debug info produced
for C++ extensive Chromium code. See
bitwiseworks/libc#82 and
bitwiseworks/libc#84.

Needed for #3.
@dmik
Copy link
Contributor Author

dmik commented Jul 9, 2020

The above commits is a result of ~two weeks of work (including all distractions like bitwiseworks/libc#82, bitwiseworks/libc#83 and bitwiseworks/libc#84).

With those commits the, DLL containing Chromium successfully links now. It's named Qt5WebC.dll (with an import libraryQt5WebEngineCore.lib) and has a size of 250 megabytes. The DLL itself appears to be fine (at least PMDLL loads it without any problem).

@dmik
Copy link
Contributor Author

dmik commented Jul 9, 2020

Note that there is a lot of stubs for the OS/2 platform instead of real code (done so to speed up getting first results ASAP). These stubs are mostly grabbed from the code for Fuchsia OS and basically do nothing ATM. It's about to be seen which ones of them are actually needed for Qt (and therefore will have to be implemented). This will be done in separate tickets. Closing this one as its main ticket is reached.

@dmik dmik closed this as completed Jul 9, 2020
dmik added a commit to bitwiseworks/libc that referenced this issue Jul 29, 2020
This enhances cf7a5da.

On OS/2, both _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN return the same value (the total number of
CPU cores available to the system at startup) and it doesn't change over time because OS/2 doesn't
suupport hot plugging.

While it's theoretically possible to return only the number of cores being actually online via _SC_NPROCESSORS_ONLN,
there is no practical point in doing so because dynamic core activation and deactivation is a measure of power management
(i.e. all cores should go online if the application wants as many threads and such) and the application should not
make its logic dependent on it.

Needed for sys_info_posix.cc in Chromium (bitwiseworks/qtwebengine-chromium-os2#3).
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

No branches or pull requests

5 participants