小编Mic*_*ani的帖子

GCC 程序集 x86 重定位警告:在 PIE 中创建 DT_TEXTREL

我正在用 AT&T 语法使用 Assembly x86(32 位)为大学编写一个项目。在课程中,我们使用 gnu Gas 和命令 ld 编译了源文件。现在我正在使用 GCC,因为我想创建一个汇编函数并从 C 程序调用它。

但是当我开始使用 GCC 进行编译时,我收到了这些关于链接和重定位的奇怪警告。

/usr/bin/ld: obj/telemetry.o: warning: relocation in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
Run Code Online (Sandbox Code Playgroud)

这是导致警告的文件的一个小示例。仅当我尝试访问/使用 .data 中声明的静态变量时才会发生警告

.file "telemetry.s"

.data 
test: .string "Example"
 
.text
.globl telemetry
.type telemetry, @function
telemetry:
    pushl %ebp
    movl %esp, %ebp
    pushl %ebx

    leal test, %ebx # if i comment this line warnings wont happen

    popl %ebx
    popl %ebp
    ret
Run Code Online (Sandbox Code Playgroud)

我仅在 Ubuntu 22.04.01 上使用当前使用的 gcc 版本 (11.2.0) 时收到警告。这是命令: …

c x86 assembly linker gcc

5
推荐指数
0
解决办法
1万
查看次数

标签 统计

assembly ×1

c ×1

gcc ×1

linker ×1

x86 ×1