Intel® for *: Compatibility with GNU Compilers

Copyright © 2002, Corporation. All rights reserved. Intel Corporation 2111 N.E. 25th Avenue Hillsboro, Oregon 97124 Intel Corporation assumes no responsibility for errors or omissions in this document. Nor does Intel make any commitment to update the information contained herein. Information in this document is provided in connection with Intel® products. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted by this document. Except as provided in Intel's Terms and Conditions of Sale for such products, Intel assumes no liability whatsoever, and Intel disclaims any express or implied warranty, relating to sale and/or use of Intel products including liability or warranties relating to fitness for a particular purpose. Intel, Pentium, Intel Xeon, and are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. * Other names and brands may be claimed as the property of others. Contents Introduction ...... 3 Overview ...... 3 C and C++ Source Compatibility...... 4 The Linux Kernel Build ...... 4 Binary Compatibility ...... 7 Linking and Libraries ...... 7 Command Line Options...... 9 Intel ...... 11 Mixed Fortran and C++ Applications...... 13

extensions. As a result, we are able to build the Linux kernel with fewer work-arounds for both the IA-32 and Itanium processor Introduction architectures compared to earlier releases of the Intel Compilers. This paper describes the compatibility of the

Intel® Compilers for Linux* with the GNU compilers in terms of source or language, The Intel C++ compiler is binary, or object binary, and command-line compatibility. file, compatible with C language binary files The Intel® C++ and Fortran Compilers for created with the GNU gcc compiler. The Linux help make your run at top Intel compilers support the C++ Application speeds on all Intel® 32-bit processors and Binary Interface (ABI), which, when fully 64-bit Intel® Itanium® processors. The implemented by other compiler vendors, will compilers also provide compatibility with allow C++ objects files and libraries to be commonly used Linux software development compatible with those compilers. At this tools. writing, the Intel and gcc compilers support the C++ ABI, but a small number of Overview differences remain. Details of object compatibility are described below. The Intel C++ Compiler 7.0 for Linux has improved source, binary and command line compatibility with the GNU gcc compiler Building the Linux kernel with the Intel C++ over previous versions. The motivation for Compiler is an ongoing project at Intel. The improved compatibility comes from customer goal is to improve gcc source compatibility, interest in building the Linux kernel with the and to find opportunities to improve kernel Intel compiler with fewer workarounds, and performance. This paper presents a in improvements to supported command-line discussion of issues associated with specific options. language differences found in building the kernel, to date. For up-to-date information, go to The Intel C++ 7.0 compiler supports the http://support.intel.com/support/perfo ANSI C and C++ standards and has greatly rmancetools/c/linux/tti/kernel.htm improved support for the GNU C language

Intel® Compilers for Linux*: Compatibility with Gnu Compilers Page 3 of 14 functionality without inhibiting compiler optimizations important to the Itanium The Intel Fortran Compiler 7.0 for Linux architecture. See the Intel C++ Compiler 7.0 supports the Fortran95 and OpenMP* for Linux User Guide for information on the standards. It is not binary compatible with intrinsic functions. the GNU g77 compiler. The Intel Fortran compiler has the same binary compatibility issues with C++ language object files The gcc C++ language extensions are created with the GNU gcc compiler, as does documented in the gcc manual. Currently, the Intel C++ compilers. the following are known GNU C++ source language compatibility limitations: The Intel C++ and Fortran compilers support • Minimum and maximum operators commonly used GNU compiler command • Declarations and definitions in one line options. The Compiler Command Line header Options section describes the options that are supported, have equivalent options and • Where’s the template? are not supported. • Extracting the function pointer from a bound pointer to member function • C++-Specific Variable, Function, C and C++ Source and Type Attributes Compatibility The C++ library documentation for the Intel The Intel C++ compiler supports the ANSI C compiler is available from Dinkumware*, the and C++ standards. In addition, some of the provider of the C++ library for the Intel C++ GNU C language extensions are supported. compiler for Linux. The extensions are documented in the gcc manual, available at http://gcc.gnu.org. Table 1 shows the supported extensions for The Linux Kernel Build the Intel C++ Compiler 5.0, 6.0 and 7.0 versions, and highlights improvements in The Intel C++ 7.0 Compiler for Linux has source compatibility. Not all C extensions greatly improved support for the GNU C are supported when compiling C++ source language extensions. files. We encourage customers to submit feature requests for additional compatibility As a demonstration of compatibility with gcc, via their Intel® Premier Support account. Intel C++ 7.0 Compilers for Linux have Premier Support is included with every successfully built and run the Linux kernels, purchased compiler. For more information, Version 2.4.18, on IA-32 and Itanium see http://www.intel.com/software/products. processors using a limited number of temporary source patches. The temporary nature of these patches will be addressed in Several of the GNU gcc C language header the future either by adding extensions to files, part of the GNU C library glibc, use gcc Intel compilers or by working with the Linux C language extensions that are not currently community to replace or reduce usage of supported by the Intel C++ compiler. less frequently used, non-standard language Modified versions of these headers are features in the kernel sources. Both efforts redistributed in the substitute headers are currently underway. package installed with the Intel C++ Compiler 7.0 for Linux. For systems using Itanium processors, source patches are required in the following GNU inline-assembly format has been areas supported on IA-32 processors since version 6.0 of the Intel C++ Compiler for Linux and • The Intel C++ Compiler for Itanium is continued in version 7.0. The Itanium processors does not support inline C++ compiler provides intrinsic functions assembly. The compiler for Itanium that provide equivalent inline assembly processors, ecc, supports a rich set of

