是不是 gcc 负责汇编文件中的预处理器?
It is gcc not as that is responsible for the preprocessor in an assembly file?
我发现CDT
在eclipse上默认使用x86_64-w64-mingw32-as
等相应的后端工具编译一个汇编文件,在C/C++ Build > Settings > Tool Settings > GCC Assembler
上配置。
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C Compiler'
x86_64-w64-mingw32-gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
src/%.o: ../src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
x86_64-w64-mingw32-g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
src/%.o: ../src/%.S
@echo 'Building file: $<'
@echo 'Invoking: GCC Assembler'
x86_64-w64-mingw32-as -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
虽然Options Controlling the Kind of Output说
file.s Assembler code.
file.S file.sx Assembler code that must be preprocessed.
我想这里 preprocessed
指的是 c 预处理器。但是,它必须是gcc file.S
而不是as file.S
(大写'S'),后者会在文件包含C预处理器时提示类似Error: junk at end of line, first unrecognized character is
('`的错误。取以下示例(.S):
#ifdef __x86_64__
#if defined(SYMBOL_UNDERSCORE)
#define GLOBL_SYMBOL(x) _##x
#else
#define GLOBL_SYMBOL(x) x
/* #error "============" */
#endif
.globl GLOBL_SYMBOL(foo)
#endif
==
这样,负责预处理器(gcc工作过程的一个步骤)的就是gcc吧?
按照这个思路,下面的(.S)就可以了...
/* https://sourceforge.net/p/predef/wiki/Architectures */
/* #ifdef __LP64__ || _LP64 */
#if defined(__i386__) || defined(_M_IX86)
# include "nomakefile/foo_x86.S"
#elif defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
# include "nomakefile/foo_x64.S"
#else
# error Unsupported architecture
#endif
阿斯洛
- How to access C preprocessor constants in assembly?
是的。 gcc
二进制文件决定要调用的程序。如果它看到后缀为 s
的文件,它会调用 as
。如果它看到后缀为 S
的文件,它会调用 cpp
,然后调用 as
。汇编程序 as
本身并不知道后缀约定,也不会为您调用 C 预处理器。
我发现CDT
在eclipse上默认使用x86_64-w64-mingw32-as
等相应的后端工具编译一个汇编文件,在C/C++ Build > Settings > Tool Settings > GCC Assembler
上配置。
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C Compiler'
x86_64-w64-mingw32-gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
src/%.o: ../src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cygwin C++ Compiler'
x86_64-w64-mingw32-g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
src/%.o: ../src/%.S
@echo 'Building file: $<'
@echo 'Invoking: GCC Assembler'
x86_64-w64-mingw32-as -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
虽然Options Controlling the Kind of Output说
file.s Assembler code.
file.S file.sx Assembler code that must be preprocessed.
我想这里 preprocessed
指的是 c 预处理器。但是,它必须是gcc file.S
而不是as file.S
(大写'S'),后者会在文件包含C预处理器时提示类似Error: junk at end of line, first unrecognized character is
('`的错误。取以下示例(.S):
#ifdef __x86_64__
#if defined(SYMBOL_UNDERSCORE)
#define GLOBL_SYMBOL(x) _##x
#else
#define GLOBL_SYMBOL(x) x
/* #error "============" */
#endif
.globl GLOBL_SYMBOL(foo)
#endif
==
这样,负责预处理器(gcc工作过程的一个步骤)的就是gcc吧? 按照这个思路,下面的(.S)就可以了...
/* https://sourceforge.net/p/predef/wiki/Architectures */
/* #ifdef __LP64__ || _LP64 */
#if defined(__i386__) || defined(_M_IX86)
# include "nomakefile/foo_x86.S"
#elif defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
# include "nomakefile/foo_x64.S"
#else
# error Unsupported architecture
#endif
阿斯洛
- How to access C preprocessor constants in assembly?
是的。 gcc
二进制文件决定要调用的程序。如果它看到后缀为 s
的文件,它会调用 as
。如果它看到后缀为 S
的文件,它会调用 cpp
,然后调用 as
。汇编程序 as
本身并不知道后缀约定,也不会为您调用 C 预处理器。