I have found that CDT
uses the corresponding backend tool such as x86_64-w64-mingw32-as
to compile an assembly file by default on eclipse, which is configured on 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 ' '
Though Options Controlling the Kind of Output says
file.s Assembler code.
file.S file.sx Assembler code that must be preprocessed.
I think here preprocessed
referrs to c preprocessor. But, it must be gcc file.S
rather than as file.S
(uppercase 'S'), the latter will prompt an error like Error: junk at end of line, first unrecognized character is
('` when the file contains C preprocessor. Take the following example(.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
Thus, it is gcc that is responsible for the preprocessor(one step of working procedures of gcc), right? According to this thinking, the following(.S) will work...
/* 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
Yes. The gcc
binary decides what programs to invoke. If it sees a file with the suffix s
, it invokes as
. If it sees a file with the suffix S
, it invokes cpp
then as
. The assembler as
itself doesn't know about the suffix convention and won't invoke the C preprocessor for you.