Intel® Compilers for Linux*: Compatibility with Gnu Compilers Page 4 of 14 intrinsics that have been successfully • The alias attribute is not supported. used in place of inline assembly. The Intel workaround is to use a • Nested functions (encountered in atm function call instead of the alias driver code) are not supported by the declaration Intel C++ Compiler for Linux. As a • You cannot initialize a struct array workaround, Intel defined these ast struct x arr[]={}. This is used in functions outside of the functions in the PCMCIA package. The Intel which they are used. workaround is to use and empty • Attribute (packed) for a typedef is used stuct initialization instead. incorrectly in the kernel and is ignored • The __builtin_fabs is not supported by gcc but flagged as an error by ecc. which is also used in the PCMCIA As a workaround, Intel removed the package. The Intel workaround is to attribute(packed) specified for the not define __GNUC__ and typedef. __GNUC__MINOR while building • Get_user/put_user gcc asm macros are PCMCIA package. not yet implemented as intrinsics by ecc. The temporary workaround is to More complete details of the workarounds implement them as function calls in as used in building the kernel with the 7.0 assembly files. compilers can be found at: http://support.intel.com/support/performance For systems using IA-32 processors, source tools/c/linux/tti/kernel.htm. patches are required in the following areas • Below are some examples of non- Note that while we are interested in your standard/incorrect usage in kernel comments on Intel compilers, any questions source that gcc either ignores or directly related to the kernel implementation processes incorrectly. Intel is working need to be supported by the Linux kernel with the Linux community to change the build community. kernel source. To report issues concerning the use of Intel • Arithmetic on function pointers compilers to build the Linux kernel, please use Intel Premier Support, which is included • Duplicate type declarations with every purchased compiler. For more • Reliance on gcc optimization levels information, see to work correctly http://www.intel.com/software/products. • Also certain gcc extensions that are currently unsupported by the Intel compiler are listed below

Intel® Compilers for Linux*: Compatibility with Gnu Compilers 5 of 14

GCC C Language Extension Intel C++ Intel C++ 6.0 Intel C++ 7.0 5.0 Support Support Supports Statement Expressions No Yes Yes Locally declared labels No No Yes Labels as values No Yes Yes Nested functions No No No Constructing function calls No No No Naming an expression's type No No Yes Typeof No Yes Yes Generalized Lvalues No No Yes Conditionals omitted operand No Yes Yes Double Word Integers No No Yes Complex Numbers No Yes Yes Hex Floats No No Yes Arrays of zero length No No Yes Variable Length Arrays No No Yes Variable ARG Macros No Yes Yes looser rules for escaped newlines No No Yes strings with embedded newlines No No Yes non-lvalue arrays subscripts No No Yes arithmetic on void pointers No Yes Yes arithmetic on function pointers No No No Non-Const Initalizers No No Yes Compound Literals No No Yes Designated Initializers No Yes Yes Cast to Union Type No No Yes Case Ranges No Yes Yes Mixed Declarations & Code No No Yes Function Attributes Few Few Most Prototype & old style fnc def No No No C++ comments Yes Yes Yes $ in identifiers No No Yes ESC char. in constants No No Yes __alignof__ (types, variables) No Yes Yes Attributes of Variables Few Few Most

