【问题标题】:It is gcc not as that is responsible for the preprocessor in an assembly file? [closed]不是 gcc 负责汇编文件中的预处理器吗? [关闭]
【发布时间】:2016-07-07 07:47:31
【问题描述】:

我发现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 汇编代码。
file.S file.sx 必须预处理的汇编代码。

我认为这里 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

阿斯洛

【问题讨论】:

  • 如果您尝试编写自答式问答,请确保问题是正确的问题,并且不包含太多答案。其他人应该可以提供多个答案。
  • 回答我自己的问题很有趣,所以我忍不住尝试一下。结果,它被标记为“-1”。是的,没用,我知道我错了~
  • 我的观点与您的回答错误无关。关键是您在问题中输入的很多文字都应该在答案中。一个带有假设的巨大问题只有一个是/否的答案。像“gcc 如何决定运行什么”这样的小问题可以得到真正的答案。
  • 其实我在.S文件中发现C预处理器不起作用,然后我就猜到了,现在我从Binutils (as bfd binutils gprof ld)3.1 Preprocessing得到它

标签: gcc assembly c-preprocessor eclipse-cdt


【解决方案1】:

是的。 gcc 二进制文件决定调用哪些程序。如果它看到一个后缀为s 的文件,它会调用as。如果它看到一个后缀为S 的文件,它会调用cpp,然后调用as。汇编器as 本身不知道后缀约定,也不会为您调用 C 预处理器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-17
    • 2011-09-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多