Linux Kernel - 为什么 System.map 中的函数地址在实时看到的地址前一个字节? [英] Linux Kernel - why a function's address in System.map is one byte preceding its address as seen in real time?

查看:23
本文介绍了Linux Kernel - 为什么 System.map 中的函数地址在实时看到的地址前一个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 linux 内核源代码中,在 tasklet_action 代码中添加了这一行:

In linux kernel source code, added this lines in tasklet_action code:

printk("tasklet_action = %p
" , *tasklet_action);
printk("tasklet_action = %p
" , &tasklet_action);
printk("tasklet_action = %p
" , tasklet_action);

在我得到的输出中:

tasklet_action = c03441a1
tasklet_action = c03441a1
tasklet_action = c03441a1

但是在 system.map 文件中搜索时,tasklet_action 地址位于 c03441a0,因此有 1 个字节的偏移量.

But when searching it in the system.map file the tasklet_action address is at c03441a0 so there is an offset of 1 byte.

  • 为什么我有这个偏移量?
  • 它总是一个字节的偏移量吗?

推荐答案

我猜你是在 ARM 上运行 Thumb 模式,或者在其他一些使用函数底部位的架构上指示运行模式的指针.

My guess is that you are running on ARM in Thumb mode, or on some other architecture that uses the bottom bit of the function pointer to indicate which mode to run in.

如果是这样,答案是你的函数确实位于system.map中的地址.

If so, the answer is that your function really is located at the address in the system.map.

你在运行时得到的值是位置和模式.

The value you get at run time is the location and the mode.

在这类架构上,指令必须始终是 2 或 4 字节对齐的,这会使底部位始终为零.当架构增加了一个额外的模式时,设计人员利用浪费"位来编码模式.它很聪明,但也令人困惑,而且不仅对您而言:很多软件(例如调试器)在首次发明时以许多令人讨厌的方式破坏了它.

Instructions, on these kinds of architectures, always must be 2- or 4-byte aligned, which would leave the bottom bit always zero. When the architecture grew an extra mode the designers made use of the 'wasted' bit to encode the mode. It's clever, but confusing, and not just for you: a lot of software, like debuggers, broke in many nasty ways when this was first invented.

对于习惯于使用任意随机对齐的可变长度指令的 x86 程序员来说,这个概念尤其令人困惑.

The concept is particularly confusing for x86 programmers who are used to variable-length instructions with any random alignment.

这篇关于Linux Kernel - 为什么 System.map 中的函数地址在实时看到的地址前一个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