Intel® Compilers for Linux*: Compatibility with Gnu Compilers 6 of 14

GCC C Language Extension Intel C++ Intel C++ 6.0 Intel C++ 7.0 (continued) 5.0 Support Support Supports Inline Function fast as Macro Yes Yes Yes Inline ASM, IA-32 ONLY No Yes Yes Control Names in asm code No No Yes Variable in specified register No No Yes Alternate Keyword No No Yes Incomplete ENUM types No Yes Yes Function name as Strings No No Yes Return/Frame Address - IA-32 No No Yes Other built-in funcs No No Few Table 1: GCC C language extensions supported by the Intel C++ Compiler for Linux showing the improved compatibility available in the 7.0 compiler. Note: “Few” (“Most”) means that for a given extension that has multiple sub-extensions (such as built in functions), few (most) of the sub- extensions are supported.

Binary Compatibility Note: The 7.0 Intel C++ IA-32 and Itanium C language objects files created with the compilers have implemented minor changes Intel C++ compiler 7.0 for Linux are binary to ensure conformance to the C++ ABI compatible with the gcc compiler and glibc, standard. As a result, object and library files the GNU C language library. built with older version of the Intel Compilers for Linux need to be recompiled if upgrading to the 7.0 Compilers. The Intel C++ compiler for IA-32 and Itanium processors supports the C++ ABI, which describes conventions for binary object code interfaces between C++ code and the Linking and Libraries implementation-provided system and Linking C language with Intel and gcc runtime libraries. When the C++ ABI is fully implemented by different compiler vendors, C language objects files can be linked with C++ binary objects files and libraries will be either the Intel or gcc compilers. Linking largely compatible. with the Intel compiler is recommended, as the Intel libraries will be correctly passed to the linker. The following example The gcc 3.x compilers have improved (Illustrations 1-6) uses gcc to link the conformance with the C++ ABI standard for application with the file main.c compiled with both IA-32 and Itanium compilers. However, gcc and the file calcSin.c with the Intel there are several outstanding issues in the compiler for IA-32 applications, optimized for interpretation of the C++ ABI standard that the Intel® Pentium® 4 processor. The prevent binary compatibility, and these paper, “Optimizing Applications with the issues are being addressed. Until the C++ Intel® C++ and Fortran Compilers” ABI issues are resolved, Intel does not available at recommend mixing and matching C++ http://www.intel.com/software/products/compilers, binary files from gcc and the Intel compilers. describes the advanced compiler This applies only to C++, the Intel C++ optimizations available with the Intel Compiler 7.0 for Linux is binary compatible compiler. with GNU C. Having C++ binary compatibility is an extremely important goal of the Intel C++ compiler.

