nm的偏移量符号值? [英] Offset in nm symbol value?

查看:162
本文介绍了nm的偏移量符号值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是给你一些上下文,这里是我想实现:
我在一个共享对象文件中嵌入一个const char *为了在.so文件本身有一个版本字符串。我正在做数据分析,这个字符串使我能够让数据知道哪个版本的软件生产它。这一切都很好。

Just to give you some context, here's what I'm trying to achieve: I am embedding a const char* in a shared object file in order to have a version string in the .so file itself. I am doing data analysis and this string enables me to let the data know which version of the software produced it. This all works fine.

我遇到的问题是,当我尝试从.so库直接读取字符串。我试图使用

The issue I am having is when I try to read the string out of the .so library directly. I tried to use

nm libSMPselection.so | grep _version_info

并取得

000000000003d968 D __SMPselection_version_info

称为_SMPselection_version_info)。
然而我希望现在可以打开文件,寻找0x3d968并开始读取我的字符串,但我得到的是垃圾。

this is all fine and as expected (the char* is called _SMPselection_version_info). However I would have expected to now be able to open the file, seek to 0x3d968 and start reading my string, but all I get is garbage.

当我打开.so文件,只需搜索字符串的内容(我知道它是如何开始的),我可以找到它在地址0x2e0b4。在这个地址,它在那里,零终止和预期。 (我现在使用这种方法。)

When I open the .so file and simply search for the contents of the string (I know how it starts), I can find it at address 0x2e0b4. At this address it's there, zero terminated and as expected. (I am using this method for now.)

我不是一个计算机科学家。有人可以向我解释为什么nm显示的符号值不正确,或者不同的是,如果符号值不是符号的地址,是什么?

I am not a computer scientist. Could someone please explain to me why the symbol value shown by nm isn't correct, or differently, what is the symbol value if it isn't the address of the symbol?

(顺便说一句,我在Mac OSX 10.7上工作)

(By the way I am working on a Mac with OSX 10.7)

推荐答案

没有人建议最简单的方法:动态加载你的lib(在命令行上给它的名字),并为你的符号dlsym(),或者它也可以在命令行上得到它)转换为字符串指针并打印到stdout。

Nobody suggested the simplest way: Do a binary that dynamically loads your lib (give it the name on the command line) and does dlsym() for your symbol (or it can get that on the command line too) cast it to string pointer and prints it to stdout.

这篇关于nm的偏移量符号值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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