我怎样才能在我的程序中获得_GLOBAL_OFFSET_TABLE_地址? [英] How can I get the _GLOBAL_OFFSET_TABLE_ address in my program?

查看:151
本文介绍了我怎样才能在我的程序中获得_GLOBAL_OFFSET_TABLE_地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的程序中得到_GLOBAL_OFFSET_TABLE_的地址。一种方法是在Linux中使用 nm 命令,可能会将输出重定向到文件并解析该文件以获取_GLOBAL_OFFSET_TABLE_的地址。但是,这种方法似乎效率很低。什么是更有效的方法呢?

解决方案

这似乎有效:

  #include< stdio.h> 

extern void * _GLOBAL_OFFSET_TABLE_;

int main()
{
printf(_ GLOBAL_OFFSET_TABLE =%p \ n,& _GLOBAL_OFFSET_TABLE_);
返回0;

code $

$ b $ p

它给出:

  $ ./test 
_GLOBAL_OFFSET_TABLE = 0x6006d0

然而, nm 认为不同:

  $ nm test | fgrep GLOBAL 
0000000000600868 d _GLOBAL_OFFSET_TABLE_


I want to get the address of _GLOBAL_OFFSET_TABLE_ in my program. One way is to use the nm command in Linux, maybe redirect the output to a file and parse that file to get address of _GLOBAL_OFFSET_TABLE_. However, that method seems to be quite inefficient. What are some more efficient methods of doing it?

解决方案

This appears to work:

#include <stdio.h>

extern void *_GLOBAL_OFFSET_TABLE_;

int main()
{
    printf("_GLOBAL_OFFSET_TABLE = %p\n", &_GLOBAL_OFFSET_TABLE_);
    return 0;
}

It gives:

$ ./test
_GLOBAL_OFFSET_TABLE = 0x6006d0

However, nm thinks different:

$ nm test | fgrep GLOBAL
0000000000600868 d _GLOBAL_OFFSET_TABLE_

这篇关于我怎样才能在我的程序中获得_GLOBAL_OFFSET_TABLE_地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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