gcc assembler preprocessor not compatible with standard headers

谁都会走 提交于 2019-12-06 02:11:47

问题


The man page for gcc states

   file.s
       Assembler code.

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

And many standard include files have

#ifndef __ASSEMBLY__ 
...
#endif

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.

Here's some test code:

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

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.

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

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?

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


回答1:


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

The linux kernel passes down __ASSEMBLY__ explicitly in linux/Makefile:

KBUILD_AFLAGS   := -D__ASSEMBLY__

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)



来源:https://stackoverflow.com/questions/28924355/gcc-assembler-preprocessor-not-compatible-with-standard-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!