Pergunta

I compiled a simple C++ function with gcc and icc.

void modify_array(int* arr, int size) {
    for (int i=0; i<size; i++) {
        arr[i] += 1;
    }
}

I was surprised to see that gcc and icc produce assembly with the same label names.

    .globl __Z12modify_arrayPii
Z12modify_arrayPii:
...

Why are they consistent? What is the meaning behind these label names?

Foi útil?

Solução

Intel state that they are making deliberate efforts to give ABI compatibility with GCC with the Linux version of ICC. While the GCC maintainers state that they are making deliberate efforts to give a stable ABI by following an industry C++ ABI standard. This helps keep a stable environment which aids Intel's rather successful efforts.

So it certainly is not by coincidence but by design that they use the same name mangling as part of providing the same ABI.

Outras dicas

I think it is just an coincident that icc and gcc has followed the same name mangling convention and it might be the case that icc has borrowed the idea of gcc while implementing the name mangling. Otherwise different compiler venders are free to choose the different naming convention as it has not been standardized by c++ standard.

Different compilers(or different versions of the same compiler, in many cases) produce such binaries under different name decoration schemes, meaning that symbols are frequently unresolved if the compilers used to create the library and the program using it employed different schemes.The classic "Annotated C++ Reference Manual" actively encourages the use of different mangling schemes to prevent linking when other aspects of the ABI, such as exception handling and virtual table layout, are incompatible.

Intel C++ Compiler (ICC) is binary compatible with GCC. There are many cases were customers mix and match different compilers to build different sections of their project (build certain source files with GCC and other ones with ICC. In those cases, the ICC build binary can coexist with GCC build binary only if they are binary compatible. Also there are cases where the customer builds his application using Intel C++ Compiler but his application depends on a third party library which is build with GCC. So sticking to GNU naming convention helps on Linux for ICC to be binary compatible with GCC.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top