This section lists various difficulties encountered in using GCC
together with other compilers or with the assemblers, linkers,
libraries and debuggers on certain systems.
- On many platforms, GCC supports a different ABI for C++ than do other
compilers, so the object files compiled by GCC cannot be used with object
files generated by another C++ compiler.
An area where the difference is most apparent is name mangling. The use
of different name mangling is intentional, to protect you from more subtle
problems.
Compilers differ as to many internal details of C++ implementation,
including: how class instances are laid out, how multiple inheritance is
implemented, and how virtual function calls are handled. If the name
encoding were made the same, your programs would link against libraries
provided from other compilers—but the programs would then crash when
run. Incompatible libraries are then detected at link time, rather than
at run time.
- Older GDB versions sometimes fail to read the output of GCC version
2. If you have trouble, get GDB version 4.4 or later.
- DBX rejects some files produced by GCC, though it accepts similar
constructs in output from PCC. Until someone can supply a coherent
description of what is valid DBX input and what is not, there is
nothing that can be done about these problems.
- The GNU assembler (GAS) does not support PIC. To generate PIC code, you
must use some other assembler, such as /bin/as.
- On some BSD systems, including some versions of Ultrix, use of profiling
causes static variable destructors (currently used only in C++) not to
be run.
- On some SGI systems, when you use -lgl_s as an option,
it gets translated magically to `-lgl_s -lX11_s -lc_s'.
Naturally, this does not happen when you use GCC.
You must specify all three options explicitly.
- On a SPARC, GCC aligns all values of type
double
on an 8-byte
boundary, and it expects every double
to be so aligned. The Sun
compiler usually gives double
values 8-byte alignment, with one
exception: function arguments of type double
may not be aligned.
As a result, if a function compiled with Sun CC takes the address of an
argument of type double
and passes this pointer of type
double *
to a function compiled with GCC, dereferencing the
pointer may cause a fatal signal.
One way to solve this problem is to compile your entire program with GCC.
Another solution is to modify the function that is compiled with
Sun CC to copy the argument into a local variable; local variables
are always properly aligned. A third solution is to modify the function
that uses the pointer to dereference it via the following function
access_double
instead of directly with `*':
inline double
access_double (double *unaligned_ptr)
{
union d2i { double d; int i[2]; };
union d2i *p = (union d2i *) unaligned_ptr;
union d2i u;
u.i[0] = p->i[0];
u.i[1] = p->i[1];
return u.d;
}
Storing into the pointer can be done likewise with the same union.
- On Solaris, the
malloc
function in the libmalloc.a library
may allocate memory that is only 4 byte aligned. Since GCC on the
SPARC assumes that doubles are 8 byte aligned, this may result in a
fatal signal if doubles are stored in memory allocated by the
libmalloc.a library.
The solution is to not use the libmalloc.a library. Use instead
malloc
and related functions from libc.a; they do not have
this problem.
- Sun forgot to include a static version of libdl.a with some
versions of SunOS (mainly 4.1). This results in undefined symbols when
linking static binaries (that is, if you use -static). If you
see undefined symbols
_dlclose
, _dlsym
or _dlopen
when linking, compile and link against the file
mit/util/misc/dlsym.c from the MIT version of X windows.
- The 128-bit long double format that the SPARC port supports currently
works by using the architecturally defined quad-word floating point
instructions. Since there is no hardware that supports these
instructions they must be emulated by the operating system. Long
doubles do not work in Sun OS versions 4.0.3 and earlier, because the
kernel emulator uses an obsolete and incompatible format. Long doubles
do not work in Sun OS version 4.1.1 due to a problem in a Sun library.
Long doubles do work on Sun OS versions 4.1.2 and higher, but GCC
does not enable them by default. Long doubles appear to work in Sun OS
5.x (Solaris 2.x).
- On HP-UX version 9.01 on the HP PA, the HP compiler
cc
does not
compile GCC correctly. We do not yet know why. However, GCC
compiled on earlier HP-UX versions works properly on HP-UX 9.01 and can
compile itself properly on 9.01.
- On the HP PA machine, ADB sometimes fails to work on functions compiled
with GCC. Specifically, it fails to work on functions that use
alloca
or variable-size arrays. This is because GCC doesn't
generate HP-UX unwind descriptors for such functions. It may even be
impossible to generate them.
- Debugging (-g) is not supported on the HP PA machine, unless you use
the preliminary GNU tools.
- Taking the address of a label may generate errors from the HP-UX
PA assembler. GAS for the PA does not have this problem.
- Using floating point parameters for indirect calls to static functions
will not work when using the HP assembler. There simply is no way for GCC
to specify what registers hold arguments for static functions when using
the HP assembler. GAS for the PA does not have this problem.
- In extremely rare cases involving some very large functions you may
receive errors from the HP linker complaining about an out of bounds
unconditional branch offset. This used to occur more often in previous
versions of GCC, but is now exceptionally rare. If you should run
into it, you can work around by making your function smaller.
- GCC compiled code sometimes emits warnings from the HP-UX assembler of
the form:
(warning) Use of GR3 when
frame >= 8192 may cause conflict.
These warnings are harmless and can be safely ignored.
- On the IBM RS/6000, compiling code of the form
extern int foo;
... foo ...
static int foo;
will cause the linker to report an undefined symbol foo
.
Although this behavior differs from most other systems, it is not a
bug because redefining an extern
variable as static
is undefined in ISO C.
- In extremely rare cases involving some very large functions you may
receive errors from the AIX Assembler complaining about a displacement
that is too large. If you should run into it, you can work around by
making your function smaller.
- The libstdc++.a library in GCC relies on the SVR4 dynamic
linker semantics which merges global symbols between libraries and
applications, especially necessary for C++ streams functionality.
This is not the default behavior of AIX shared libraries and dynamic
linking. libstdc++.a is built on AIX with “runtime-linking”
enabled so that symbol merging can occur. To utilize this feature,
the application linked with libstdc++.a must include the
-Wl,-brtl flag on the link line. G++ cannot impose this
because this option may interfere with the semantics of the user
program and users may not always use `g++' to link his or her
application. Applications are not required to use the
-Wl,-brtl flag on the link line—the rest of the
libstdc++.a library which is not dependent on the symbol
merging semantics will continue to function correctly.
- An application can interpose its own definition of functions for
functions invoked by libstdc++.a with “runtime-linking”
enabled on AIX. To accomplish this the application must be linked
with “runtime-linking” option and the functions explicitly must be
exported by the application (-Wl,-brtl,-bE:exportfile).
- AIX on the RS/6000 provides support (NLS) for environments outside of
the United States. Compilers and assemblers use NLS to support
locale-specific representations of various objects including
floating-point numbers (`.' vs `,' for separating decimal
fractions). There have been problems reported where the library linked
with GCC does not produce the same floating-point formats that the
assembler accepts. If you have this problem, set the LANG
environment variable to `C' or `En_US'.
- Even if you specify -fdollars-in-identifiers,
you cannot successfully use `$' in identifiers on the RS/6000 due
to a restriction in the IBM assembler. GAS supports these
identifiers.
- On Ultrix, the Fortran compiler expects registers 2 through 5 to be saved
by function calls. However, the C compiler uses conventions compatible
with BSD Unix: registers 2 through 5 may be clobbered by function calls.
GCC uses the same convention as the Ultrix C compiler. You can use
these options to produce code compatible with the Fortran compiler:
-fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
- On the Alpha, you may get assembler errors about invalid syntax as a
result of floating point constants. This is due to a bug in the C
library functions
ecvt
, fcvt
and gcvt
. Given valid
floating point numbers, they sometimes print `NaN'.