简体   繁体   English

gcc-arm编译器为同一源文件生成不同的目标文件

[英]gcc-arm Compiler produce different object file for the same source file

Using the GCC compiler for ARM (windows) : 使用ARM的GCC编译器(windows):

arm-none-eabi-gcc.exe (Sourcery CodeBench Lite 2012.09-63) 4.7.2 version arm-none-eabi-gcc.exe(Sourcery CodeBench Lite 2012.09-63)4.7.2版本

I have got different object file produced every ~5 times i compiled the same source file. 我每隔〜5次生成不同的目标文件,我编译了相同的源文件。

The optimization level 3 (aggressive) is used, compiler options used: 使用优化级别3(激进),使用的编译器选项:

-O3 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fshort-wchar -fshort-enums -funsafe-math-optimizations -mvectorize-with-neon-quad -O3 -mcpu = cortex-a8 -mfpu = neon -mfloat-abi = softfp -fshort-wchar -fshort-enums -funsafe-math-optimizations -mvectorize-with-neon-quad

The dump of the different object files (using objdump) shows too many differences in assembly instructions , registers and addresses used. 转储不同的目标文件(使用objdump)显示在使用的汇编指令,寄存器和地址方面存在太多差异。

  • Is it normal that compiler optimize/compile exactly the same source file differently and produce different object files ?! 编译器以不同方式优化/编译完全相同的源文件并生成不同的目标文件是否正常? is it a compiler bug ? 它是编译器错误吗?

  • How to avoid this behavior without turning off aggressive optimization ? 如何在不关闭激进优化的情况下避免这种行为?

EDIT: object files differences snippet: 编辑:对象文件差异片段:

object_file_dump_A: object_file_dump_A:

0000350 <PreInit>:
 350:   e3003000    movw    r3, #0
 354:   e3403000    movt    r3, #0
 358:   e92d4ff0    push    {r4, r5, r6, r7, r8, r9, sl, fp, lr}
 35c:   e1a09000    mov r9, r0
 360:   e24dd034    sub sp, sp, #52 ; 0x34
 /*some identical ASM for both files */
 388:   e1a0700b    mov r7, fp
 38c:   e1a0600b    mov r6, fp
 390:   e300a000    movw    sl, #0
 394:   e340a000    movt    sl, #0
 398:   e5911004    ldr r1, [r1, #4]
 39c:   e8ae0003    stmia   lr!, {r0, r1}

object_file_dump_B: object_file_dump_B:

00000350 <PreInit>:
 350:   e3003000    movw    r3, #0
 354:   e3403000    movt    r3, #0
 358:   e92d4ff0    push    {r4, r5, r6, r7, r8, r9, sl, fp, lr}
 35c:   e1a08000    mov r8, r0
 360:   e24dd034    sub sp, sp, #52 ; 0x34
  /*some identical ASM for both files */
 388:   e1a0700b    mov r7, fp
 38c:   e3009000    movw    r9, #0
 390:   e3409000    movt    r9, #0
 394:   e5911004    ldr r1, [r1, #4]
 398:   e8ae0003    stmia   lr!, {r0, r1}
 39c:   e5b30010    ldr r0, [r3, #16]!

EDIT: 编辑:

source code : 源代码 :

void PreInit(init_T *f_params, results_T *results) 
{
  u8 i, j, k, idx;
  const u8 cr_index[4] = {0, 1, 2, 7};
  const u8 minVal[] = {2, 4, 6, 0, 0, 0, 0, 19}; 
  const u8 maxVal[] = {0, 3, 5, 0, 0, 0, 0, 18}; 

  memset(f_params, 0, sizeof(init_T));

  _ASSERT(CONF_NUM_X_LIMITS == CST_NbSLi);
  _ASSERT(CONF_NUM_CRITERIA == CST_NbIdxCriteria);

  for (i = 0; i < CST_NbSLi; ++i)
  {
    f_params->_sli[i].x = s_limits[i];
    for (j = 0; j < CST_NbIdxCriteria; ++j)
    {
      f_params->_sli[i].criteria[j] = conf_criterias[i][j];
    }
  }
/*some code*/
}

As mentioned by others the assembly codes are equivalent. 如其他人所述,汇编代码是等效的。 If you look at them closely, the command 如果仔细观察它们,请执行命令

e1a0600b mov r6, fp e1a0600b mov r6,fp

It moves fp to r6, but the r6 register is not used later. 它将fp移动到r6,但r6寄存器以后不再使用。 So, if we consider the randomization tactics to allocate registers, and code creation, the variations are not big and in the second part the optimization removed the line. 因此,如果我们考虑随机化策略来分配寄存器和代码创建,那么变化并不大,在第二部分中,优化会删除该行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gcc-arm链接错误:尝试动态对象的静态链接 - gcc-arm linking error: attempted static link of dynamic object 与源文件位于同一目录中的GCC输出对象文件 - GCC Output Object File in Same Directory as Source File arm-linux-gcc编译器链接,无法找到文件 - arm-linux-gcc compiler linking, file could not be found 当我在不同路径中具有相同的头文件时,是什么使gcc编译器 - What makes the gcc compiler when i have the same header file in different paths 使用交叉编译器(arm-none-eabi-gcc)Typedef文件中的外部结构 - Typedef an externel structure in file using cross-compiler (arm-none-eabi-gcc) GCC-ARM:在 C 中跳转到 linker 部分而不是绝对地址 - GCC-ARM: Make a jump in C to a linker section instead to a absolute address libwebsockets.h - 没有这样的文件或目录,Ubuntu,arm-linux-gcc 交叉编译器 - libwebsockets.h - no such file or directory, Ubuntu, arm-linux-gcc cross compiler 如何使用 arm-non-eabi-gcc 作为交叉编译器生成一个 elf 文件以在 eclipse on windows 上运行? - How to generate a elf file to run in eclipse on windows using arm-non-eabi-gcc as cross compiler? 相同的声明以不同的顺序在gcc中产生不同的结果 - The same declaration in a different order produce different results in gcc 使用本机编译器和交叉编译器生成相同的目标文件 - Generate the same object file with a native compiler and a cross compiler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM