Shared Object fails to LOAD on linux after just Declaring std::map<int, int>

0

I am trying to build and load a shared library SO file and it was loading just fine. It fails to load when I added the below lines to create a map and it fails to load. It compiles and builds fine. I am using Eclipse & CDT.

Edit 1: Just by adding map<int, int> test, the size of SO file increased to 253 KB from 213 KB. I am not sure if the load issues are something to do with the increase in size. Below is the command for my java process, which is trying to load the SO file.

[java, -Xms256M, -Xmx512M, -XX:+UseG1GC, -XX:+ScavengeBeforeFullGC, -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses, -XX:+UseStringDeduplication, -XX:MaxMetaspaceSize=300M, -XX:MetaspaceSize=100M, -XX:CompressedClassSpaceSize=128M, -Djava.awt.headless=true, -Dspring.profiles.active=prod-drivers,test-service-5.0.4-SNAPSHOT, -Ddcx.cs.rabbitmq.host=localhost, -Ddcx.cs.rabbitmq.port=5672, -jar, test-service-5.0.4-SNAPSHOT.jar, -Dfile.encoding=UTF-8, -Xdebug, -Xrunjdwp:transport=dt_socket,server=y,address=5766,suspend=n, -Dcom.sun.management.jmxremote, -Dcom.sun.management.jmxremote.port=5300, -Dcom.sun.management.jmxremote.rmi.port=5300, -Dcom.sun.management.jmxremote.authenticate=false, -Dcom.sun.management.jmxremote.ssl=false, -Djava.rmi.server.hostname=127.0.0.1, -Dspring.liveBeansView.mbeanDomain, -Dspring.application.admin.enabled=true, -DLOGSERIAL=null]

Edit 2: libstdc++.so.6 is already there in /usr/lib/ in my target environment

using namespace std;
map<int, int> test;

Below is my makefile

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include trunk/src/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: libLinuxFTDI.so

# Tool invocations
libLinuxFTDI.so: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: Cross G++ Linker'
    arm-linux-gnueabihf-g++ -L"C:\Users\srika\OneDrive\Desktop\LinuxFTDI\trunk\ftd2xx\arm" -shared -Wl,-soname=mftdi -o "libLinuxFTDI.so" $(OBJS) $(USER_OBJS) $(LIBS)
    @echo 'Finished building target: $@'
    @echo ' '

# Other Targets
clean:
    -$(RM) $(LIBRARIES)$(CC_DEPS)$(C++_DEPS)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) libLinuxFTDI.so
    -@echo ' '

.PHONY: all clean dependents

-include ../makefile.targets

It is derived from my eclipse options.

Below is the java crash report

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x76f415b0, pid=30591, tid=0x4fe5f470
#
# JRE version: OpenJDK Runtime Environment (8.0_121-b13) (build 1.8.0_121-internal-b13)
# Java VM: OpenJDK Client VM (25.121-b13 mixed mode linux-aarch32 )
# Problematic frame:
# C  [ld-linux-armhf.so.3+0x85b0]
#
# Core dump written. Default location: /opt/dcx-cs/driver/core or core.30591
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x50526800):  JavaThread "IPM-2B" daemon [_thread_in_native, id=30899, stack(0x4fe10000,0x4fe60000)]

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x00000004

Registers:
R0=0x00000010
R1=0x40000000
R2=0x00000000
R3=0x00000000
R4=0x00000001
R5=0x00000000
R6=0x00000001
R7=0x4fe5d6f0
R8=0x76f61000
R9=0x00000001
R10=0x76e18afd
R11=0x52878058
R12=0x52877ed4
R13=0x4fe5d6e0
R14=0x76f47321
R15=0x76f415b0

Top of Stack: (sp=0x4fe5d6e0)
0x4fe5d6e0:   00000047 00000000 00000001 52878058
0x4fe5d6f0:   00000000 00000065 00000000 0000002c
0x4fe5d700:   00000077 00000000 00000000 00000000
0x4fe5d710:   76f61568 00000000 00000004 4fe5d6e8
0x4fe5d720:   00000000 00000000 00000084 52878210
0x4fe5d730:   00000001 00000001 4fe5d6e8 52877ed0
0x4fe5d740:   00000002 4fe5d6e8 00000000 00000000
0x4fe5d750:   00000000 00000045 00000000 00000089 

Instructions: (pc=0x76f415b0)
0x76f41590:   00 2b 40 f0 f0 84 fb 61 3a 6c db f8 7c 30 02 f0
0x76f415a0:   01 04 db f8 34 20 00 2b 0c bf 00 23 04 f0 01 03
0x76f415b0:   52 68 ba 62 1b b3 db f8 2c 30 5b 68 59 68 21 b1
0x76f415c0:   db f8 00 20 0a 44 cb f8 10 22 7a 6b c3 f8 04 b0 

Register to memory mapping:

R0=0x00000010 is an unknown value
R1=0x40000000 is an unknown value
R2=0x00000000 is an unknown value
R3=0x00000000 is an unknown value
R4=0x00000001 is an unknown value
R5=0x00000000 is an unknown value
R6=0x00000001 is an unknown value
R7=0x4fe5d6f0 is pointing into the stack for thread: 0x50526800
R8=0x76f61000: <offset 0x28000> in /lib/ld-linux-armhf.so.3 at 0x76f39000
R9=0x00000001 is an unknown value
R10=0x76e18afd: <offset 0xafd> in /lib/libdl.so.2 at 0x76e18000
R11=0x52878058 is an unknown value
R12=0x52877ed4 is an unknown value
R13=0x4fe5d6e0 is pointing into the stack for thread: 0x50526800
R14=0x76f47321: <offset 0xe321> in /lib/ld-linux-armhf.so.3 at 0x76f39000
R15=0x76f415b0: <offset 0x85b0> in /lib/ld-linux-armhf.so.3 at 0x76f39000


Stack: [0x4fe10000,0x4fe60000],  sp=0x4fe5d6e0,  free space=309k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ld-linux-armhf.so.3+0x85b0]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  java.lang.ClassLoader$NativeLibrary.load(Ljava/lang/String;Z)V+0
j  java.lang.ClassLoader.loadLibrary0(Ljava/lang/Class;Ljava/io/File;)Z+328
j  java.lang.ClassLoader.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)V+48
j  java.lang.Runtime.load0(Ljava/lang/Class;Ljava/lang/String;)V+57
j  java.lang.System.load(Ljava/lang/String;)V+7
j  com.masimo.drivers.mdk.serial.util.NativeLibraryUtil.loadNativeLibrary(Ljava/lang/String;)Z+81
j  com.masimo.drivers.mdk.serial.jni.D2XXStack.<clinit>()V+22
v  ~StubRoutines::call_stub
j  com.masimo.drivers.mdk.serial.port.D2XXPort.<init>()V+1
j  com.nanthealth.drivers.common.management.SerialDriverInstance.getCom()Lcom/masimo/drivers/mdk/interfaces/communication/SerialDeviceCom;+46
j  com.nanthealth.drivers.philips.ipm.driver.PhilipsIPMDriver.createCoreDeviceDriver()V+49
j  com.nanthealth.drivers.common.management.DriverInstance.run()V+29
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
=>0x50526800 JavaThread "IPM-2B" daemon [_thread_in_native, id=30899, stack(0x4fe10000,0x4fe60000)]
  0x754da400 JavaThread "ForkJoinPool.commonPool-worker-0" daemon [_thread_blocked, id=30898, stack(0x4ff60000,0x4ffb0000)]
  0x52848800 JavaThread "Camel (camel-1) thread #8 - WireTap" daemon [_thread_blocked, id=30897, stack(0x4ffb0000,0x50000000)]
  0x52847c00 JavaThread "Camel (camel-1) thread #7 - RabbitMQConsumer" daemon [_thread_blocked, id=30896, stack(0x50d4f000,0x50d9f000)]
  0x75407800 JavaThread "DestroyJavaVM" [_thread_blocked, id=30592, stack(0x75523000,0x75573000)]
  0x50538000 JavaThread "Camel (camel-1) thread #6 - RabbitMQConsumer" daemon [_thread_blocked, id=30832, stack(0x50000000,0x50050000)]
  0x5156a400 JavaThread "pool-2-thread-12" [_thread_blocked, id=30831, stack(0x50050000,0x500a0000)]
  0x50cd1c00 JavaThread "AMQP Connection 127.0.0.1:5672" [_thread_in_native, id=30830, stack(0x500a0000,0x500f0000)]
  0x528fe000 JavaThread "Camel (camel-1) thread #5 - RabbitMQConsumer" daemon [_thread_blocked, id=30829, stack(0x500f0000,0x50140000)]
  0x51581c00 JavaThread "pool-2-thread-10" [_thread_blocked, id=30828, stack(0x50140000,0x50190000)]
  0x51580800 JavaThread "AMQP Connection 127.0.0.1:5672" [_thread_in_native, id=30827, stack(0x50190000,0x501e0000)]
  0x51fa6400 JavaThread "Camel (camel-1) thread #4 - seda://heartbeats" daemon [_thread_blocked, id=30826, stack(0x501e0000,0x50230000)]
  0x50c2a400 JavaThread "Camel (camel-1) thread #3 - seda://events" daemon [_thread_blocked, id=30825, stack(0x50230000,0x50280000)]
  0x51f34c00 JavaThread "Camel (camel-1) thread #2 - seda://waveform-envelopes" daemon [_thread_blocked, id=30824, stack(0x50280000,0x502d0000)]
  0x51f33c00 JavaThread "Camel (camel-1) thread #1 - seda://envelopes" daemon [_thread_blocked, id=30823, stack(0x502d0000,0x50320000)]
  0x50cd7c00 JavaThread "pool-2-thread-8" [_thread_blocked, id=30822, stack(0x50320000,0x50370000)]
  0x50c85c00 JavaThread "AMQP Connection 0:0:0:0:0:0:0:1:5672" [_thread_in_native, id=30821, stack(0x50370000,0x503c0000)]
  0x525db000 JavaThread "pool-2-thread-6" [_thread_blocked, id=30820, stack(0x503c0000,0x50410000)]
  0x525da000 JavaThread "AMQP Connection 0:0:0:0:0:0:0:1:5672" [_thread_in_native, id=30819, stack(0x50410000,0x50460000)]
  0x5152a400 JavaThread "pool-2-thread-4" [_thread_blocked, id=30818, stack(0x50460000,0x504b0000)]
  0x51808000 JavaThread "AMQP Connection 127.0.0.1:5672" [_thread_in_native, id=30817, stack(0x504b0000,0x50500000)]
  0x520f2800 JavaThread "pool-2-thread-2" [_thread_blocked, id=30816, stack(0x50810000,0x50860000)]
  0x52504c00 JavaThread "AMQP Connection 0:0:0:0:0:0:0:1:5672" [_thread_in_native, id=30815, stack(0x50860000,0x508b0000)]
  0x523f0c00 JavaThread "scheduling-1" [_thread_blocked, id=30794, stack(0x509b0000,0x50a00000)]
  0x52825c00 JavaThread "logback-2" daemon [_thread_blocked, id=30789, stack(0x51d24000,0x51d74000)]
  0x754b4400 JavaThread "AsyncAppender-Worker-ASYNC" daemon [_thread_blocked, id=30650, stack(0x51d74000,0x51dc4000)]
  0x5257c800 JavaThread "logback-1" daemon [_thread_blocked, id=30646, stack(0x52610000,0x52660000)]
  0x75479800 JavaThread "Service Thread" daemon [_thread_blocked, id=30598, stack(0x526e0000,0x52730000)]
  0x75476400 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=30597, stack(0x52730000,0x527b0000)]
  0x75474c00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=30596, stack(0x527b0000,0x52800000)]
  0x75464800 JavaThread "Finalizer" daemon [_thread_blocked, id=30595, stack(0x52926000,0x52976000)]
  0x75461c00 JavaThread "Reference Handler" daemon [_thread_blocked, id=30594, stack(0x52976000,0x529c6000)]

Other Threads:
  0x7545d000 VMThread [stack: 0x529c6000,0x52a46000] [id=30593]
  0x7547b800 WatcherThread [stack: 0x52660000,0x526e0000] [id=30599]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap:
 def new generation   total 78656K, used 25964K [0x53200000, 0x58750000, 0x5dca0000)
  eden space 69952K,  30% used [0x53200000, 0x5467fc20, 0x57650000)
  from space 8704K,  57% used [0x57650000, 0x57b2b700, 0x57ed0000)
  to   space 8704K,   0% used [0x57ed0000, 0x57ed0000, 0x58750000)
 tenured generation   total 174784K, used 10530K [0x5dca0000, 0x68750000, 0x73200000)
   the space 174784K,   6% used [0x5dca0000, 0x5e6e8bf0, 0x5e6e8c00, 0x68750000)
 Metaspace       used 23008K, capacity 23912K, committed 23960K, reserved 24880K

Card table byte_map: [0x530ff000,0x53200000] byte_map_base: 0x52e66000

Polling page: 0x76f5d000

CodeCache: size=32768Kb used=4456Kb max_used=4485Kb free=28311Kb
 bounds [0x73332000, 0x7379a000, 0x75332000]
 total_blobs=2194 nmethods=1984 adapters=140
 compilation: enabled



Edit3: replaced

map<int, int> test;

with

std::map<int,int>& m(){
    static std::map<int,int>* ans;
    return *ans;
}

and the library loaded fine. I am not sure why and I am not sure if it will work when I actually access m(). Thanks a lot

Edit 4:

Enabled LD_DEBUG=all and started the java process. Below is the error on the console.

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x76fac5b0, pid=2092, tid=0x6042f470
#
# JRE version: OpenJDK Runtime Environment (8.0_121-b13) (build 1.8.0_121-internal-b13)
# Java VM: OpenJDK Client VM (25.121-b13 mixed mode linux-aarch32 )
# Problematic frame:
#       2092:   symbol=_dl_addr;  lookup in file=java [0]
      2092: symbol=_dl_addr;  lookup in file=/usr/lib/jvm/openjre-8/bin/../lib/aarch32/jli/libjli.so [0]
      2092: symbol=_dl_addr;  lookup in file=/lib/libc.so.6 [0]
      2092: binding file /lib/libdl.so.2 [0] to /lib/libc.so.6 [0]: normal symbol `_dl_addr' [GLIBC_PRIVATE]
C  [ld-linux-armhf.so.3+0x85b0]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/root/hs_err_pid2092.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
c++
linux
java-native-interface
shared-libraries
cross-compiling
asked on Stack Overflow Oct 16, 2020 by Srikanth Chadalavada • edited Oct 19, 2020 by Srikanth Chadalavada

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0