.so has text relocations. This is wasting memory and prevents security hardening. Please fix.

转载请标明出处:http://blog.csdn.net/xx326664162/article/details/52926274 文章出自:薛瑄的博客

你也可以查看我的其他同类文章,也会让你有一定的收货

首先说明出现下面这个错误的原因可能有很多,你也可以直接看下面的分析,来判断是不是和我一样的问题

介绍一下,在下面的环境中,解决这个问题使用的解决方法。

测试环境:

Galaxy Note3 Android 5.0
Android studio 2.2.2
gradle-2.14.1-all
NDK版本如下图:
这里写图片描述

项目的build.gradle如下:

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"

    defaultConfig {
        applicationId "com.firs.facedetecttosvr"
        minSdkVersion 19
        targetSdkVersion 21

        ndk {
            moduleName "libface_identify"
            abiFilters 'armeabi', 'armeabi-v7a'
        }
    }
   ...(部分省略)
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
}

Android.mk配置如下

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := facetemp
LOCAL_SRC_FILES := libFiFacial.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := jpegtemp
LOCAL_SRC_FILES := libjpeg.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
#LOCAL_SRC_TCP  := ./tcpSock/maintcp.cpp ./tcpSock/CommLayerTcp.cpp ./tcpSock/NetAuth.cpp ./tcpSock/NetDeal.cpp ./tcpSock/NetPublic.cpp
#LOCAL_SRC_TCP  := maintcp.cpp CommLayerTcp.cpp NetAuth.cpp NetDeal.cpp NetPublic.cpp

LOCAL_MODULE    := libface_identify
LOCAL_SRC_FILES := facelib.cpp public.cpp  maintcp.cpp CommLayerTcp.cpp NetAuth.cpp NetDeal.cpp NetPublic.cpp gb2312.cpp
#LOCAL_MODULE_FILENAME = libface_identify
LOCAL_SHARED_LIBRARIES := jpegtemp
LOCAL_STATIC_LIBRARIES := facetemp
LOCAL_LDLIBS := -llog -lstdc++
include $(BUILD_SHARED_LIBRARY)

java代码调用so库的代码

 static {
        // System.loadLibrary("stlport_shared");
        // System.loadLibrary("jpeg");
        System.loadLibrary("face_identify");
    }

出现下面这个错误的原因可能有很多,接下来介绍一下,在上面的环境下,解决这个问题使用的解决方法。

崩溃时的logcat

10-25 19:12:49.217 23377-23377/? I/art: Late-enabling -Xcheck:jni
10-25 19:12:49.587 23377-23377/com.firs.facedetecttosvr W/linker: /data/app/com.firs.facedetecttosvr-2/lib/arm/libjpeg.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
10-25 19:12:49.593 23377-23377/com.firs.facedetecttosvr D/Face_Identify: login in username[test] pwd[123456] nLen[68]
10-25 19:12:49.593 23377-23377/com.firs.facedetecttosvr D/Face_Identify: send packType[1] msgtype[256] subTyep[1]
10-25 19:12:49.601 23377-23377/com.firs.facedetecttosvr D/Face_Identify:  xxxxxxxxxxxxx(10); Client moudle quit StartNetModule 64
10-25 19:12:49.602 23377-23377/com.firs.facedetecttosvr D/Face_Identify:  3333333333(10); Client moudle quit StartNetModule 70
10-25 19:12:49.602 23377-23377/com.firs.facedetecttosvr D/Face_Identify:  88888888888sleep(10); Client moudle quit StartNetModule 72
10-25 19:12:49.608 23377-23413/com.firs.facedetecttosvr D/Face_Identify: iCliePort[32108]  acClieIp[116.205.1.86]CreateTcpClient 478
10-25 19:12:49.620 23377-23416/com.firs.facedetecttosvr D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-25 19:12:49.628 23377-23377/com.firs.facedetecttosvr D/ActivityThreadInjector: clearCachedDrawables.
10-25 19:12:49.634 23377-23416/com.firs.facedetecttosvr I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8974_LA.BF.1.1.3_RB1__release_AU (I741a3d36ca)
                                                                      OpenGL ES Shader Compiler Version: E031.29.00.00
                                                                      Build Date: 04/04/16 Mon
                                                                      Local Branch: mybranch19053788
                                                                      Remote Branch: quic/LA.BF.1.1.3_rb1.12
                                                                      Local Patches: NONE
                                                                      Reconstruct Branch: NOTHING
