小编Rab*_*ars的帖子

gcc使用的实际默认链接描述文件和设置

我在哪里可以找到gcc使用的实际链接器脚本和设置?


我试过的事情:

具体来说,让我们考虑一个小程序:empty.c

int main(void)
{   
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

静态构建它,并查看结果:

$ gcc -static -o empty empty.c
$ readelf -W -l empty

Elf file type is EXEC (Executable file)
Entry point 0x400f4e
There are 6 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x0bf581 0x0bf581 R E 0x200000
  LOAD           0x0bfeb0 0x00000000006bfeb0 0x00000000006bfeb0 0x001d80 0x0042d8 RW  0x200000
  NOTE           0x000190 0x0000000000400190 0x0000000000400190 0x000044 0x000044 R   0x4
  TLS            0x0bfeb0 0x00000000006bfeb0 0x00000000006bfeb0 0x000020 …
Run Code Online (Sandbox Code Playgroud)

linker gcc linker-scripts

10
推荐指数
2
解决办法
5855
查看次数

gcc汇编程序预处理程序与标准标头不兼容

gcc的手册页说明

   file.s
       Assembler code.

   file.S
   file.sx
       Assembler code that must be preprocessed.
Run Code Online (Sandbox Code Playgroud)

许多标准包含文件都有

#ifndef __ASSEMBLY__ 
...
#endif
Run Code Online (Sandbox Code Playgroud)

包装器允许从程序集文件中包含.我可以发誓我以前用gcc写过程序,并在组装时定义了这个程序,但现在我遇到了问题.

这是一些测试代码:

test.S

#include <sys/syscall.h>
#include <asm/signal.h>
    .intel_syntax noprefix

    .text
    .global foo // int foo(int pid)
foo:
    mov esi,SIGUSR1
    mov eax,SYS_kill
    syscall
    ret
Run Code Online (Sandbox Code Playgroud)

当我运行时gcc -c test.S,它抱怨asm/signal.h中的所有类型的东西,因为它没有看到__ASSEMBLY__定义.

现在我的工作是:

#ifndef __ASSEMBLY__
#define __ASSEMBLY__
#endif
Run Code Online (Sandbox Code Playgroud)

但这似乎是错误的,必须将其添加到我的所有文件.

这是GCC中的错误吗?
或者我在这里做错了什么?

注意:
我在测试中看到gcc确实定义__ASSEMBLER__但是大多数头文件测试__ASSEMBLY__(我确实看到了一对测试__ASSEMBLER__).适当的ifdef在某些时候发生了变化吗?

我使用的是Ubuntu 14.04,gcc报告版本:gcc(Ubuntu 4.8.2-19ubuntu1)4.8.2

assembly gcc c-preprocessor

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

标签 统计

gcc ×2

assembly ×1

c-preprocessor ×1

linker ×1

linker-scripts ×1