Skip to content

In case of Android, give warning only and return the empty sectionInfo. #11615

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

Merged
merged 1 commit into from
Aug 30, 2017

Conversation

amraboelela
Copy link
Contributor

This will avoid unnecessary crashes in Android

Fix for https://bugs.swift.org/browse/SR-5757

Resolves SR-5757.

@milseman
Copy link
Member

@jckarter can you review this? I'm not familiar with this part of the runtime.

@milseman milseman requested a review from jckarter August 25, 2017 00:23
@milseman
Copy link
Member

@swift-ci please smoke test

@jckarter
Copy link
Contributor

Why is the runtime attempting dlopens that fail in the first place? Can we avoid them to begin with?

@amraboelela
Copy link
Contributor Author

@jckarter I found in https://developer.android.com/about/versions/nougat/android-7.0-changes.html

In order to reduce the impact that this restriction may have on currently released apps, a set of libraries that see significant use—such as libandroid_runtime.so, libcutils.so, libcrypto.so, and libssl.so—are temporarily accessible on Android 7.0 (API level 24) for apps targeting API level 23 or lower. If your app loads one of these libraries, logcat generates a warning and a toast appears on the target device to notify you. If you see these warnings, you should update your app to either include its own copy of those libraries or only use the public NDK APIs. Future releases of the Android platform may restrict the use of private libraries altogether and cause your app to crash.

@jckarter
Copy link
Contributor

Thanks @amraboelela. The Swift runtime should only be using dlopen here to get a handle to libraries that have already been loaded into the process, either because the executable is linked against them, or because of a previous successful dlopen. It sounds like the libraries affected by this compatibility hack are things that should not be linked against to begin with. Can we find out why Swift binaries are getting linked against these libraries, and fix the compiler and/or implementation so that it doesn't have to?

@amraboelela
Copy link
Contributor Author

@jckarter yes it actually tries to open tons of libraries. Here are the warnings I get after using my patch:

08-24 14:45:14.293 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libcutils.so': dlopen failed: library "/system/lib/libcutils.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.296 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libutils.so': dlopen failed: library "/system/lib/libutils.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.336 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libbinder.so': dlopen failed: library "/system/lib/libbinder.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.339 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libnativeloader.so': dlopen failed: library "/system/lib/libnativeloader.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.367 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libandroid_runtime.so': dlopen failed: library "/system/lib/libandroid_runtime.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.393 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libwilhelm.so': dlopen failed: library "/system/lib/libwilhelm.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.396 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libc++.so': dlopen failed: library "/system/lib/libc++.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.448 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libbacktrace.so': dlopen failed: library "/system/lib/libbacktrace.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.506 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libnativehelper.so': dlopen failed: library "/system/lib/libnativehelper.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.510 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmemtrack.so': dlopen failed: library "/system/lib/libmemtrack.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.559 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libandroidfw.so': dlopen failed: library "/system/lib/libandroidfw.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.573 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libexpat.so': dlopen failed: library "/system/lib/libexpat.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.575 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libnetutils.so': dlopen failed: library "/system/lib/libnetutils.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.578 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libui.so': dlopen failed: library "/system/lib/libui.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.580 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libgui.so': dlopen failed: library "/system/lib/libgui.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.596 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libinput.so': dlopen failed: library "/system/lib/libinput.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.599 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libinputflinger.so': dlopen failed: library "/system/lib/libinputflinger.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.604 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libcamera_client.so': dlopen failed: library "/system/lib/libcamera_client.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.607 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libcamera_metadata.so': dlopen failed: library "/system/lib/libcamera_metadata.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.610 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libskia.so': dlopen failed: library "/system/lib/libskia.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.624 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libsqlite.so': dlopen failed: library "/system/lib/libsqlite.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.676 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libETC1.so': dlopen failed: library "/system/lib/libETC1.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.678 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libhardware.so': dlopen failed: library "/system/lib/libhardware.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.701 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libhardware_legacy.so': dlopen failed: library "/system/lib/libhardware_legacy.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.704 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libselinux.so': dlopen failed: library "/system/lib/libselinux.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.707 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libsonivox.so': dlopen failed: library "/system/lib/libsonivox.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.709 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libcrypto.so': dlopen failed: library "/system/lib/libcrypto.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.722 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libssl.so': dlopen failed: library "/system/lib/libssl.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.762 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmedia.so': dlopen failed: library "/system/lib/libmedia.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.765 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libjpeg.so': dlopen failed: library "/system/lib/libjpeg.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.769 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libusbhost.so': dlopen failed: library "/system/lib/libusbhost.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.783 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libharfbuzz_ng.so': dlopen failed: library "/system/lib/libharfbuzz_ng.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.790 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libaudioutils.so': dlopen failed: library "/system/lib/libaudioutils.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.792 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libpdfium.so': dlopen failed: library "/system/lib/libpdfium.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.802 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libimg_utils.so': dlopen failed: library "/system/lib/libimg_utils.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.805 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libnetd_client.so': dlopen failed: library "/system/lib/libnetd_client.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.822 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libradio.so': dlopen failed: library "/system/lib/libradio.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.825 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libsoundtrigger.so': dlopen failed: library "/system/lib/libsoundtrigger.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.827 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libminikin.so': dlopen failed: library "/system/lib/libminikin.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.830 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libprocessgroup.so': dlopen failed: library "/system/lib/libprocessgroup.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.844 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libnativebridge.so': dlopen failed: library "/system/lib/libnativebridge.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.847 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libradio_metadata.so': dlopen failed: library "/system/lib/libradio_metadata.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.849 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmemunreachable.so': dlopen failed: library "/system/lib/libmemunreachable.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.862 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libhwui.so': dlopen failed: library "/system/lib/libhwui.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.872 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright.so': dlopen failed: library "/system/lib/libstagefright.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.875 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_foundation.so': dlopen failed: library "/system/lib/libstagefright_foundation.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.877 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libeffects.so': dlopen failed: library "/system/lib/libeffects.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.890 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_http_support.so': dlopen failed: library "/system/lib/libstagefright_http_support.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.894 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libbase.so': dlopen failed: library "/system/lib/libbase.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.896 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libunwind.so': dlopen failed: library "/system/lib/libunwind.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.921 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libsync.so': dlopen failed: library "/system/lib/libsync.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.924 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libpng.so': dlopen failed: library "/system/lib/libpng.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.926 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libft2.so': dlopen failed: library "/system/lib/libft2.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.929 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libdng_sdk.so': dlopen failed: library "/system/lib/libdng_sdk.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.943 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libpiex.so': dlopen failed: library "/system/lib/libpiex.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.945 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libpcre.so': dlopen failed: library "/system/lib/libpcre.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.948 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libpackagelistparser.so': dlopen failed: library "/system/lib/libpackagelistparser.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.961 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libnbaio.so': dlopen failed: library "/system/lib/libnbaio.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.964 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libspeexresampler.so': dlopen failed: library "/system/lib/libspeexresampler.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.967 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libprotobuf-cpp-lite.so': dlopen failed: library "/system/lib/libprotobuf-cpp-lite.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:14.984 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libRScpp.so': dlopen failed: library "/system/lib/libRScpp.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:14.987 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libdrmframework.so': dlopen failed: library "/system/lib/libdrmframework.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.002 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmediautils.so': dlopen failed: library "/system/lib/libmediautils.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.004 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libopus.so': dlopen failed: library "/system/lib/libopus.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.007 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_omx.so': dlopen failed: library "/system/lib/libstagefright_omx.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.022 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_yuv.so': dlopen failed: library "/system/lib/libstagefright_yuv.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.024 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libvorbisidec.so': dlopen failed: library "/system/lib/libvorbisidec.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.027 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libpowermanager.so': dlopen failed: library "/system/lib/libpowermanager.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.030 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_enc_common.so': dlopen failed: library "/system/lib/libstagefright_enc_common.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.056 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_avc_common.so': dlopen failed: library "/system/lib/libstagefright_avc_common.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.059 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/liblzma.so': dlopen failed: library "/system/lib/liblzma.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.073 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libbinary_parse.so': dlopen failed: library "/system/lib/libbinary_parse.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.076 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libimage_type_recognition.so': dlopen failed: library "/system/lib/libimage_type_recognition.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.080 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libtiff_directory.so': dlopen failed: library "/system/lib/libtiff_directory.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.102 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libRS_internal.so': dlopen failed: library "/system/lib/libRS_internal.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.105 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libbcinfo.so': dlopen failed: library "/system/lib/libbcinfo.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.108 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libLLVM.so': dlopen failed: library "/system/lib/libLLVM.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.120 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libart.so': dlopen failed: library "/system/lib/libart.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.124 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libsigchain.so': dlopen failed: library "/system/lib/libsigchain.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.127 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/liblz4.so': dlopen failed: library "/system/lib/liblz4.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.129 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot.oat': dlopen failed: library "/system/framework/arm/boot.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.156 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-core-libart.oat': dlopen failed: library "/system/framework/arm/boot-core-libart.oat" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.158 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-conscrypt.oat': dlopen failed: library "/system/framework/arm/boot-conscrypt.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.161 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-okhttp.oat': dlopen failed: library "/system/framework/arm/boot-okhttp.oat" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.165 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-core-junit.oat': dlopen failed: library "/system/framework/arm/boot-core-junit.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.168 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-bouncycastle.oat': dlopen failed: library "/system/framework/arm/boot-bouncycastle.oat" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.180 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-ext.oat': dlopen failed: library "/system/framework/arm/boot-ext.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.183 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-framework.oat': dlopen failed: library "/system/framework/arm/boot-framework.oat" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.187 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-telephony-common.oat': dlopen failed: library "/system/framework/arm/boot-telephony-common.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.190 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-voip-common.oat': dlopen failed: library "/system/framework/arm/boot-voip-common.oat" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.212 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-ims-common.oat': dlopen failed: library "/system/framework/arm/boot-ims-common.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.215 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-apache-xml.oat': dlopen failed: library "/system/framework/arm/boot-apache-xml.oat" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.217 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/framework/arm/boot-org.apache.http.legacy.boot.oat': dlopen failed: library "/system/framework/arm/boot-org.apache.http.legacy.boot.oat" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.299 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmediadrm.so': dlopen failed: library "/system/lib/libmediadrm.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.352 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libart-compiler.so': dlopen failed: library "/system/lib/libart-compiler.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.355 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libvixl.so': dlopen failed: library "/system/lib/libvixl.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.358 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libjavacore.so': dlopen failed: library "/system/lib/libjavacore.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.361 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libopenjdk.so': dlopen failed: library "/system/lib/libopenjdk.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.374 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libopenjdkjvm.so': dlopen failed: library "/system/lib/libopenjdkjvm.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.377 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmedia_jni.so': dlopen failed: library "/system/lib/libmedia_jni.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.379 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libmtp.so': dlopen failed: library "/system/lib/libmtp.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.393 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libexif.so': dlopen failed: library "/system/lib/libexif.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.398 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libstagefright_amrnb_common.so': dlopen failed: library "/system/lib/libstagefright_amrnb_common.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.411 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libjavacrypto.so': dlopen failed: library "/system/lib/libjavacrypto.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.413 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libkeystore-engine.so': dlopen failed: library "/system/lib/libkeystore-engine.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.416 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libkeystore_binder.so': dlopen failed: library "/system/lib/libkeystore_binder.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.419 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libkeymaster_messages.so': dlopen failed: library "/system/lib/libkeymaster_messages.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.432 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libsoftkeymasterdevice.so': dlopen failed: library "/system/lib/libsoftkeymasterdevice.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.435 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libkeymaster1.so': dlopen failed: library "/system/lib/libkeymaster1.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.438 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/egl/libEGL_emulation.so': dlopen failed: library "/system/lib/egl/libEGL_emulation.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.463 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libOpenglSystemCommon.so': dlopen failed: library "/system/lib/libOpenglSystemCommon.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.465 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/lib_renderControl_enc.so': dlopen failed: library "/system/lib/lib_renderControl_enc.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.468 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libGLESv2_enc.so': dlopen failed: library "/system/lib/libGLESv2_enc.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.485 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libGLESv1_enc.so': dlopen failed: library "/system/lib/libGLESv1_enc.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.488 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/egl/libGLESv1_CM_emulation.so': dlopen failed: library "/system/lib/egl/libGLESv1_CM_emulation.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.495 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/egl/libGLESv2_emulation.so': dlopen failed: library "/system/lib/egl/libGLESv2_emulation.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.498 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libcompiler_rt.so': dlopen failed: library "/system/lib/libcompiler_rt.so" wasn't loaded and RTLD_NOLOAD prevented it 08-24 14:45:15.501 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on /system/lib/libwebviewchromium_loader.so': dlopen failed: library "/system/lib/libwebviewchromium_loader.so" wasn't loaded and RTLD_NOLOAD prevented it
08-24 14:45:15.504 7242-7242/com.example.addswift A/SwiftRuntime: dlopen() failed on `/data/app/com.example.addswift-2/oat/arm/base.odex': dlopen failed: library "/data/app/com.example.addswift-2/oat/arm/base.odex" wasn't loaded and RTLD_NOLOAD prevented it

@jckarter
Copy link
Contributor

If you ldd the executable, is it linked directly against those libraries?

@jckarter
Copy link
Contributor

Like @gparker42 suggests in https://twitter.com/gparker/status/901168354001436672, it might be better to have the runtime just skip trying to load any libraries under /system on Android (which are unlikely to contain any Swift bits anyway), instead of ignoring potential problems altogether.

@amraboelela
Copy link
Contributor Author

amraboelela commented Aug 25, 2017

I tried in adb shell:

generic:/data/local/tmp $ ldd libswiftCore.so
/system/bin/sh: ldd: not found

@jckarter
Copy link
Contributor

You may need to do it on your host device instead of within Android itself.

@amraboelela
Copy link
Contributor Author

I am running it using Mac OS, but those libs are in arm v7 format. And there is no executable as it is running though a java activity.

@gonzalolarralde
Copy link
Contributor

@jckarter @amraboelela it is my understanding that you're not supposed to link them, but it doesn't mean that the libraries that you can link against, can't link against any of the "prohibited" dependencies, so yeah, there's some weird logic there where you end up with a lib in memory that you're not supposed to specifically reference.

In #10836 we've discussed this problem, but coming from a different issue: one of the libraries that is passed in that list as per bionic's dl_iterate_phdrimplementation is the executable or shared library itself. In that PR we agreed on ignoring whatever that can't be opened, but if there's another approach that we may want to use, more than happy to do any research required for it.

There's a list called permitted_paths that is being referenced when the error of a denied library is tried to be open happens is shown, @ephemer tried to lookup where that list is coming from so we can match against it but it is my understanding that he couldn't get there without referencing more prohibited stuff.

07-24 16:51:53.312 1746-1746/? E/linker: library "/system/lib/libnativeloader.so" ("/system/lib/libnativeloader.so") needed or dlopened by "/system/lib/libnativeloader.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="/data/app/com.xyz-1/lib/arm:/data/app/com.xyz-1/base.apk!/lib/armeabi-v7a", permitted_paths="/data:/mnt/expand:/data/data/com.xyz"]

Sorry for the noise if any, hope this is useful.

@jckarter
Copy link
Contributor

If there were an alternate way to get a dlsym-able handle more directly from the phdr instead of having to go back through dlopen, that seems to me like it'd be a lot less brittle. Android seems to have a lot of quirks here.

@amraboelela
Copy link
Contributor Author

amraboelela commented Aug 25, 2017

I used ndk-depends which is the replacement of ldd in android idk, and I got:

$ ndk-depends libswiftCore.so
libswiftCore.so
liblog.so
libicui18nswift.so
libicuucswift.so
libstdc++.so
libicudataswift.so
libz.so
libc++_shared.so
libm.so
libdl.so
libc.so

And I tried ndk-depends on all these libs and none of them link with libcutils.so or any of the libs mentioned in the warnings.

@jckarter
Copy link
Contributor

OK, as long as we aren't inappropriately linking against anything we aren't supposed to, then it should be OK to skip over trying to open libraries in /system. I don't think we want to swallow all dlopen failures, since a silent failure to register a library that does have Swift code in it would lead to bizarre runtime behavior changes downstream.

@amraboelela
Copy link
Contributor Author

ok but some of these libs comes from system, like liblog.so, libz.so,libm.so,libdl.so,libc.so

@jckarter
Copy link
Contributor

Sure, but none of those is going to have any Swift code in them.

@amraboelela
Copy link
Contributor Author

ok, good, i was also thinking about looking into the lib name path and check if it include /system/lib to ignore it. But the question is, why do we link to those libs in the first place?

@jckarter
Copy link
Contributor

Those are (AFAICT) still public libraries. The Swift runtime relies on the standard C/C++ libraries as well as ICU for various things, so it's expected that it (and most executables) would link against them.

@johnno1962
Copy link
Contributor

johnno1962 commented Aug 25, 2017

Hi, Sorry to butt in, but I’m not sure there is a way to avoid just skipping shared libs that don’t load. On my device (LG Lollipop) the imageName argument to getSectionInfo does not include the full path and there is an imageName passed in that doesn't correspond to any shared library: e.g.

W/SwiftRuntime(27353): dlopen() 0xb6f97004 `(null)': undefined symbol: JNI_OnLoad
W/SwiftRuntime(27353): dlopen() 0x0 `net.zhuoweizhang.swifthello': dlopen failed: library "net.zhuoweizhang.swifthello" not found
W/SwiftRuntime(27353): dlopen() 0xb6f97154 `libsigchain.so': (null)
W/SwiftRuntime(27353): dlopen() 0xb6f972a4 `libandroid_runtime.so': undefined symbol: .swift2_protocol_conformances_start
W/SwiftRuntime(27353): dlopen() 0xb6f973f4 `libbinder.so': undefined symbol: .swift2_protocol_conformances_start
W/SwiftRuntime(27353): dlopen() 0xb6f97544 `libc.so': undefined symbol: .swift2_protocol_conformances_start
...

‘net.zhuoweizhang.swifthello' is identifier of the Java side of the app. I suppose where there is a path you could not even try to load anything that starts with /system or libs that don’t end in '.so’.

How about:

#ifdef __ANDROID__
  llvm::StringRef imagePath = imageName;
  if (imagePath.startswith("/system/lib") || (imageName && !imagePath.endswith(".so")))
    return sectionInfo;
#endif
  void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD);
  if (!handle) {
    fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName, dlerror());
  }

This works on my LG. @amraboelela does this work on your V7 device?

@amraboelela
Copy link
Contributor Author

Hi @johnn1962
Yes your suggestion sounds ok. I can test it later and let you know.

@amraboelela
Copy link
Contributor Author

amraboelela commented Aug 27, 2017

ok I changed the code to @ johnn1962 suggestion. I am currently rebuilding swift with the new code then I'll test it after.

@amraboelela
Copy link
Contributor Author

I tested it with the new change and it is working fine.

@amraboelela amraboelela force-pushed the android-getSectionInfo branch from c260756 to 3ce27b0 Compare August 27, 2017 13:14
@johnno1962
Copy link
Contributor

Excellent, I’ll be happy to see this merged! Do you think the warning message is needed in the final version?

@jckarter
Copy link
Contributor

@swift-ci Please smoke test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

#ifdef __ANDROID__
llvm::StringRef imagePath = llvm::StringRef(imageName);
if (imagePath.startswith("/system/lib") || (imageName && !imagePath.endswith(".so"))) {
warning(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName, dlerror());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this warning is necessary, since failure in this case may be expected. It'll just noise up logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep the warning so hopefully somebody later would figure out the reason we are trying to link to all these libraries and try to avoid it. But I can remove it, no problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the warning in the final commit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It sounds like we're trying to load these private libraries because they're transitive dependencies of public libraries, but Android's dlopen is special-cased to reject attempts to open them explicitly, which is gross but a situation we can't do much about.

Copy link
Collaborator

@xwu xwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by nit: this file uses two spaces for indents and wraps at 80 characters per line; please restore the original indentation and wrapping and conform new code to the same convention.

@amraboelela
Copy link
Contributor Author

I fixed the indentation, even though I don't understand why don't we keep the standard indentation of the Xcode?

@amraboelela amraboelela force-pushed the android-getSectionInfo branch from 83208af to 8ca8d91 Compare August 28, 2017 18:03
@gonzalolarralde
Copy link
Contributor

@amraboelela @johnno1962 question: how is this dealing with ignoring the path to self? it's my understanding that this won't work when embedding the library in an APK, as we expect it to end with .so, right?

@johnno1962
Copy link
Contributor

Not with you. Code will still try to open it if you put a loaded library in the .apk without .so at the end.

Copy link
Collaborator

@xwu xwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project largely follows LLVM conventions for style rather than Xcode’s defaults. I’ve pointed out a few remaining nits.

#ifdef __ANDROID__
llvm::StringRef imagePath = llvm::StringRef(imageName);
if (imagePath.startswith("/system/lib") ||
(imageName && !imagePath.endswith(".so"))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more space is required for this line.

return sectionInfo;
}
#endif
fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName, dlerror());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the original line break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jckarter
Copy link
Contributor

@swift-ci Please smoke test

…ry doesn't end with .so, we will give warning only and return empty sectionInfo.
@amraboelela amraboelela force-pushed the android-getSectionInfo branch from 9f8a7c7 to 2447658 Compare August 30, 2017 17:27
@amraboelela
Copy link
Contributor Author

Is it ready to merge now?

@jckarter
Copy link
Contributor

@swift-ci Please smoke test

@jckarter jckarter merged commit c37b5a8 into swiftlang:master Aug 30, 2017
@jckarter
Copy link
Contributor

Thanks @amraboelela !

@johnno1962
Copy link
Contributor

Thanks @jckarter

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

Successfully merging this pull request may close these issues.

6 participants