Intel® Compilers for Linux*: Compatibility with Gnu Compilers 7 of 14 This example uses the Intel compiler to compile the calcSin.c function and is able to $ gcc main.o calcSin.o automatically vectorize the loop. undefined reference to $ cat calcSin.c `__intel_cpu_indicator' #include undefined reference to `__intel_cpu_indicator_init' void calcSin(double *a,double *b, int N){ undefined reference to `__libm_sse2_sin' int i; undefined reference to `__libm_sse2_sin' for (i=0; i

$ icc -c -axW -vec_report3 calcSin.c Running the nm utility on the Intel libraries calcSin.c(4) : (col. 3) remark: LOOP WAS will help determine which libraries are VECTORIZED. required. See the Intel C++ and Fortran Illustration 1. User’s Guides, library section, for documentation on the different Intel libraries. Next, the grep utility is used (Illustration 5) The main function is compiled with gcc in to verify the symbols are defined in the Intel Illustration 2. libraries. Read the symbol file to determine $ cat main.c which library contains the missing symbol void calcSin(double *a,double *b,int N); and add this to the link options. int main() { $ nm /opt/intel/compiler70/ia32/lib/* > const int N=100000; sym.txt double a[N], b[N], c[N], x[N]; $ grep "T __intel_cpu_indicator" sym.txt int i; 000b73f0 T __intel_cpu_indicator_init for (i=0;i

Intel® Compilers for Linux*: Compatibility with Gnu Compilers Page 8 of 14 DSO version is searched for first, and if it is it is linked from the Linux math library, libm. not found, a static version is searched for. The Linux math library, libm, for the Itanium Linking the DSO version of libcxa conforms processor architecture contains optimized to the C++ ABI standard. math functions, which makes this issue more important for IA-32 processors. The following command line options modify the default behavior: Note that if the user specifies the “–lm“ • –static (or –Bstatic): Use the static command line option, the default behavior version of all libraries specified after this changes. All math functions will be linked point or until the option –Bdynamic is from libm; libimf will not be used. To avoid used. This option can be used to this, the “–limf –lm” options can be used, statically link all libraries. which uses optimized versions if available. It is common for Makefiles and build scripts • –Bdynamic: Use the dynamic (DSO) version of all libraries specified after this to specify “–lm“ to link in the math library point or until the –static (or –Bstatic) because gcc does not automatically link in option is used. Note that –static (or – the math library, libm. The Intel Compilers Bstatic) and –Bdynamic are toggles. link in the math libraries to use the optimized versions. • –i_dynamic: Link all Intel provided compiler libraries dynamically, i.e. use DSO versions of Intel libraries. Command Line Options • –shared: Instructs the linker to create a DSO instead of an application binary. The Intel C++ and Fortran compilers for Note: –shared is not the opposite of the Linux support some of the common GNU –static option. compiler command line options. Table 2 lists the GCC compiler options that are

supported by the Intel C++ compiler for The following command line options are new Linux. Table 3 lists GCC compiler options in the 7.0 release and provide additional with equivalent options supported by the flexibility: Intel compilers for Linux. Table 4 lists GCC • -static-libcxa: Link the libcxa compiler options that are not currently library statically. This option is in supported. Version 7 of the Intel Compiler conflict with the C++ ABI. increases the support of gcc command line options. If there are command line options • -dynamic-libcxa: Link the libcxa not supported that are important to you, library dynamically. please submit a feature request via your Intel Premier Support account. The ldd utility lists all of the DSO’s that an application is linked with including the Note that the Intel C++ and Fortran location of the libraries. This utility is useful compilers have a large number of features in understanding the above options. to optimize applications for the latest IA-32 and Intel Itanium processor family. The paper, Optimizing Applications with the ® Optimized Intel Math Function Library Intel(R) C++ and Fortran Compilers, The Intel® Math Function library, libimf.a, is explains how to use the Intel compilers to an optimized math library provided with the optimize for the Pentium 4 and Itanium Intel compilers for Linux. The Linux system processors. It is available at math library, libm, contains functions in http://www.intel.com/software/products/compilers/ addition to those provided in the Intel Math . Function library. By default, the Intel Compilers will first link to the libimf library, then the libm library. If an optimized function is available, it will be found in the Intel Math Function library, libimf. Otherwise

Intel® Compilers for Linux*: Compatibility with Gnu Compilers 9 of 14

Compiler Description Command Linux Option -A[(val)] Create assertion ‘name’ having value ‘val’ -ansi Select strict ANSI conformance dialect. New in version 7.0. -C Do not strip comments -D Define preprocessor macro -dM Output macro definitions in effect after preprocessing (use with -E). New in version 7.0. -E Preprocess source file to stdout -fPIC Generate position independent code. -g Generates symbolic debugging information in the object code for use by source-level debuggers. -H Print the name of each header file used. New in version 7.0. --help Basic list of compiler options. New in version 7.0. -Idir Add directory ‘dir’ to include file search path. -lmylib Search for the library file libmylib.a when linking. -Ldir Add directory ‘dir’ to library file search path -march= Generate code excusively for a given . -mcpu= Optimize for a specific cpu. -M Generate makefile dependency information. -MD Generate makefile dependency information and save in file. New in version 7.0. -MM Generate makefile dependency information like ‘-M’ option but only include user header files (#include “FILE” not #include ). -MMD Generate makefile dependency information for user header files (#include “FILE” not #include ) and save in file. New in version 7.0. -O Enable optimizations -O1 Enable optimizations. -O2 Enable optimizations. -O3 Enable –O2 optimizations plus more aggressive optimizations that may not improve performance for all programs. -ofilename Name the output file ‘filename’. -S Compile to assembly file (.s) only, do not link -Uname Remove definition of preprocessor macro ‘name’ -v Show compiler driver tool commands. New in version 7.0. -Wall Enable most warning messages. New in version 7.0. -Werror Change warnings into errors. New in version 7.0. Table 2: GCC Compiler Command Line Options with identical Intel Compilers for Linux options.

Intel® Compilers for Linux*: Compatibility with Gnu Compilers Page 10 of 14

GCC Compiler Intel® Compilers for Description Command Linux Option Linux Equivalent Option -P -P Preprocess source file omitting #line directives. The difference is output to stdout or filename with .i extension. -finline_functions -ip Inline simple function calls.

Table 3: GCC Compiler Command Line Options with Equivalent Intel Compilers for Linux options.

Compiler Description Command Linux Option -I- Any directories you specify with ‘-I’ options before the ‘-I-‘ option are searched only for the case of ‘#include “FILE”’; they are not searched for ‘#include ’. The Intel compiler -V version Runs given ‘version’ of gcc. -pipe Use pipes rather than temporary files between the different stages of compilation.

Table 4: GCC Compiler Options not currently supported.

use an interface module with the Intel compiler to call a subroutine compiled with Intel Fortran Compiler the g77 compiler. However, Illustration 12 shows a problem when I/O is performed in The Intel Fortran compiler supports the the subroutine compiled by the g77 compiler Fortran95 and OpenMP standards. The Intel due to different run-time libraries. For this Fortran compiler for Linux is not binary reason, Intel does not recommend mixing compatible with the GNU g77 compiler. In object files created by the Intel Fortran general Fortran compilers are not binary compiler and the g77 compiler. The compatible due to different run-time libraries. examples use the Intel Fortran compiler for The Intel Fortran compiler is binary IA-32 applications, and they are valid for the compatible with C language object files Itanium compiler (efc). created with either the Intel C++ compiler for

Linux or the GNU gcc compiler. However, the Intel Fortran runtime libraries contain The example below (Illustrations 7-10) show some C++ code and are built with the Intel the different name mangling scheme used by C++ compiler, making them subject to similar the Intel Fortran compiler and the g77. C++ object incompatibilities with GNU C++ $ cat example.F as described earlier. Please see the section below on “Mixed Fortran and C++ subroutine foo Applications” for mixing C++ code with end Fortran. The Intel Fortran compiler for Linux subroutine foo_bar User’s Guide has further details on calling C end language functions from Fortran. Illustration 7.

The Intel Fortran Compiler for Linux uses a different name mangling scheme than the Illustration 8 shows compiling with the Intel g77 compiler. Illustration 11 shows how to Fortran compiler and running the nm utility to

Intel® Compilers for Linux*: Compatibility with Gnu Compilers 11 of 14 list the symbols in the object file shows that Illustration 11 shows how to use an interface ifc mangles the second subroutine as module with the Intel compilers to call a “foo_bar_” (one underscore). subroutine compiled with the GNU g77 compiler.

$ ifc -c example.F $ nm example.o $ cat g77-ifc.F90 00000000 d EPC.RZERO.0 Module WULF 00000000 T foo_ interface 00000010 T foo_bar_ subroutine foo_bar() Illustration 8. !! force the compiler to generate the name foo_bar__

!DEC$ATTRIBUTES ALIAS:'foo_bar__' :: Illustration 9 shows compiling with g77 and foo_bar running nm on the object file shows g77 end subroutine mangles the second subroutine as end interface “foo_bar__” (two trailing underscores). end module $ g77 -c example.F; nm example.o program test 00000000 T foo_ USE WULF 0000000c T foo_bar__ call foo() 00000000 t gcc2_compiled. call foo_bar() Illustration 9. end

Illustration 10 shows problematic case in $ ifc –c g77-ifc.F90 which a test application was compiled with $ g77 -c example.F the Intel Fortran compiler and where in which example.F was compiled with g77. In it a $ ifc example.o g77-ifc.o test application was compiled with the Intel Illustration 11. Fortran compiler and in which example.F was compiled with g77. $ cat err-g77-ifc.F90 program test call foo() call foo_bar() end $ ifc –c err-g77-ifc.F90 $ g77 -c example.F $ ifc example.o err-g77-ifc.o err-g77-ifc.o: In function `main': err-g77-ifc.o(.text+0x21): undefined reference to `foo_bar_' Illustration 10.

