Resolve “`.rodata' can not be used when making a PIE object; recompile with -fPIC”

1. Question

       When I use Ubuntu18.04 desktop operating system to compile "Onenet Video SDK"(https://github.com/cm-heclouds/video_sdk),I encountered an problem as below:

/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(bignum.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(ctr_drbg.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(entropy.c.o): relocation R_X86_64_32 against symbol `mbedtls_platform_entropy_poll' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(entropy_poll.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(rsa.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha1.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha512.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(timing.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(aes.c.o): relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(md.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(oid.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(ripemd160.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha256.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(md5.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
onvif/libonvif_s.a(stdsoap2.c.o): In function `soap_ssl_init':
stdsoap2.c:(.text+0x68b5): undefined reference to `SSL_library_init'
stdsoap2.c:(.text+0x68ba): undefined reference to `OPENSSL_add_all_algorithms_noconf'
stdsoap2.c:(.text+0x68bf): undefined reference to `SSL_load_error_strings'
onvif/libonvif_s.a(stdsoap2.c.o): In function `ssl_auth_init':
stdsoap2.c:(.text+0x6b54): undefined reference to `SSLv23_method'
onvif/libonvif_s.a(stdsoap2.c.o): In function `tcp_connect':
stdsoap2.c:(.text+0x9612): undefined reference to `SSL_state'
stdsoap2.c:(.text+0x97e3): undefined reference to `sk_pop_free'
stdsoap2.c:(.text+0x9811): undefined reference to `sk_value'
stdsoap2.c:(.text+0x988f): undefined reference to `sk_num'
stdsoap2.c:(.text+0x98b1): undefined reference to `sk_pop_free'
onvif/libonvif_s.a(mecevp.c.o): In function `soap_mec_init':
mecevp.c:(.text+0x76): undefined reference to `EVP_CIPHER_CTX_init'
onvif/libonvif_s.a(mecevp.c.o): In function `soap_mec_cleanup':
mecevp.c:(.text+0x433): undefined reference to `EVP_CIPHER_CTX_cleanup'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_init':
smdevp.c:(.text+0x33d): undefined reference to `HMAC_CTX_init'
smdevp.c:(.text+0x395): undefined reference to `EVP_MD_CTX_init'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_final':
smdevp.c:(.text+0x76a): undefined reference to `HMAC_CTX_cleanup'
smdevp.c:(.text+0x77c): undefined reference to `EVP_MD_CTX_cleanup'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_check':
smdevp.c:(.text+0x844): undefined reference to `HMAC_CTX_cleanup'
smdevp.c:(.text+0x856): undefined reference to `EVP_MD_CTX_cleanup'
/usr/bin/ld: final link failed: Symbol needs debug section which does not exist
collect2: error: ld returned 1 exit status
sample/CMakeFiles/sample_video_s.dir/build.make:373: recipe for target '../bin/sample_video_s' failed
make[2]: *** [../bin/sample_video_s] Error 1
CMakeFiles/Makefile2:225: recipe for target 'sample/CMakeFiles/sample_video_s.dir/all' failed
make[1]: *** [sample/CMakeFiles/sample_video_s.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2 

 

2. Analysis:

        It is inferred that the trouble should be positioned in linking procedure. The specialize static library "libmbedcrypto.a" was ever compiled without option "fPIC", but the present system compiler turns on this function definitely. So we can see from log that it recommends recompile with -fPIC.

 

 3. Resolution

        If we use CMake tool to help compile, we can just add an "-no-pie" to linker flags:
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
Job done.

 

4.  Summarize knowledge

        PIE full name is "Position Independent Executable", which is used to create an media between common executable and common shared library. This kind of code can relocate space just as common shared library, and it must be linked to Scrt1.o.
Details can be referred to https://blog.csdn.net/ivan240/article/details/5363395.

 

  • 18
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值