gnu arm汇编程序命令行宏失败,并显示“.ifdef的无效标识符” [英] gnu arm assembler command line macro fails with "Invalid identifier for .ifdef"
问题描述
我的工具链是arm-gcc的最新版本。
我在程序集文件中有一段代码,必须有条件地包含/组装。
.ifdef MACRO_FROM_CMDLINE
结果在MACRO_FROM_CMDLINE = 1:没有这样的文件或目录,无法识别的选项--defsym错误。
汇编instr1
汇编instr2
.endif
$ c
封装代码是最近的一个新增功能。
我已经尝试了两种方法:
p>
gcc -x汇编程序与cpp --defsym MACRO_FROM_CMDLINE = 1<连同其他必要的选项>
gcc -x汇编程序与cpp -D MACRO_FROM_CMDLINE = 1<连同其他必要的选项>
-D
结果为无效标识符对于.ifdef和.endif没有.if错误。
$ b $ <<> c $ c> - defsym
解决方案
gcc
二进制通过依次调用一些其他程序来驱动编译过程,以实际执行各个阶段的工作(编译,组装,链接)。
当你说:
gcc -x汇编程序与cpp -D MACRO_FROM_CMDLINE = 1 ...
您要求它通过C预处理器运行源代码,然后通过汇编器运行结果。 / p>
C预处理器步骤将变为:
.ifdef MACRO_FROM_CMDLINE
放入:
.ifdef 1
之前将它传递给汇编器,然后无法理解它。这就是你得到无效标识符错误的原因。它还解释了为什么使用C预处理器
#ifdef
可以解决问题。
- defsym
不起作用,因为它是汇编程序的选项,而不是gcc
驱动程序。 (gcc
驱动程序确实理解并通过某些选项将 一些选项调用,但不是全部选项。 )
然而,您可以使用
将任意选项传递给汇编程序
-Wa,option [,option ...]
语法,它告诉
gcc
驱动程序将这些选项传递给汇编程序(作为空格分隔的选项列表)。
例如:
gcc -x汇编程序与cpp -Wa, - defsym, MACRO_FROM_CMDLINE = 1 ...
加上
- defsym MACRO_FROM_CMDLINE = 1
到选项列表当
gcc
调用它时,传递给作为
,这就是如何使原始的.ifdef
示例工作。
您可以看到由
gcc调用的单个程序
及其执行的选项y通过添加-v
选项传递给它们。
在这种情况下,您应该看到一些名为
cc1
(实际的GCC C编译器二进制文件)用-E
标志调用(仅用于预处理),以便将输入预处理为临时文件,然后在临时文件上调用作为
来组装它。My toolchain is a recent version of arm-gcc.
I have a piece of code in an assembly file which must be conditionally included/assembled.
.ifdef MACRO_FROM_CMDLINE Assembly instr1 Assembly instr2 .endif
Encapsulated code is a recent addition.
I have tried both:
gcc -x assembler-with-cpp --defsym MACRO_FROM_CMDLINE=1 <along with other necessary options> gcc -x assembler-with-cpp -D MACRO_FROM_CMDLINE=1 <along with other necessary options>
The
-D
results in "Invalid identifier for .ifdef " and ".endif without .if" errors.The
--defsym
results in "MACRO_FROM_CMDLINE=1 : No such file or directory", "unrecognized option --defsym" errors.解决方案The
gcc
binary drives the compilation process by invoking a number of other programs in sequence to actually perform the various stages of work (compiling, assembling, linking).When you say:
gcc -x assembler-with-cpp -D MACRO_FROM_CMDLINE=1 ...
you are asking it to run the source through the C preprocessor, and then run the result through the assembler.
The C preprocessor step will turn:
.ifdef MACRO_FROM_CMDLINE
into:
.ifdef 1
before passing it to the assembler, which then can't make sense of it. This is why you get the "invalid identifier" error. It also explains why using C preprocessor
#ifdef
fixes the problem.
--defsym
doesn't work because it's an option to the assembler, not thegcc
driver program. (Thegcc
driver does understand and pass through some options to some of the programs it invokes, but not all.)You can, however, pass arbitrary options through to the assembler using the
-Wa,option[,option...]
syntax, which tells the
gcc
driver to pass those option(s) through to the assembler (as a list of space-separated options).For example:
gcc -x assembler-with-cpp -Wa,--defsym,MACRO_FROM_CMDLINE=1 ...
adds
--defsym MACRO_FROM_CMDLINE=1
to the list of options passed to
as
whengcc
invokes it, and that's how to make your original.ifdef
example work.
You can see the individual programs invoked by
gcc
, and the options it actually passes to them, by adding the-v
option.In this case, you should see something called
cc1
(the actual GCC C compiler binary) invoked with the-E
flag (preprocess only) to preprocess the input to a temporary file, and thenas
invoked on the temporary file to assemble it.这篇关于gnu arm汇编程序命令行宏失败,并显示“.ifdef的无效标识符”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文