dalvik hangs on loading shared library

329 views
Skip to first unread message

ryanjulian

unread,
Jul 19, 2010, 1:40:40 PM7/19/10
to android-ndk
Hi All,

I'm trying to debug an unusual problem with my (crystax) NDK app.
Dalvik hangs when I try to load my shared library with
system.loadLibrary() . I've confirmed that the program never reaches
JNI_OnLoad(), it just hangs.

This is even more bizarre because this code is a minor modification of
another app, which works perfectly.

Here's the LogCat output of the launch:

07-19 17:33:39.902: DEBUG/AndroidRuntime(1083): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
07-19 17:33:39.902: DEBUG/AndroidRuntime(1083): CheckJNI is ON
07-19 17:33:40.136: DEBUG/AndroidRuntime(1083): --- registering native
functions ---
07-19 17:33:40.782: DEBUG/AndroidRuntime(1083): Shutting down VM
07-19 17:33:40.792: DEBUG/dalvikvm(1083): Debugger has detached;
object registry had 1 entries
07-19 17:33:40.812: INFO/AndroidRuntime(1083): NOTE: attach of thread
'Binder Thread #3' failed
07-19 17:33:41.283: DEBUG/AndroidRuntime(1091): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
07-19 17:33:41.283: DEBUG/AndroidRuntime(1091): CheckJNI is ON
07-19 17:33:41.466: DEBUG/AndroidRuntime(1091): --- registering native
functions ---
07-19 17:33:42.143: INFO/ActivityManager(60): Starting activity:
Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] flg=0x10000000
cmp=com.example.hellotopics/.HelloTopics }
07-19 17:33:42.211: DEBUG/AndroidRuntime(1091): Shutting down VM
07-19 17:33:42.254: DEBUG/dalvikvm(1091): Debugger has detached;
object registry had 1 entries
07-19 17:33:42.287: INFO/AndroidRuntime(1091): NOTE: attach of thread
'Binder Thread #3' failed
07-19 17:33:42.322: INFO/ActivityManager(60): Start proc
com.example.hellotopics for activity
com.example.hellotopics/.HelloTopics: pid=1098 uid=10032 gids={3003}
07-19 17:33:42.963: DEBUG/dalvikvm(1098): Trying to load lib /data/
data/com.example.hellotopics/lib/libhello-topics.so 0x43dc2a70
07-19 17:33:52.171: WARN/ActivityManager(60): Launch timeout has
expired, giving up wake lock!
07-19 17:33:52.735: WARN/ActivityManager(60): Activity idle timeout
for HistoryRecord{43ed15a8 com.example.hellotopics/.HelloTopics}
07-19 17:33:57.812: DEBUG/dalvikvm(793): GC_EXPLICIT freed 717
objects / 39472 bytes in 77ms

