gcc汇编程序预处理器与标准标头不兼容 [英] gcc assembler preprocessor not compatible with standard headers

查看:115
本文介绍了gcc汇编程序预处理器与标准标头不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc状态的手册页

   file.s
       Assembler code.

   file.S
   file.sx
       Assembler code that must be preprocessed.

许多标准包含文件都有

#ifndef __ASSEMBLY__ 
...
#endif

包装器,允许包含在程序集文件中.我本可以发誓我以前曾用gcc编写过程序,并且在组装时就定义了它,但是现在我遇到了问题.

wrappers to allow inclusion from assembly files. I could have sworn I've written programs before with gcc and it defined this when assembling, but now I'm running into problems.

以下是一些测试代码:

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

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

When I run gcc -c test.S, it complains about all kinds of stuff in the asm/signal.h because it doesn't see __ASSEMBLY__ defined.

目前,我的解决方法是:

For now my work around is:

#ifndef __ASSEMBLY__
#define __ASSEMBLY__
#endif

但是将其添加到我的所有文件中似乎有点不对.

But this just seems wrong to have to add this to all my files.

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

Is this a bug in GCC?
Or am I doing something wrong here?

注意:
我在测试中看到gcc确实定义了__ASSEMBLER__,但是大多数头文件都对__ASSEMBLY__进行了测试(我确实看到了几个对__ASSEMBLER__进行测试的对象).适当的ifdef在某个时候改变了吗?

NOTE:
I see in a test that gcc does define __ASSEMBLER__ but most of the header files test for __ASSEMBLY__ (I do see a couple that test for __ASSEMBLER__). Was the appropriate ifdef changed at some point?

我正在使用Ubuntu 14.04,并且gcc报告的版本为:gcc(Ubuntu 4.8.2-19ubuntu1)4.8.2

I am using Ubuntu 14.04, and gcc reports version: gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

推荐答案

__ASSEMBLY__是Linux内核项目在知道gcc预定义宏__ASSEMBLER__的存在之前就组成的约定.

__ASSEMBLY__ is a convention that the Linux kernel project made up themselves before they knew about the existence of the gcc predefined macro __ASSEMBLER__.

Linux内核在 linux/Makefile :

KBUILD_AFLAGS   := -D__ASSEMBLY__

2005年,在LKML上发布了一些补丁程序,这些补丁程序可以迁移到__ASSEMBLER__,但它们并未合并:

There were patches posted on LKML to migrate to __ASSEMBLER__ in 2005 but they were not merged: Re: [RFC][MEGAPATCH] Change ASSEMBLY to ASSEMBLER (defined by GCC from 2.95 to current CVS)

这篇关于gcc汇编程序预处理器与标准标头不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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