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

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

问题描述

在linux内核源代码中,在tasklet_action代码中加入这几行:

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

printk("tasklet_action = %p\n" , *tasklet_action);
printk("tasklet_action = %p\n" , &tasklet_action);
printk("tasklet_action = %p\n" , 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 内核 - 为什么 System.map 中的函数地址是实时看到的地址前一个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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