邮箱:pengdonglin137@163.com

参考:https://stackoverflow.com/questions/1706328/how-do-shared-libraries-work-in-a-mixed-64bit-32bit-system

概述

  在嵌入式开发时,经常会通过编译busybox来制作rootfs,然后在上面跑可执行程序。那么如何通过修改配置,让一个rootfs同时兼容32位和64位的可执行程序呢?

  我们知道,如果EL1运行在64位时,那么EL0既可以运行在64位,也可以运行在32位。具体到这里,我们让内核运行在64位(EL1),然后在EL0运行64位或者32位的可执行程序,在加载32位的可执行程序时,会先陷入Linux内核(EL1),然后通过解析elf文件发现EL0要运行在32位模式,那么在eret异常返回到EL0时会通过SPSR将当前cpu切到32位模式运行。

正文

1、配置linux kernel

使kernel支持在EL0上运行32位可执行程序:(arch/arm64/Kconfig中)

config COMPAT
bool "Kernel support for 32-bit EL0"
depends on ARM64_4K_PAGES || EXPERT
select COMPAT_BINFMT_ELF if BINFMT_ELF
select HAVE_UID16
select OLD_SIGSUSPEND3
select COMPAT_OLD_SIGACTION
help
This option enables support for a -bit EL0 running under a -bit
kernel at EL1. AArch32-specific components such as system calls,
the user helper functions, VFP support and the ptrace interface are
handled appropriately by the kernel. If you use a page size other than 4KB (i.e, 16KB or 64KB), please be aware
that you will only be able to execute AArch32 binaries that were compiled
with page size aligned segments. If you want to execute -bit userspace applications, say Y.

具体是在:Userspace binary formats --> Kernel support for 32-bit EL0

然后重新编译内核

2、配置根文件系统

这一步需要视情况而定,如果32位的可执行程序采用的是静态链接的,那么此时应该就可以直接运行。如果采用的是动态链接,那么就需要专门的设置了。

  • 在rootfs的根目录下创建/lib32目录,然后将要用到的32位的动态库拷贝到其中
  • 设置LD_LIBRARY_PATH环境变量,将刚才的路径添加到其中:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib32
  • 进入/lib目录,在其中创建一个指向/lib32/ld-linux-armhf.so.3的软连接:ld-linux-armhf.so.3

3、测试

  • 运行32位可执行程序

在64位系统里运行一个32位的测试程序:

然后可以查看其虚拟内存地址分配

  • 运行64位可执行程序

查看其地址分配:

完。

最新文章

  1. WebServices复习
  2. Xcode - 知道.001
  3. HTML5 web workes实现多线程
  4. 【Java】Java6 WebService的发布
  5. 半透明panel
  6. spring集成quartz
  7. 【爬虫入门手记03】爬虫解析利器beautifulSoup模块的基本应用
  8. git http服务免登录实现(免去每次请求用户名密码输入,Visual Studio可用)
  9. ubuntu 安装 nvm 管理Node.js 以及vim 插件增强
  10. Swift 里 Dictionary
  11. 域名系统DNS简介
  12. 【大数据】SparkStreaming学习笔记
  13. ubuntu(14.04) 下安装yaf拓展
  14. Android开发和调试必备工具-SDK Tools
  15. gephi
  16. 集群负载均衡LVS
  17. 转载:【原译】Erlang常见注意事项(Efficiency Guide)
  18. vue项目中分享到朋友圈,调用微信接口
  19. python 中如何计算时间差...
  20. CF954F Runner's Problem(动态规划,矩阵快速幂)

热门文章

  1. 0x01 Wechall writeup
  2. <String> 49 87
  3. Centos7下搭建NFS服务器与连接详解
  4. Linux性能优化实战学习笔记:第七讲
  5. [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
  6. [LeetCode] 154. Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值之二
  7. 【微信小程序】获取用户地理位置权限,二次请求授权,逆解析获取地址
  8. JVM系列之七:HotSpot 虚拟机
  9. OSG :三维无序离散点构建Delaunay三角网
  10. String.format方法使用-浅析(转)