⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trouble.texi

📁 理解和实践操作系统的一本好书
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,@c 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,@c Inc.@c This is part of the GCC manual.@c For copying conditions, see the file gcc.texi.@node Trouble@chapter Known Causes of Trouble with GCC@cindex bugs, known@cindex installation trouble@cindex known causes of troubleThis section describes known problems that affect users of GCC@.  Mostof these are not GCC bugs per se---if they were, we would fix them.But the result for a user may be like the result of a bug.Some of these problems are due to bugs in other software, some aremissing features that are too much work to add, and some are placeswhere people's opinions differ as to what is best.@menu* Actual Bugs::		      Bugs we will fix later.* Cross-Compiler Problems::   Common problems of cross compiling with GCC.* Interoperation::      Problems using GCC with other compilers,			   and with certain linkers, assemblers and debuggers.* Incompatibilities::   GCC is incompatible with traditional C.* Fixed Headers::       GCC uses corrected versions of system header files.                           This is necessary, but doesn't always work smoothly.* Standard Libraries::  GCC uses the system C library, which might not be                           compliant with the ISO C standard.* Disappointments::     Regrettable things we can't change, but not quite bugs.* C++ Misunderstandings::     Common misunderstandings with GNU C++.* Protoize Caveats::    Things to watch out for when using @code{protoize}.* Non-bugs::		Things we think are right, but some others disagree.* Warnings and Errors:: Which problems in your code get warnings,                         and which get errors.@end menu@node Actual Bugs@section Actual Bugs We Haven't Fixed Yet@itemize @bullet@itemThe @code{fixincludes} script interacts badly with automounters; if thedirectory of system header files is automounted, it tends to beunmounted while @code{fixincludes} is running.  This would seem to be abug in the automounter.  We don't know any good way to work around it.@itemThe @code{fixproto} script will sometimes add prototypes for the@code{sigsetjmp} and @code{siglongjmp} functions that reference the@code{jmp_buf} type before that type is defined.  To work around this,edit the offending file and place the typedef in front of theprototypes.@end itemize@node Cross-Compiler Problems@section Cross-Compiler ProblemsYou may run into problems with cross compilation on certain machines,for several reasons.@itemize @bullet@itemAt present, the program @file{mips-tfile} which adds debugsupport to object files on MIPS systems does not work in a crosscompile environment.@end itemize@node Interoperation@section InteroperationThis section lists various difficulties encountered in using GCCtogether with other compilers or with the assemblers, linkers,libraries and debuggers on certain systems.@itemize @bullet@itemOn many platforms, GCC supports a different ABI for C++ than do othercompilers, so the object files compiled by GCC cannot be used with objectfiles generated by another C++ compiler.An area where the difference is most apparent is name mangling.  The useof different name mangling is intentional, to protect you from more subtleproblems.Compilers differ as to many internal details of C++ implementation,including: how class instances are laid out, how multiple inheritance isimplemented, and how virtual function calls are handled.  If the nameencoding were made the same, your programs would link against librariesprovided from other compilers---but the programs would then crash whenrun.  Incompatible libraries are then detected at link time, rather thanat run time.@itemOn some BSD systems, including some versions of Ultrix, use of profilingcauses static variable destructors (currently used only in C++) not tobe run.@itemOn some SGI systems, when you use @option{-lgl_s} as an option,it gets translated magically to @samp{-lgl_s -lX11_s -lc_s}.Naturally, this does not happen when you use GCC@.You must specify all three options explicitly.@itemOn a SPARC, GCC aligns all values of type @code{double} on an 8-byteboundary, and it expects every @code{double} to be so aligned.  The Suncompiler usually gives @code{double} values 8-byte alignment, with oneexception: function arguments of type @code{double} may not be aligned.As a result, if a function compiled with Sun CC takes the address of anargument of type @code{double} and passes this pointer of type@code{double *} to a function compiled with GCC, dereferencing thepointer 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 withSun CC to copy the argument into a local variable; local variablesare always properly aligned.  A third solution is to modify the functionthat uses the pointer to dereference it via the following function@code{access_double} instead of directly with @samp{*}:@smallexampleinline doubleaccess_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;@}@end smallexample@noindentStoring into the pointer can be done likewise with the same union.@itemOn Solaris, the @code{malloc} function in the @file{libmalloc.a} librarymay allocate memory that is only 4 byte aligned.  Since GCC on theSPARC assumes that doubles are 8 byte aligned, this may result in afatal signal if doubles are stored in memory allocated by the@file{libmalloc.a} library.The solution is to not use the @file{libmalloc.a} library.  Use instead@code{malloc} and related functions from @file{libc.a}; they do not havethis problem.@itemOn the HP PA machine, ADB sometimes fails to work on functions compiledwith GCC@.  Specifically, it fails to work on functions that use@code{alloca} or variable-size arrays.  This is because GCC doesn'tgenerate HP-UX unwind descriptors for such functions.  It may even beimpossible to generate them.@itemDebugging (@option{-g}) is not supported on the HP PA machine, unless you usethe preliminary GNU tools.@itemTaking the address of a label may generate errors from the HP-UXPA assembler.  GAS for the PA does not have this problem.@itemUsing floating point parameters for indirect calls to static functionswill not work when using the HP assembler.  There simply is no way for GCCto specify what registers hold arguments for static functions when usingthe HP assembler.  GAS for the PA does not have this problem.@itemIn extremely rare cases involving some very large functions you mayreceive errors from the HP linker complaining about an out of boundsunconditional branch offset.  This used to occur more often in previousversions of GCC, but is now exceptionally rare.  If you should runinto it, you can work around by making your function smaller.@itemGCC compiled code sometimes emits warnings from the HP-UX assembler ofthe form:@smallexample(warning) Use of GR3 when  frame >= 8192 may cause conflict.@end smallexampleThese warnings are harmless and can be safely ignored.@itemIn extremely rare cases involving some very large functions you mayreceive errors from the AIX Assembler complaining about a displacementthat is too large.  If you should run into it, you can work around bymaking your function smaller.@itemThe @file{libstdc++.a} library in GCC relies on the SVR4 dynamiclinker semantics which merges global symbols between libraries andapplications, especially necessary for C++ streams functionality.This is not the default behavior of AIX shared libraries and dynamiclinking.  @file{libstdc++.a} is built on AIX with ``runtime-linking''enabled so that symbol merging can occur.  To utilize this feature,the application linked with @file{libstdc++.a} must include the@option{-Wl,-brtl} flag on the link line.  G++ cannot impose thisbecause this option may interfere with the semantics of the userprogram and users may not always use @samp{g++} to link his or herapplication.  Applications are not required to use the@option{-Wl,-brtl} flag on the link line---the rest of the@file{libstdc++.a} library which is not dependent on the symbolmerging semantics will continue to function correctly.@itemAn application can interpose its own definition of functions forfunctions invoked by @file{libstdc++.a} with ``runtime-linking''enabled on AIX@.  To accomplish this the application must be linkedwith ``runtime-linking'' option and the functions explicitly must beexported by the application (@option{-Wl,-brtl,-bE:exportfile}).@itemAIX on the RS/6000 provides support (NLS) for environments outside ofthe United States.  Compilers and assemblers use NLS to supportlocale-specific representations of various objects includingfloating-point numbers (@samp{.} vs @samp{,} for separating decimalfractions).  There have been problems reported where the library linkedwith GCC does not produce the same floating-point formats that theassembler accepts.  If you have this problem, set the @env{LANG}environment variable to @samp{C} or @samp{En_US}.@item@opindex fdollars-in-identifiersEven if you specify @option{-fdollars-in-identifiers},you cannot successfully use @samp{$} in identifiers on the RS/6000 dueto a restriction in the IBM assembler.  GAS supports theseidentifiers.@end itemize@node Incompatibilities@section Incompatibilities of GCC@cindex incompatibilities of GCC@opindex traditionalThere are several noteworthy incompatibilities between GNU C and K&R(non-ISO) versions of C@.@itemize @bullet@cindex string constants@cindex read-only strings@cindex shared strings@itemGCC normally makes string constants read-only.  If severalidentical-looking string constants are used, GCC stores only onecopy of the string.@cindex @code{mktemp}, and constant stringsOne consequence is that you cannot call @code{mktemp} with a stringconstant argument.  The function @code{mktemp} always alters thestring its argument points to.@cindex @code{sscanf}, and constant strings@cindex @code{fscanf}, and constant strings@cindex @code{scanf}, and constant stringsAnother consequence is that @code{sscanf} does not work on some veryold systems when passed a string constant as its format control stringor input.  This is because @code{sscanf} incorrectly tries to writeinto the string constant.  Likewise @code{fscanf} and @code{scanf}.The solution to these problems is to change the program to use@code{char}-array variables with initialization strings for thesepurposes instead of string constants.@item@code{-2147483648} is positive.This is because 2147483648 cannot fit in the type @code{int}, so(following the ISO C rules) its data type is @code{unsigned long int}.Negating this value yields 2147483648 again.@itemGCC does not substitute macro arguments when they appear inside ofstring constants.  For example, the following macro in GCC@smallexample#define foo(a) "a"@end smallexample@noindentwill produce output @code{"a"} regardless of what the argument @var{a} is.@cindex @code{setjmp} incompatibilities@cindex @code{longjmp} incompatibilities@itemWhen you use @code{setjmp} and @code{longjmp}, the only automaticvariables guaranteed to remain valid are those declared@code{volatile}.  This is a consequence of automatic registerallocation.  Consider this function:@smallexamplejmp_buf j;foo ()@{  int a, b;  a = fun1 ();  if (setjmp (j))    return a;  a = fun2 ();  /* @r{@code{longjmp (j)} may occur in @code{fun3}.} */  return a + fun3 ();@}@end smallexampleHere @code{a} may or may not be restored to its first value when the@code{longjmp} occurs.  If @code{a} is allocated in a register, thenits first value is restored; otherwise, it keeps the last value storedin it.@opindex WIf you use the @option{-W} option with the @option{-O} option, you willget a warning when GCC thinks such a problem might be possible.@itemPrograms that use preprocessing directives in the middle of macroarguments do not work with GCC@.  For example, a program like thiswill not work:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -