How to compile V8 as shared library even for Release build?

1,291 views
Skip to first unread message

Anton Smirnov

unread,
Mar 22, 2018, 4:53:48 AM3/22/18
to Chromium-dev
Hey, guys.

I'm working on Chromium for Android fork with some built-in functionality.
For this i need to build V8 as shared library even for Release build (by default V8 parts are compiled as shared libraries for Debug build and as source sets for Release build) as some other library have to be linked to V8 shared library.

In general my modifications look like this (v8/BUILD.gn):

if (is_component_build || v8_component_build)
    defines = [ "BUILDING_V8_SHARED" ]
}

to force compile shared library in Release build.

I've been able to build apk with `gn gen --args='target_os="android" proprietary_codecs=true is_official_build=true is_debug=false ffmpeg_branding="Chrome" v8_component_build=true' out/ReleaseV8Shared` and i can see libv8.cr.so in apk.

However it crashes while loading of native library (that uses V8):
backtrace:
   #00 pc 0003c9d0  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
   #01 pc 00001a8d  /system/bin/linker (__dl__ZN6soinfo12CallFunctionEPKcPFvvE+44)
   #02 pc 00001b61  /system/bin/linker (__dl__ZN6soinfo9CallArrayEPKcPPFvvEjb+140)
   #03 pc 00001e41  /system/bin/linker (__dl__ZN6soinfo16CallConstructorsEv+144)
   #04 pc 00002495  /system/bin/linker (__dl__Z9do_dlopenPKciPK17android_dlextinfo+136)
   #05 pc 00000ea1  /system/bin/linker (__dl__ZL10dlopen_extPKciPK17android_dlextinfo+24)
   #06 pc 001d4297  /system/lib/libart.so (art::JavaVMExt::LoadNativeLibrary(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, art::Handle<art::mirror::ClassLoader>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)+502)
   #07 pc 001fc2e9  /system/lib/libart.so (art::Runtime_nativeLoad(_JNIEnv*, _jclass*, _jstring*, _jobject*, _jstring*)+548)
   #08 pc 00019811  /system/framework/arm/boot.oat