And here's an strace (starting just before the call to
system.loadLibrary() ):
# strace -p1126
Process 1126 attached - interrupt to quit
setup() = -1 ETIMEDOUT (Connection
timed out)
access("/system/lib/libhello-topics.so", F_OK) = -1 ENOENT (No such
file or directory)
brk(0x211000) = 0x211000
access("/data/data/com.example.hellotopics/lib/libhello-topics.so",
F_OK) = 0
writev(3, [{"\3", 1}, {"dalvikvm\0", 9}, {"Trying to load lib /data/
data/co"..., 86}], 3) = 96
stat64("/data/data/com.example.hellotopics/lib/libhello-topics.so",
{st_mode=S_IFREG|0755, st_size=3713021, ...}) = 0
open("/data/data/com.example.hellotopics/lib/libhello-topics.so",
O_RDONLY|O_LARGEFILE) = 29
lseek(29, 0, SEEK_SET) = 0
read(29, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0��\20\000"...,
4096) = 4096
lseek(29, -8, SEEK_END) = 3713013
read(29, "IcEC2Ej\0", 8) = 8
mmap2(0x80c00000, 2396160, PROT_READ|PROT_EXEC, MAP_PRIVATE|
MAP_ANONYMOUS, -1, 0) = 0x80c00000
mmap2(0x80c00000, 2364112, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
29, 0) = 0x80c00000
mprotect(0x80c00000, 2367488, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x80e42000, 17048, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
29, 0x241) = 0x80e42000
mmap2(0x80e47000, 5920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_ANONYMOUS, -1, 0) = 0x80e47000
close(29) = 0
mprotect(0x80c00000, 2367488, PROT_READ|PROT_EXEC) = 0
getuid32() = 10032
geteuid32() = 10032
getgid32() = 10032
getegid32() = 10032
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
recv(-1345054140,

(after which it hangs forever)

I greatly appreciate any insight you can lend.

Angus Lees

unread,
Jul 20, 2010, 9:06:02 AM7/20/10
to andro...@googlegroups.com
On Tue, Jul 20, 2010 at 03:40, ryanjulian <ryanj...@gmail.com> wrote:
> recv(-1345054140,

This last number looks a bit suspect - I presume there is some memory
corruption somewhere.

Your next step is probably to attach to the hung process with gdb and
see what the stacktrace looks like. If it _is_ stack memory
corruption, then you might still get garbage with that approach so
you'll need to single step back through the module load and see where
things go awry :/

- Gus

ryanjulian

unread,
Jul 21, 2010, 1:19:28 PM7/21/10
to android-ndk
Update:

I've confirmed dlopen() is hanging the load, but I haven't been able
to get any farther than that.

The offending library is a build of Google Protocol Buffers (http://
code.google.com/p/protobuf/)

Another interesting note is that I can compile and run the "lite"
subset of the library, but the full protobuf library causes dlopen to
hang. It also hangs dlopen if I statically link (full) libprotobuf to
my other library (and then try to System.loadLibrary() on that
library).

Here's the Android.mk (placed in $PROTOBUF_ROOT/src) for protocol
buffers, in case anyone's interested:

(to compile protobuf-lite, just commend out all source files after but
not including "google/protobuf/io/zero_copy_stream_impl_lite.cc")
----------------------------- BEGIN
ANDROID.MK-----------------------------
LOCAL_PATH := $(call my-dir)

# Build the module
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := \
google/protobuf/stubs/common.cc \
google/protobuf/stubs/once.cc \
google/protobuf/stubs/hash.cc \
google/protobuf/extension_set.cc \
google/protobuf/generated_message_util.cc \
google/protobuf/message_lite.cc \
google/protobuf/repeated_field.cc \
google/protobuf/wire_format_lite.cc \
google/protobuf/io/coded_stream.cc \
google/protobuf/io/zero_copy_stream.cc \
google/protobuf/io/zero_copy_stream_impl_lite.cc
\
google/protobuf/stubs/strutil.cc \
google/protobuf/stubs/substitute.cc \
google/protobuf/stubs/structurally_valid.cc \
google/protobuf/descriptor.cc \
google/protobuf/descriptor.pb.cc \
google/protobuf/descriptor_database.cc \
google/protobuf/dynamic_message.cc \
google/protobuf/extension_set_heavy.cc \
google/protobuf/generated_message_reflection.cc \
google/protobuf/message.cc \
google/protobuf/reflection_ops.cc \
google/protobuf/service.cc \
google/protobuf/text_format.cc \
google/protobuf/unknown_field_set.cc \
google/protobuf/wire_format.cc \
google/protobuf/io/gzip_stream.cc \
google/protobuf/io/printer.cc \
google/protobuf/io/tokenizer.cc \
google/protobuf/io/zero_copy_stream_impl.cc \
google/protobuf/compiler/importer.cc \
google/protobuf/compiler/parser.cc


LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CPP_EXTENSION := .cc
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../


include $(BUILD_SHARED_LIBRARY)
----------------------------- END
ANDROID.MK-----------------------------

----------------------------- BEGIN
CONFIG.H-----------------------------
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */

/* the name of <hash_set> */
#define HASH_MAP_CLASS unordered_map

/* the location of <hash_map> */
#define HASH_MAP_H <tr1/unordered_map>

/* the namespace of hash_map/hash_set */
#define HASH_NAMESPACE std::tr1

/* the name of <hash_set> */
#define HASH_SET_CLASS unordered_set

/* the location of <hash_set> */
#define HASH_SET_H <tr1/unordered_set>

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1

/* Define to 1 if you have the `ftruncate' function. */
#define HAVE_FTRUNCATE 1

/* define if the compiler has hash_map */
#define HAVE_HASH_MAP 1

/* define if the compiler has hash_set */
#define HAVE_HASH_SET 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1

/* Define to 1 if you have the `mkdir' function. */
#define HAVE_MKDIR 1

/* Define if you have POSIX threads libraries and header files. */
#define HAVE_PTHREAD 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1

/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the `strtol' function. */
#define HAVE_STRTOL 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Enable classes using zlib compression. */
/*#define HAVE_ZLIB 1*/

/* Define to the sub-directory in which libtool stores uninstalled
libraries.
*/
#define LT_OBJDIR ".libs/"

/* Name of package */
#define PACKAGE "protobuf"

/* Define to the address where bug reports for this package should be
sent. */
#define PACKAGE_BUGREPORT "prot...@googlegroups.com"

/* Define to the full name of this package. */
#define PACKAGE_NAME "Protocol Buffers"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "Protocol Buffers 2.3.0"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "protobuf"

/* Define to the version of this package. */
#define PACKAGE_VERSION "2.3.0"

/* Define to necessary symbol if this constant uses a non-standard
name on
your system. */
/* #undef PTHREAD_CREATE_JOINABLE */

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Version number of package */
#define VERSION "2.3.0"

/* Define to 1 if on AIX 3.
System headers sometimes define this.
We just want to avoid a redefinition error message. */
#ifndef _ALL_SOURCE
/* # undef _ALL_SOURCE */
#endif

/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif

/* Define to 1 if on MINIX. */
/* #undef _MINIX */

/* Define to 2 if the system does not provide POSIX.1 features except
with
this defined. */
/* #undef _POSIX_1_SOURCE */

/* Define to 1 if you need to in order for `stat' and other things to
work. */
/* #undef _POSIX_SOURCE */

/* Enable extensions on Solaris. */
#ifndef __EXTENSIONS__
# define __EXTENSIONS__ 1
#endif
#ifndef _POSIX_PTHREAD_SEMANTICS
# define _POSIX_PTHREAD_SEMANTICS 1
#endif
#ifndef _TANDEM_SOURCE
# define _TANDEM_SOURCE 1
#endif
----------------------------- END
CONFIG.H-----------------------------

On Jul 20, 6:06 am, Angus Lees <al...@google.com> wrote:
Reply all
Reply to author
Forward
0 new messages