什么是绝对符号,以及如何在C中定义它? [英] What is absolute symbol and how to define it in C?

查看:287
本文介绍了什么是绝对符号,以及如何在C中定义它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nm的手册页中.它说

"A"该符号的值为绝对值,不会通过进一步的链接进行更改.

"A" The symbol's value is absolute, and will not be changed by further linking.

但是,我不知道这意味着什么.如何在C中定义变量或其他使变量的值绝对为 ?

However, I don't know what that means. How can I define a variable or something else to make its value absolute in C?

如果我在test.c的文件范围内声明了一个变量

If I declare a variable in test.c in its file scope

int a;

然后在nm的输出中,a的条目将在我的计算机上显示以下内容

Then in the output of nm, the entry for a will be the following on my machine

0000000000000004 C a

所以我想知道如何使变量的nm输出"A".而且我不知道绝对"是什么意思.

So I'm wondering what can I do to make the nm output "A" for a variable. And I don't know what "absolute" means.

推荐答案

当C编译器编译您的程序时,除程序的二进制代码外,它还会生成符号列表.您将看到的最常见的类型是U s(用于未定义"),D s和S s(用于全局数据)和T s(用于文本"段),它们是可执行代码所在的位置.

When C compiler compiles your program, it produces a list of symbols in addition to the binary code of your program. The most common types that you are going to see are Us (for "undefined"), Ds and Ss (for global data), and Ts (for "text" segment, which is where the executable code goes).

A s或 absolute (不可移动)符号来支持嵌入式开发,在嵌入式开发中,需要将事物放置在内存中的绝对地址处.通常,仅当使用C语言扩展名(用于指定绝对地址)对嵌入式系统进行交叉编译时,才生成此类符号.典型的语法如下所示:

As, or absolute (un-moveable) symbols are there to support embedded development, where placement of things at absolute addresses in memory is required. Normally you would produce such symbols only when cross-compiling for an embedded system, using C language extensions that let you specify the absolute address. A typical syntax would look like this:

unsigned char buf[128]@0x2000;

这不是标准的C,但是它是嵌入式系统的扩展.像这样的代码将在地址0x2000处设置一个绝对符号buf,链接器无法移动它.

This is not a standard C, though, it's an extension for embedded systems. The code like this would produce an absolute symbol buf set at address 0x2000, which cannot be moved by linker.

这篇关于什么是绝对符号,以及如何在C中定义它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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