stack:
        9fdfacb0  00120025  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
        9fdfacb4  00000000  
        9fdfacb8  ffffffff  
        9fdfacbc  af5400c0  [anon:libc_malloc]
        9fdfacc0  00000029  
        9fdfacc4  464c457f  /dev/ashmem/dalvik-main space (deleted)
        9fdfacc8  00010101  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
        9fdfaccc  00000000  
        9fdfacd0  00000000  
        9fdfacd4  00280003  
        9fdfacd8  00000001  
        9fdfacdc  00000000  
        9fdface0  00000034  
        9fdface4  00123940  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
        9fdface8  05000200  
        9fdfacec  00200034  
        9fdfacf0  00280009  
        9fdfacf4  001b001c  
        9fdfacf8  00000009  
        9fdfacfc  b461e000  
        9fdfad00  b461e034  
        9fdfad04  00001000  
        9fdfad08  00008000  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
        9fdfad0c  00126000  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
        9fdfad10  00004000  
        9fdfad14  00008034  /data/app/org.chromium.chrome-1/lib/arm/libadblockplus-jni.so
        9fdfad18  afc49644  [anon:linker_alloc]
        9fdfad1c  b6fb4c0f  /system/bin/linker
        9fdfad20  00000001  
        9fdfad24  00000000  
        9fdfad28  afc49644  [anon:linker_alloc]
        9fdfad2c  b6facb65  /system/bin/linker (__dl__ZN

What can be the reason? In Debug build it works as expected (and works).
Message has been deleted

Anton Smirnov

unread,
Mar 23, 2018, 2:57:13 AM3/23/18
to Chromium-dev
For some reason my post #2 with additional information was deleted, so adding new one instead.

I've got additional information if running on another device (Nougat):

03-23 11:53:01.619 21217-21228 I/cr_LibraryLoader: Using linker: org.chromium.base.library_loader.ModernLinker
03-23 11:53:01.638 21217-21231 I/cr_LibraryLoader: Loading v8_libbase.cr
03-23 11:53:01.640 21217-21231 I/cr_LibraryLoader: Loading v8.cr
03-23 11:53:01.641 21217-21231 E/cr_ChromiumAndroidLinker: LoadLibrary: Failed to obtain fixed address for load
03-23 11:53:01.641 21217-21231 E/cr_LibraryLoader: Unable to load library: libv8.cr.so
03-23 11:53:01.641 21217-21231 E/cr_LibraryLoader: Unable to load library: v8.cr
03-23 11:53:01.641 21217-21231 W/cr_ContentCPSDelegate: Failed to load native library with shared RELRO, retrying without
03-23 11:53:01.641 21217-21231 I/cr_LibraryLoader: Loading v8_libbase.cr
03-23 11:53:01.641 21217-21231 E/cr_ChromiumAndroidLinker: GetLibraryLoadSize: Failed to find library at address 0xbc5a0000
03-23 11:53:01.641 21217-21231 E/cr_ChromiumAndroidLinker: LoadLibrary: Unable to find size for load at 0xbc5a0000
03-23 11:53:01.641 21217-21231 E/cr_LibraryLoader: Unable to load library: libv8_libbase.cr.so
03-23 11:53:01.642 21217-21231 E/cr_LibraryLoader: Unable to load library: v8_libbase.cr
03-23 11:53:01.642 21217-21231 E/cr_ContentCPSDelegate: Failed to load native library on retry
                                                        org.chromium.base.library_loader.ProcessInitException
                                                            at org.chromium.base.library_loader.LibraryLoader.loadAlreadyLocked(LibraryLoader.java:375)
                                                            at org.chromium.base.library_loader.LibraryLoader.loadNowOverrideApplicationContext(LibraryLoader.java:186)
                                                            at org.chromium.content.app.ContentChildProcessServiceDelegate.loadNativeLibrary(ContentChildProcessServiceDelegate.java:131)
                                                            at org.chromium.base.process_launcher.ChildProcessServiceImpl$2.run(ChildProcessServiceImpl.java:188)
                                                            at java.lang.Thread.run(Thread.java:761)
                                                         Caused by: java.lang.UnsatisfiedLinkError: Unable to load library: libv8_libbase.cr.so
                                                            at org.chromium.base.library_loader.ModernLinker.loadLibraryImpl(ModernLinker.java:413)
                                                            at org.chromium.base.library_loader.LibraryLoader.loadAlreadyLocked(LibraryLoader.java:4569)
                                                            at org.chromium.base.library_loader.LibraryLoader.loadNowOverrideApplicationContext(LibraryLoader.java:186) 
                                                            at org.chromium.content.app.ContentChildProcessServiceDelegate.loadNativeLibrary(ContentChildProcessServiceDelegate.java:131) 
                                                            at org.chromium.base.process_launcher.ChildProcessServiceImpl$2.run(ChildProcessServiceImpl.java:188) 
                                                            at java.lang.Thread.run(Thread.java:761) 
03-23 11:53:01.643 21217-21231 I/art: System.exit called, status: -1
03-23 11:53:01.643 21217-21231 I/AndroidRuntime: VM exiting with result code -1, cleanup skipped.

Does it mean shared library is corrupted? Or ss it some loading argument affected that behaviour?

I've tried to remove "_FORTIFY_SOURCE=2" from config but it did not help.

David Turner

unread,
Mar 23, 2018, 9:37:22 AM3/23/18
to Anton Smirnov, Chromium-dev
Try to have a look at the dynamic section of the shared libraries embedded in your APK (e.g. readelf --dynamic /path/to/libfoo.so). The (NEEDED) entries will tell you which other shared libraries this one depends on.
On a regular component build of Chromium, I can see the following for libv8_libbase.cr.so:

 0x00000001 (NEEDED)                     Shared library: [libc++_shared.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [liblog.so]
 0x0000000e (SONAME)                     Library soname: [libv8_libbase.cr.so]

And for libv8.cr.so:

 0x00000001 (NEEDED)                     Shared library: [libicui18n.cr.so]
 0x00000001 (NEEDED)                     Shared library: [libicuuc.cr.so]
 0x00000001 (NEEDED)                     Shared library: [libv8_libbase.cr.so]
 0x00000001 (NEEDED)                     Shared library: [libc++_shared.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x0000000e (SONAME)                     Library soname: [libv8.cr.so]

For the record, only the libraries listed in blue above are provided by the system, the rest must be in the Chromium APK, or you won't be able to load any of these libraries.
In this specific example, this means that v8 depends on the shared libraries or both libc++ and //third_party/icu (in orange above).

Your build may be different, depending on the content of your patches, but that's the most likely explanation.


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/0f97cf2c-8470-4bbd-b403-fc4533e087c7%40chromium.org.

Anton Smirnov

unread,
Mar 26, 2018, 2:34:32 AM3/26/18
to Chromium-dev
David, thanks for the suggestions!

However i was able to make it working just turning off android linker:

diff --git a/base/android/linker/config.gni b/base/android/linker/config.gni
index 27793ffe6ef7..a755cab5433c 100644
--- a/base/android/linker/config.gni
+++ b/base/android/linker/config.gni
@@ -10,4 +10,4 @@ import("//build/config/sanitizers/sanitizers.gni")
 # disable for component builds, see crbug.com/657093.
 # Chromium linker causes instrumentation to return incorrect results.
 chromium_linker_supported =
-    !is_component_build && !enable_profiling && !use_order_profiling && !is_asan
+    !is_component_build && use_chromium_linker && !enable_profiling && !use_order_profiling && !is_asan
diff --git a/build/config/android/config.gni b/build/config/android/config.gni
index e74ee86f4e69..a550a049ab9d 100644
--- a/build/config/android/config.gni
+++ b/build/config/android/config.gni
@@ -172,6 +172,10 @@ if (is_android) {
     # When true, updates all android_aar_prebuilt() .info files during gn gen.
     # Refer to android_aar_prebuilt() for more details.
     update_android_aar_prebuilts = false
+
+    # When false, chromium linker is forced to be Not used for Release build
+    use_chromium_linker = true

David Turner

unread,
Mar 31, 2018, 6:16:19 AM3/31/18
to Anton Smirnov, Chromium-dev
Interesting, you probably worked-around this bug, where the chromium linker doesn't seem to support the component build anymore. I should really take the time to fix this some day :)

Regards,

- Digit

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
Reply all
Reply to author
Forward
0 new messages