10-25 19:12:49.645 23377-23416/com.firs.facedetecttosvr I/OpenGLRenderer: Initialized EGL, version 1.4
10-25 19:12:49.700 23377-23413/com.firs.facedetecttosvr D/Face_Identify: login in username[test] pwd[123456] nLen[68]
10-25 19:12:49.700 23377-23413/com.firs.facedetecttosvr D/Face_Identify: send packType[1] msgtype[256] subTyep[1]
10-25 19:12:49.700 23377-23414/com.firs.facedetecttosvr D/Face_Identify: TmpStrData.iFd[23] SNEDLEN[90] DoTcpSendThreadPool 736
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: 000100
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: packType 1 msgtype 256 subType 2 DoTcpClient 407 
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: InStrProPack.head.index 65000 InStrProPack.head.dataLen 584 DoTcpClient 412 
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: sizeof(InStrProPack.head)[19]
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify:  DoTcpClient 459
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: chksum[1439] recvSum[1439] DoTcpClient 467
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: InStrProPack.csuffix[7f]
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: recv InStrProPack->head.msgtype 256 InStrProPack->head.subType 2 AllDealTcp 682
10-25 19:12:49.803 23377-23413/com.firs.facedetecttosvr D/Face_Identify: DealMsgAuth 145
10-25 19:12:50.599 23377-23377/com.firs.facedetecttosvr I/Timeline: Timeline: Activity_launch_request time:27234823
10-25 19:12:50.985 23377-23377/com.firs.facedetecttosvr D/Face_Identify: InitFaceLib()ghCe: 0xa9f539f0 fun:InitFacial line: 292
10-25 19:12:51.029 23377-23377/com.firs.facedetecttosvr D/Face_Identify: fun:InitFacial line: 299 ghFacialCodec: 0xa9fba180
10-25 19:12:51.029 23377-23377/com.firs.facedetecttosvr D/Face_Identify: DoTcpSendThreadPool Java_com_firs_cn_FaceNative_initFaceLib 357
10-25 19:12:51.043 23377-23377/com.firs.facedetecttosvr D/ActivityThreadInjector: clearCachedDrawables.
10-25 19:12:51.377 23377-23416/com.firs.facedetecttosvr V/RenderScript: 0xaeac8000 Launching thread(s), CPUs 4
10-25 19:12:51.613 23377-23450/com.firs.facedetecttosvr A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xaebc4000 in tid 23450 (AsyncTask #1)

分析

关键代码:

@Override
    protected void onResume() {
        super.onResume();
        //initCamera(); // 初始化摄像头得到width和height的值
        surfaceCreated(surfaceHolder);//设置目标界面
        //创建异步任务,必须传送非零的width和height
        mTask = new RecognizeTask(width, height, isFront);//异步操作   摄像头可用240  320  true
        mTask.setRecognizeListener(this);//重写接口方法
        mTask.execute(0);
    }

我改动了一些java代码,导致出现了这个错误,我还原到改动之前的代码,一点一点去替换,发现是调用ndk时,传入的参数问题导致的,(上面代码的第4行,不应该注释掉,初始化摄像头得到width和height的值,在异步任务中调用jni方法会用到这两个值),但是不知道为什么会报出这个错误,想不出原因。感觉有点误导方向

解决方法:

@Override
    protected void onResume() {
        super.onResume();
        initCamera(); // 初始化摄像头得到width和height的值
        surfaceCreated(surfaceHolder);//设置目标界面
        //创建异步任务,必须传送非零的width和height
        mTask = new RecognizeTask(width, height, isFront);//异步操作   摄像头可用240  320  true
        mTask.setRecognizeListener(this);//重写接口方法
        mTask.execute(0);
    }

虽然示例很有针对性,但是不影响这种解决方法的普遍性,可以当做一种排查方案

关注我的公众号,轻松了解和学习更多技术
这里写图片描述

发布了244 篇原创文章 · 获赞 799 · 访问量 234万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 代码科技 设计师: Amelia_0503

分享到微信朋友圈

×

扫一扫,手机浏览