Intel® Compilers for Linux*: Compatibility with Gnu Compilers Page 12 of 14 Illustration 12 shows that a problem occurs if above in “Linking C language Intel and gcc I/O is performed in a subroutine compiled objects”. with different Fortran compilers. This causes the link to fail due to unresolved references, Customer Feedback because the two compilers have different run-time libraries. Illustration 12 shows one Intel is committed to providing compilers that of many related errors that can result from deliver the highest Linux-based application mixing object files compiled with different performance for applications running on Fortran compilers. This practice is not systems that us Intel® IA-32 or Itanium recommended. processors. We strongly value customer feedback and are interested in suggestions for improved compatibility with the GNU $ cat example-io.F compilers. If your applications require SUBROUTINE FOO additional compatibility features, please submit a feature request by creating a END customer support issue via your Intel® SUBROUTINE FOO_BAR Premiers Support account, which explains print*,'in foo_bar' your request and its impact. END $ ifc g77-ifc.F90 Developers should register for an Intel $ g77 -c example-io.F Premier Support account to obtain technical $ ifc example-io.o g77-ifc.o support and product updates. The product example-io.o: In function release notes describe how to register or you `foo_bar__': can visit the Intel Software Development Products home page at example-io.o(.text+0x17): undefined reference to `s_wsle' http://www.intel.com/software/products. example-io.o(.text+0x30): undefined reference to `do_lio' example-io.o(.text+0x38): undefined Summary reference to `e_wsle' This paper discussed the improved source Illustration 12. language, binary or object file, and compiler options compatibility of the Intel C++ and Fortran Compilers for Linux with the GNU compilers. Mixed Fortran and C++ Applications If a Linux application contains C++ and Fortran routines, it is necessary to use the Intel C++ Compiler for Linux with the Intel Fortran Compiler for Linux. If a Linux application contains C (not C++), then the gcc or the Intel compiler for Linux can be used to compile the C functions. The reason for this is the Fortran libraries contain C++ code and currently C++ binary files cannot be linked with the gcc and Intel compilers. The section “Binary Compatibility” above describes this in detail. When linking C language object files with Fortran, Intel recommends using the Intel C++ Compiler for Linux to correctly link in the Intel libraries, but it is possible to pass options to the gcc compiler to do the same. See the example

Intel® Compilers for Linux*: Compatibility with Gnu Compilers 13 of 14

References • http://www.intel.com/software/products General information on Intel software development tools including the Intel C++ and Fortran compilers. • http://developer.intel.com/software/products/op ensource/ - Documentation, application notes and source code for libraries, tools, and code examples. • http://developer.intel.com/design/itanium/ Information on Intel Itanium processor architecture. • http://developer.intel.com/design/pentium4/ Intel Pentium 4 processor information. • http://www.openmp.org - Information on the OpenMP standard. • http://www.ansi.org - Information on the ANSI C and C++ standards. • http://www.gnu.org - Information on the GNU project including GNU gcc and g77 compilers and glibc, the GNU C library. • http://www.codesourcery.com/cxx-abi/ C++ Application Binary Interface describes conventions for object code interfaces between C++ code and implementation-provided system and libraries.

Intel® Compilers for Linux*: Compatibility with Gnu Compilers Page 14 of 14