2. Where is the Dongdong?
2.1 Where is GCC-HOWTO?
This document is one of the Linux Howto series. In other words, you can find her in all sites where Linux HOWTO files are stored, such as http://sunsite.unc.edu/pub/linux/docs/howto/ . HTML version (possibly a newer version) can be captured from http://ftp.linux.org.uk/~barlow/howto/gccc-howto.html.
2.2 Where is the GCC related data?
The standard GCC description file is included in the Source Distribution (there is a look in the head in the Source Distribution). If your network connection is fast enough, or there is a CDROM, otherwise, he has a high degree of patience, you can put it Untar, then copy the corresponding bits to / usr / info directory. If your conditions do not match the above, you may wish to visit visit to TSX-11. However, I think, there is no need to always be the latest version!
There are two sources of file instructions for libc. One is GNU libc, stored in. Info's format, except for STDIO, the description of the remaining Linux libc is quite detailed and accurate. Another file description that can be found on the system call (Section 2) and the libc function (Section 3) on the Linux's Archive ManPages.
2.3 GCC
Solution is 2:
(a) You can find a formal Linux GCC Distribution System (Distribution) on ftp:/pub/linux/packages/gcc/, and is a functions that have been compiled. . When I am writing this file, 2.7.2 (GCC-2.7.2.bin.tar.gz) is the latest version.
(b) The latest source code released by the free software foundation (Free Software Foundation can be obtained from the website GNU Archives. There is no need to consisten to the above version, but this version is indeed the latest. Linux GCC maintenance users (Maintainers) makes you easily compile this latest version. Configure Script File (Script) will help you automatically set all the things you do. I suggest you have time, you may wish to see it, say that there will be a revised version is what you will want.
If you want to write some useful software (not me, there are many software that have no use of the use of the use of the software.), What you need to talk about this section below:
2.4 C Prunivers and Taround
Which of the store is depends on (i) your system is ELF or a.out; (ii) Which of you want your system? If you upgrade from libc 4 to libc 5, give you a conscientious suggestion, let's take a look at Elf-Howto. You will be asked, where is the ELF file? Hey there! Hey there! If it is unbedied, it is similar to the same location as this file. The website TSX-11 can find what you want.
LIBC-5.2.18.bin.tar.gz
--- ELF Shared Library Images, Static Libraries and headers (for C language and mathematics).
LIBC-5.2.18.Tar.gz
--- source code for libc-5.2.18.bin.tar.gz. You also need this file because .bin. Suite (package) contains the required header file. If you are hesitant, you don't know that you are in your own sea. It is better to compile the C library; or use the binaries who use people to compile people. Have this trouble, come, look at my mouth: I can't solve it using people. Only if you want NYS or Shadow Password, you need your own hand to push the cradle.
LIBC-4.7.5.bin.tar.gz
--- This file is a.Sout's Shared Library Image and the static library, which is designed to coexist with the aforementioned libc 5 suite, but unless you want to continue using A.out The program or proceedings continue to develop A.out, otherwise, it is not necessary.
2.5 Has associated tools (AS, LD, AR, STRINGS ETC)
So far, these tools can be found from the website TSX-11 as before. The current version is binutils-2.6.0.2.bin.tar.gz.
It should be noted that binutils only applies to ELF, and the current libc version is also Elf; Of course, if you are used to A.out, if you have an ELF's libc, it is used together, this is They are very good. It is undeniable that the development of the C prices is moving towards ELF format with a firm foottet, unless you really have a good reason, need A.out's stuff, you will encourage you to break through, joining early The big trend is unstoppable.
3. GCC installation and GCC setting
3.1 GCC version
Type GCC -V under the shell's prompt, the version of the GCC you currently is currently using is displayed. At the same time, this is also a fairly reliable way to determine that ELFs you use are ELF or A.out. In my system, the result of performing GCC -V is:
$ GCC -V
Reading Specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
GCC Version 2.7.2
The above message points out a few important things:
i486 This is specified that the GCC you are using now is written for the 486 microprocessor - your computer may be 386 or 586. The program code compiled by the three microprocessors chips, which can be used in compatibility with each other. The difference is that the 486 program code has a Padding function in some places, so you can run more fast at 486. This for 386 machines, the performance of the executing procedure does not have any adverse effects, but it really makes the program code a little bigger. Box can be said to be something wrong; but it may also be referred to (like Slackware or Debian), or nothing is (so Luo! Complete directory name is i486-linux). If you are the leader of the practice, you can create your own GCC, then you can set this in the process of building to load your facade. Just like I did :-). Linux actually refers to Linuxelf or Linuxaout. This will cause unnecessary confusion, what will refer to which one will vary depending on the version you use.
Linux means that if the version number of ELF is 2.7.0. (or updated version); otherwise, it is a.out. Linuxaout means the format of A.out. When Linux's definition is replaced from A.out to ELF, Linuxaout will be shine, and it is turned into a target. So you won't see any version of the GCC whose version is newly 2.7.0. There is Linuxaout. Linuxelf has been out of time. This is usually a GCC of version 2.6.3, and this version can also be used to generate an executable file for ELF. It should be noted that GCC 2.6.3 has bugs when generating an ELF program code, so if you are using it happens to be this version, it is recommended that you upgrade quickly. Sequence number of version 2.7.2. So, summarize, I have a version 2.7.2 GCC, which can generate program code in ELF format. It's so simple, surprised! EH?
3.2 Where is the Dongdong installed?
If you don't carefully look at the screen when you install the GCC, or you are caught in a complete release system, then you will want to know those who live in the entire document system after these stuffs. local. Several focus is as follows:
/ usr / lib / gcc-lib / target / version / (with subdirectory) The compiler is living in this place. There is an executable program here, actually doing compilation; in addition, there are some specific versions of libraries and headers, etc. will also be stored here. / usr / bin / gcc refers to a compiler's driver - it is the program you actually execute on Command Line. This catalog can be used for various versions of GCC, as long as you can install them with different compiler directories (as described above). To know that the content is that one, play GCC -V under the shell prompt symbol. If you want to force a version, change GCC -V Version. E.g:
# GCC -V
Reading Specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
GCC Version 2.7.2
# GCC -V 2.6.3 -V
Reading Specs from /usr/lib/gcc-lib/i486-box-linux/2.6.3/specs
GCC Driver Version 2.7.2 Executing GCC VERSION 2.6.3
/ usr / target / (bin | lib | incude) / If you have a digital target object, such as A.out and ELF, or a cross-compiler (Cross-Compiler), those belong to The mainstream target object (Non-Native Target (S)) library, Binutils (AS, LD, etc.) tools and headers can be found here. Even if you only have a GCC, you can find these originals here, it is the stuff prepared for them. If it is not here, then it should be in / usr / (bin | lib | incrude). / lib /, / usr / lib and other directory, etc. are all mainstream system (Native-System). Many applications use / lib / cpp, so you also need it --- practice, not copying from / usr / lib / gcc-lib / target / version / directory, is Symlink Point to there. [Translator Note: The so-called native means that your system is in the format of A.out or ELF, or which version of the constant GCC is equal. Native means 'local', 'The country' '' '' '' '' s " After the platform, if you add some different target objects, you will have 'local' and '外 省' (not related to politics), 'Domestic' and 'Foreign', 'Natural' and 'Artificial', etc. It also contains the meaning of the default. If you add your personal values and preferences, I want to use mainstream (NON-NATIVE) to translate properly. ] 3.3 Header gear? Header gear?
If you install your own yourself in the header of the / usr / local / include directory, there is another three main header files below the header of the / usr / local / incrude directory.
/ usr / include / with headers under its subdirectory, most of them are provided by the Libc Binary Package, which is developed by H.J.LU. I will only say the reason for the 'large part', because you may have some other source header (like Curses and DBM libraries, etc.) are waiting here; especially if you are now using the latest LIBC If the issuance system (the new version is not like the old version, there is no longer supporting Curses or DBM.) [Translator Note: libc binary package refers to a kit stored in a machine code. It is not a source code (TEXT). To translate in Chinese, it is a 'libc binary kit', which seems to be The teeth are suspected, and it is slightly going to binary, and it is known to the libc kit. ] Kernel Source Distribution, / USR / include / on / usr / include / asm (in front of these files:
$ SU
# make config
(Answer the next question. Usually answering is not correct, unless you intend to continue to make the core.)
# cd / usr / include
# ln -s ../src/linux/include/linux.
# ln -s ../src/linux/include/ASM.
If
Target Platform as a labeled job platform
Suppose you have got the source code of the GCC, usually you can complete all settings as long as you follow the instructions of the install file. Behind make again configure --target = i486-linux --host = xxx on platage xxx, you can help you change. It should be noted that you will need Linux and the core header gear; it also needs to establish a cross group translator (Cross Linker), the source is ftp: //tsx-11.mit. EDU / PUB / Linux / Packages / GCC /.
Linux as a Source Platform, MSDOS as a target work platform
UGH. Obviously, this probably needs to use the suite "EMX" or the extension kit "Go". Please go to ftp://sunsite.unc.edu/pub/linux/devel/msdos to see it. I have not tested these things, so there is no way to guarantee what.
4. Transplant procedures and compilers
4.1 GCC defined symbols
As long as the GCC is executed, the -v this parameter can be found, you can find the GCC you use, which will help you define what symbols. For example, my machine looks like this:
$ Echo 'main () {Printf ("Hello World / N");}' | gcc -e -v -
Reading Specs from /usr/lib/gcc-lib/i486-box-linux/2.7.2/specs
GCC Version 2.7.2
/usr/lib/gcc-lib/i486-box-linux/2.7.2/cpp -lang-c -v -undef
-D__gnuc __ = 2 -d__gnuc_minor __ = 7 -d__elf__ -dunix -di386 -dlinux
-D__elf__ -d__unix__ -d__i386__ -d__linux__ -d__unix -d__i386
-D__linux -asystem (unix) -asystem (pOSIX) -Acpu (i386)
-AMACHINE (i386) -D__i486__
If the program code you are writing will use some Linux unique features, then those who cannot be transplanted, enclose the pre-commands that are compiled, but a good idea! As shown below:
#ifDef __linux__
/ * ... funky stuff ... * /
#ENDIF / * Linux * /
Use __linux__ to achieve a goal; look at it carefully, not Linux. Although Linux also has definitions, after all, this is still not a POSIX standard.
4.2 Online SOLVED
The instruction file of the GCC compiler parameter is GCC Info Page (in Emacs, pressing C-H i, then select the 'GCC' option). If you can't get it, you don't sell your CD-ROM, you didn't press this East to you, or you are now using the old version. In this case, the best way is to move the hip to Archive ftp://prep.ai.mit.edu/pub/gnu or its mirrors platform, go home to the GCC's source code case, re- Cook. GCC Manual Page (GCC.1) can be said to be outdated, if you are full, it is nothing to see, it will tell you that nothing is bored.
Flag is fluttering
When the GCC is executed on the command column, as long as the -on's option is backed up behind, the GCC can give you the best encoded machine code. Here, N is a can have no small integer. The meaning of different versions of GCC, N is different from its correct effect, but the typical range is from 0 (do not want to cock, I don't know the best code.) Change To 2 (best coding.), Upgrade to 3 (best coding, more, more).
GCC translates these numbers into a series of -f and -m options. Bring the flag-V and -Q when performing GCC, you can clearly see that each level of -O is corresponding to those options. For example, in -o2, my GCC told me:
ENABED: -FDEFER-POP -FCSE-FOLLOW-JUMPS -FCSE-SKIP-Blocks
-FEXPENSIVE-OPTIMIZATIONS
-fthread-jumps -fpeephole -fforce-mat -ffunction-cse -finline
-FCALLER-SAVES -FPCC-STRUCT-RETURN -FRERUN-CSE-AFTER-LOOP
-FCOMMON-FGNU-Linker -m80387 -Mhard-float-malo-soft-float
-MNO-386 -M486 -Mieee-fp -MFP-RET-IN-387
If you use the best coding level than your compiler, you can support (E.G. -O6), then its effect is the same as you have the highest level of your compiler. To be honest, the GCC program code that releases it goes is actually used in compiling this problem. It is really not a good idea. In the future, if there is a more advanced best coding method, it is specifically integrated into a new version, and you (or your useers) try to do this, you may find that GCC will interrupt your program.
Upgrading from GCC 2.7.0 to 2.7.2 should pay attention to a bug when using -O2. Worse, the strength reduction parameters are actually useless! If you like to recompile GCC, there is such a revised version to correct this error; otherwise, be sure to determine how to add -fno-strength-reduu every time you compile!
11/12/97 translation
Some microprocessor
There are some -M's flags that are useful, but they cannot be used by various grades -O open. The most important thing in this is the two types of -m386 and -m486, used to tell GCC to treat the program code being compiled as 386 or 486 machines. Whether it is to compile the program code, you can perform on each other's machines, and the code compiled by -M486 will be relatively large, but it will not be more slow to brought on the 386 machine.
There is currently no -mpensium or the banner of -m586. Linus recommends that we can use -m486 -malign-loops = 2 -malign-jumps = 2 -malign-functions = 2 to get the best encoded 486 program code, do just avoid Alignment (Pentium does not need) Large GAPS happened. Michael Meissner said: My sixth told me,
-Mno-strength-redu (! To know that I am not talking about the bug of intensity reduction parameters, it is already another battle battlefield.) The same can also produce a faster program code on the X86 machine. This is because the X86 machine has an indelible □ thirst, and GCC's Method of Grouping Registers Into Spill Registers vs. Other Registers doesn't Help Either. Traditionally, the result of intensity reduction will enable the compiler to replace the multiplication operation by using the addition register with an additional operation. In fact, I am suspected
-fcaller-saves may be just a vulnerability.
And my seventh feeling will tell me again,
-FOMIT-FRAME-POINTER may also have any earning heads. From this point of view, it means that there is another question that can be used to handle memory allocation. On the other hand, if purely from the X86 machine is converted into a machine code, it is necessary to say that the memory space used by the stack is much more than if the Frame is used. In other words, ICache is the program There is no substantial help, if you use it.
-FOTIMIT-FRAME-POINTER, but also tells the compiler that after each call function, you must correct stacking indicators; however, if Frame is not called, if there is not much number of times, it is allowed to be temporarily stacked.
The last paragraph of this is still coming from Linus:
It should be noted that if you want to get the best condition, don't believe in me. In any case, you must test it. There are still many parameters available in the GCC compiler, which may have a most special combination that gives you the best coded results.
11/14/97 translation 5/15/98 correction
INTERNAL COMPILER ERROR: CC1 Got Fatal Signal 11
Signal 11 refers to sigsegv, or 'segmentation violation'. This means that GCC is confused to the indicators you have used, but also try to write data in memory that does not belong to it. So, this may be a GCC bug. However, generally, GCC is a software masterpiece that has been strictly tested and has a reliability. It also uses a large number of complex data structures and amazing numbers. In short, if you want to select this century, the most meticulous RAM test program is the most meticulous RAM test, and GCC is absolutely a crown. If you can't re-copy this bug - when you restart compile, the wrong message has not always appeared in the same place - there is almost certain, it is your hardware itself has a problem (CPU, memory, host Board or more memory). Don't be tested by your computer, or Windows can run very smooth, or anything else, you will return to the head to say that this is a BUG of GCC; These test movements you have done usually have no actual value, this is a very reasonable conclusion. Also, don't stay in the class of the core, you should always stay in the 'Make Zimage' stage, you have to be big, this is the BUG of GCC -, of course it will stop there! When doing 'make zimage', the file that needs to be compiled may exceed 200 files; we are experimenting an alternative solution. If you can overcome the generated bug, and (it is best this!) You can write a short program to show this bug, you can make it bug report, then email gives FSF, or Linux- GCC Communication Forum. You can refer to the GCC's instruction file to see what more detailed information is what they need.
4.3 Transplantability
According to reports, many positive news recently pointed out that if there is some Dongdong to now, it is not ported to Linux, then it is certain that it must be a little value. :-)
Ok! A bit. In general, the source code only needs to do some local modifications, you can overcome Linux 100% and POSIX compatible qualities. If you have made any modifications, it will be a very constructive move to pass this part to the original. This will only need to use 'Make' in the future, you can get an executable file.
BSDess (with BSD_IOCTL, DAEMON and
When compiling programs, you can match -i / usr / include / bsd and link -LBSD libraries. (Example: In your makefile file, add -i / usr / include / bsd to CFLAGS, and add -lbsd to the ldflags). If you really want the signal behavior in the BSD format, you don't need to add -D__use_bsd_signal. That's because when you use -i / usr / include / BSD, it will be automatically added when you have the header file
Lost Seal (Sigbus, SiGEMT, SIGIOT, Sigtrap, Sigsys ETC)
Linux is fully compatible with POSIX. However, some signals are not defined by POSIX - ISO / IEC 9945-1: 1990 (IEEE STD 1003.1-1990), Paragraph B.3.3.1.1 Sez:
"Slight Sigbus, SiGEMT, SIGIOT, SigTrap and Sigsys signals in POSIX.1, because their behavior is closely related to specific ways, and cannot be properly classified. After confirming the specific method, they can send these signals. However, it is necessary to explain that they are sent under what kind of environment, and pointed out any restrictions related to their development. "
To fix this problem, the simplest is also the most stupid method is to redefine these signals with SIGUNUSED. The correct way should be to process these issues with conditional compilation #ifDef:
#ifdef Sigsys
/ * ... Non-POSIX Sigsys code Here ... * /
#ENDIF
11/15/97 translation 5/22/98 correction
K & R
GCC is a compiler with an ANSI; strangely, most program code does not meet the standards set by ANSI. If you love ANSI, I like to write the C procedure with the standards provided by ANSI. In addition to adding the banner of -traditional, there is no more trouble. THERE IS A CERTAIN Amount of Finer-Grained Control over Which Varieties of Brain Damage To Emulate; Please check your own GCC Info Page.
It should be noted that although you use -traditional to change the characteristics of the language, its effect is only limited to the range that GCC can accept. For example, -traditional opens -fwritable-strings so that string constants move to data memory space (from the program code memory space, this place is not written). This will make the program code increase in memory space.
Front processor symbol Function prototype declaration
The most common problem is, such as well known, there are many common functions in Linux, defined into a macro in the header file. At this time, if there is a similar function prototype declaration, the front processor will refuse Performing the pre-work of grammar analysis. Common ATOI () and atol ().
Sprintf ()
On most UNIX systems, Sprintf (String, FMT, ...) is transmitted back the String indicator, however, Linux (ANSI) is transmitted back to the number of characters in String. Perform When transplanted, especially for Sunos, there is a warliness.
FCNTL and related functions; FD_ * The definition of the family is in the end?
Just in
In general, the Manual Page of the function will list the required header files in the Synopsis section.
Select () timing --- the program is executed - the state of waiting
A long time ago, the timing parameters of select () only readily read. Even in recent recently, Manual Pages still have the following warning:
SELECT () should be the time left after the start of the original timing, by correcting the value of the time (if any). Future versions may make this feature. Therefore, as far as it is, if you want to call Select (), the timing indicator will not be corrected, but a very unwise thing!
In the future, it is in front of us! At least, you can absolutely see here. The function select () is transmitted back, and it is the time value after deducting the data that has not arrived. If there is no data transfer at the end of the timing, the timing quotes will be set to 0; if there is any select (), the same timing Structure is called, then SELECT () will end immediately.
To correct this problem, just put the timing value in the timer in the timer, as long as you call Select (), there is no problem. Put the following program code,
Struct TimeVal Timeout; Timeout.tv_sec = 1; timeout.tv_usec = 0;
While (some_condition)
SELECT (N, Readfds, Writefds, ExcePTFDS, & Timeout);
Change to,
Struct TimeVal Timeout;
WHILE (some_condition) {
TIMEOUT.TV_SEC = 1; timeout.tv_usec = 0;
SELECT (N, Readfds, Writefds, ExcePTFDS, & Timeout);
}
This problem, is quite famous in some versions of Mosaic, as long as the Waiting, Mosaic is hanging there. Mosaic's screen, is there a round, the earth animation that will rotate. The ball is getting faster, and it means that the amount of time transmitted from the network is slower!
System call for interruption
feature:
When a program is aborted in Ctrl-z, then the case where the CTRL-C interrupt signal can be generated, if other can generate the CTRL-C interrupt signal, if the end of the subroutine, the system will complain, "Interrupted System Call" or "Write : unknown error, or a message like this.
question:
POSIX's system checks the number of times, more than one old version of UNIX. If it is Linux, Signal Handlers may be executed.
Non-synchronous (Turning Action of Timer) System call value during the following system calls: select (), pause (), connect (), accept (), read () on Terminals, Sockets, Pipes OR Files In / Proc, Write () on Terminals, Sockets, Pipes or The Line Printer, Open () ON FIFOS, PTYS or Serial Lines, IOCTL () ON TERMINALS, FCNTL () With Command f_setlkw, Wait4 (), syslog () , Any TCP OR NFS Operations.
For other operating systems, you need to call these systems: Creat (), Close (), getmsg (), PUTMSG (), MSGRCV (), msgsnd (), RECV (), Send () , Wait (), Waitpid (), WAIT3 (), TCDRAIN (), SIGPAUSE (), SEMOP () to this list.
During the system call, if there is a signal (the program itself should be prepared to be Handler's response), the handler will be called. When Handler transfer control back to system call, it detects that it has generated interrupt, and the return value will be set to -1, and Errno is set to Eintr. The program did not expect this kind of thing, so I hang.
There are two modified methods to choose:
(1) Signal Handler installed for each you must add SA_RESTART in the flag of SigAction. For example, put the following procedures,
Signal (SIG_NR, My_SIGNAL_HANDLER);
Change to,
Signal (SIG_NR, My_SIGNAL_HANDLER);
{struct sigaction sa;
SigAction (SIG_NR, SIGACTION *) 0, & SA;
#ifdef sa_restart
Sa.sa_flags | = sa_restart; #ENDIF
#ifdef sa_interrupt
Sa.sa_flags & = ~ sa_interrupt;
#ENDIF
SigAction (SIG_NR, & SA, (Struct SigAction *) 0);
}
It should be noted that when this change is largely applied to the system call, read (), write (), ioctl (), select (), pause () and connect (), you still have to check Eintr . As follows:
(2) You have to check EINTR very clearly:
There are two examples for READ () and IOCTL ().
Original program fragment, use read ():
Int result;
While (len> 0) {
Result = read (FD, Buffer, Len);
IF (Result <0) BREAK;
Buffer = Result; LEN - = Result;
}
changed to,
Int result;
While (len> 0) {
Result = read (FD, Buffer, Len);
IF (Result <0) {if (errno! = Eintr) Break;}
Else {Buffer = Result; LEN - = Result;
}
Original program fragment, use ioctl ():
Int result;
Result = IOCTL (FD, CMD, ADDR);
changed to,
Int result;
Do {result = ioctl (fd, cmd, addr);
While ((Result == -1) && (errno == eintr));
Note that some versions of BSD UNIX, their own behavior is to re-execute system calls. To let the system call to interrupt, you have to use the SV_Interrupt or Sa_Interrupt flag.
String that can be written
GCC has an optimistic idea for its USERS, I believe that when they intend to make a string as a constant --- then it is really only a string constant. Therefore, such a string constant will store in the memory section of the program code. This area can be on the image of the disk, avoiding the SWAP memory space, and anything that is written will cause a paging error (Segmentation Fault). This is a feature!
For older programs, this may have a problem. For example, call mkTemp (), the quotes passing the number (arguments) is a string constant. MkTemp () will try to rewrite its quotes in * appropriate position *.
The correction method is not more than (a) compiling with -fwritable-strings, forcing GCC to place this constant in data memory space; or (b) rewrite the part of the violation, configure a word that is not constant Strings, before calling, first copying the data in strcpy ().
Why call EXECL () will fail?
That's because you call the way. The first quoter of Execl is the program name you want to execute. The second with the continued quotes becomes the Argv array of programs you call. Remember: Traditionally, Argv [0] is only a set value only when the program does not have a quoter execution. So Luo, you should write this:
Execl ("/ bin / ls", "ls", null;
Not only,
Execl ("/ bin / ls", null; executing the program without any quota, can be interpreted as an invitation letter to print this program's dynamic library independent features. At least, A.out is like this. For ELF. It's not the case.
(If you want to know the information of this library, there are some simpler interfaces available; refer to dynamic loading that chapter, or LDD's Manual Page.)
5. Debugging and supervision
5.1 Prevention of weight (LINT)
Lint does not have a wide range of purposes for Linux, mainly because most people can satisfy the warning messages provided by GCC. It is possible to -wall parameters --- This parameter is used to request GCC to show all warning messages; But probably has more mnemonic value if weght of as the string you bang your head against.
There is a practical Public Domain LINT on the network, located in ftp://larch.lcs.mit.edu/pub/larch/lclint. I don't know how good this station is.
5.2 debugging
How do I do to put the debug information in a program?
You need to add -G's parameters to compile and link programs, and you cannot use the -FOMIT-FRAME-POINTER parameter. In fact, you don't need to recompile all the programs, just recompile the current you are debugging.
As far as A.out's configuration, the shared library is compiled with -fomit-frame-pointer. At this time, GDB has become unilaterable. The option to be given when connecting to the -g, should impose the meaning of static linkage; this is why you want to add -G.
If the connector is connected, tell you that you can't find libg.a, that is, under the / usr / lib / directory, less libg.a. Libg.a is a special debugging library for C language. Libg.a is generally provided within LIBC's kits; otherwise (the new version is like this), you may need to set it yourself by Libc's source code, but actually you should don't need it. No matter what purpose, most cases, just connect libg.a to /usr/lib/libc.a, you can get enough information.
Then, can you take the debug information?
Many GNU software will set -g option when compiling, which will cause excessive problems (usually static links). In fact, this is not a very hot idea.
If the program itself has autoconf, a configure script file is generated, usually you can use ./configure cflags = or ./configure cflags = -O2 to turn off debug information. Otherwise, you have to check to check Makefile. Of course, if you use the ELF, the program will link in a dynamic manner, whether there is a -g setting; therefore, you can take the -g in normal heart.
Practical software
It is understood that most people are commissioned with GDB. You can get the original program from GNU Archive Sites; or to TSX-11 take executive files. XXGDB is a debugger of an X interface, which is based on GDB (that is, you have to install GDB first, you can add XXGDB again). The source code of XXGDB can be found in ftp://ftp.x.org/contrib/xxgdb-1.08.tar.gz.
In addition, the UPS debugger has been transplanted by Rick Sladkey. UPS can live very well under X, unlike XXGDB - only the X front interface of the GDB (X Front end). This debug program has a lot of excellent features, and if you take time to remove a tattered procedure, I suggest you consider the XXGDB. The source code for prior compiled Linux version and revision can be found in ftp://sunsite.unc.edu/pub/linux/devel/debuggers/. The initial original procedure is placed in ftp://ftp.x.org/contrib/ups-2.45.2.tar.z. You may find another tool Strace for debugging, is also quite useful. It can display system calls generated by the program, but also have other numerous complicated features, like if you have no source code, Strace can help you find out that there are "path-names) compiled Inside; ExacerBating Race Conditions In Programs That You Suspect Contain; The latest version (currently 3.0.8) can find ftp://ftp.std.com/pub/JRS/.
Background program (resident program)
Early typical resident programs (DAEMON Programs) are executing fork () and then terminate the parent. This way makes the debugging time to decrease.
Understanding this easiest way is to set a breakpoint for fork (). When the program is stopped, forced fork () to pass back 0.
(GDB) List
1 #include
2
3 main ()
4 {
5 IF (fork () == 0) Printf ("Child / N");
6 Else Printf ("PARENT / N");
7}
(GDB) BREAK FORK
BreakPoint 1 AT 0x80003B8
(GDB) RUN
Starting program: /Home ,/dan/src/hello/./fork
BreakPoint 1 AT 0x400177C4
Breakpoint 1, 0x400177c4 in fork ()
(GDB) RETURN 0
Make SELECTED Stack Frame RETURN NOW? (Y OR N) Y
# 0 0x80004a8 in main ()
AT fork.c: 5
5 IF (fork () == 0) Printf ("Child / N");
(GDB) Next
Single Stepping UnTil EXIT from Function Fork,
Which Has No Line Number Information.
Child
7}
Core file
When Linux is turned on, it is usually configured to set it to not produce a core file. If you like them so much, you can use the shell's buildin command to re-take effect: as a C-shell compatible shell (such as tcsh), it will be the following:
% LIMIT CORE Unlimited
And similar to Bourne Shell (SH, Bash, ZSH, PDKSH) uses the following syntax:
$ ulimit -c unlimited
If you want to have a multi-artistic core file name (for example, if you're ", you can do a little smaller for your core programs Small fidelity. Look for FS / BINFMT_AOUT.C and FS / BINFMT_ELF.C file (in newer kernels, you'll ": memcpy (Corefile," Core. ", 5);
#if 0
Memcpy (Corefile 5, Current-> Comm, Sizeof (Current-> Comm));
#ELSE
Corefile [4] = '/ 0';
#ENDIF
Change 0 to 1.
5.3 supervision
Profiling is a method for checking those parts of a program to be most frequently called or executed. This is a quite good way for the optimization of the program and how to find when it is a waste. You must compile -P to the destination file of Timing Information, and if you want to make the output file meaning, you will need GPROF (command from the Binutils suite). See GPROF's Manual Page can be seen in detail.
6.
Due to the difference in format between the static and shared library, the difference and the verb * LINK * Excessive use is in the meaning of compilation, * and * When compiling good programs, what happens * These two things Head, this chapter has become more complicated. (And, Actually, The Overloading of the word `load 'in a comparable but oppositive sense) However, the complexity is the same, so you don't have to worry too much.
In order to slightly reduce the readers' confusion, we call the event that happened during the execution period * Dynamically loaded *, this topic will talk in the next chapter. You will also see that I will describe the dynamic load in other places * dynamic linkage *, but will not be in this chapter. In other words, this chapter talks, all refers to the connection after the completion of the compilation.
6.1 Sharing Library VS Static Library
The last step of establishing the program is a link; that is, all scattered applets are combined to see if it is missing. Obviously, there are many things that many programs will be doing - for example, open files, then all the small programs related to the open file will provide the relevant files of the storage library to your program. On the general Linux system, these small programs can be found at / lib and / usr / lib / directory.
When you use a static library, the link will find the module required by the program, and then actually copy them into the executable. However, this is not the case for the shared library. The shared library will leave a mark within the execution file, indicating * When the program is executed, the library must first be loaded. Obviously, the shared library is trying to make the executive smaller, equivalent to using fewer memory and disk space. Linux's internal behavior is a linking sharing program, as long as Linux can find these shared libraries, there is no problem; otherwise, Linux will be static. If you want to share the library, check if these libraries (* .sa for a.out, * .so for ELF) live in places they should be, and is readable.
On Linux, the static library has a name similar to libName.a; and the shared library is called libName.SO.x.y.z, which is the style of the version serial number. The shared library usually has a connection symbol to point to the static library (very important) and the associated .sa file. Standard libraries will include both shared and static libraries.
You can use LDD Dynamic Dependencies to find which shared libraries that require a prop program.
$ LDD / USR / BIN / LYNX
Libncurses.so.1 => /usr/lib/libncurs.so.1.9.6
Libc.so.5 => /lib/libc.so.2.18
This is to say on my system, WWW browser * Lynx * relies on libc.so.5 (the c library) and libNCursees.so.1 (control of the terminal screen). If a propulus lacks independence, LDD will say 'staticly linked' or 'staticly linked (ELF)'.
6.2 Ultimate Trial (Which library is "sin ()? ')
NM library names should list all symbols referred to in this library name. This instruction can be applied to static and shared libraries. Suppose you want to know where tcgetattr () is defined: You can do this,
$ nm libncurses.so.1 | grep tcget
U tcgetattr
* U * pointed out * undefined * --- That is to say, the NCURSES library is useful to Tegetattr (), but does not define it. You can also do this,
$ nm libc.so.5 | GREP TCGET
00010FE8 T __TCGETATTR
00010 W Tcgetattr
00068718 T tcgetpgrp
* W * Description * Weak *, which means that although the symbol has been defined, but can be replaced by another definition in different libraries. The simplest * normal * definition (like tcgetpgrp) is indicated by * t *:
The problem talked about the title, the simplest answer is libm. (SO | a). All defined functions in
6.3 x file?
LD: Output File Requires Shared Library `Libfoo.so.1`
LD is different from the strategy of searching for documents, which is different depending on the difference in the version, but the only one you can reasonably assume that it is / usr / lib. If you want the library that it's it, it is also included in the search ranks, then you must tell the GCC or LD with the -l option.
If you find a little effect, just hurry to see that the file is still lying in place. For A.out, the -LFOO parameters are connected, which will drive LD to look for libfoo.sa; if there is no success, it will be replaced with Libfoo.a (static). For ELF, LD will look for libfoo.so first, then Libfoo.a. Libfoo.so is usually a link symbol, coupled to libfoo.so.x.
6.4 Establish your own library
Control version
Like any other program, the library also has a problem that the incomplete BUGS is present. They may also produce some new features, change the effects of the currently existing modules, or remove the old removal. This may be a big problem for the programs that are using their programs. What should I do if one is executed according to the old characteristics? Therefore, we introduced the concept of the library version number. We use the library * secondary * and * main * change slots, and regulate * times * change is not allowed to use the old program of this library to interrupt. You can distinguish its version from the file name of the library (actually, strictly, for ELF is just a big lie; continue to read, you can understand why): libfoo.so. 1.2 The main version is 1, the secondary version is 2. The secondary version of the number may be true, or there may be no all --- libc uses the concept of * correction at * correction at this point, and sets a library name like libc.so.2.18. The secondary version of the number is placed in some letters, bottom lines, or any ASCII characters that can be printed, is also very reasonable.
One of the most important differences in ELF and A.out format is to set up the shared library; let's see ELF first because it is relatively simple.
ELF? What is it in the end?
ELF (Executable and Linking Format) was initially developed by USL (UNIX System Laboratories), which is currently available on Solaris and System V Release 4. Since the ELF has increased flexibility far exceeding the A.out format used in Linux, the developers of the GCC and C library decided to change the binary format for the linux standard in 1995.
How come again?
This section is from '/news-archives/comp.sys.sun.misc' files.
ELF ("Executable Linking Format") is a new modified destination format introduced by SVR4. ELF has a lot of functions compared to COFF. In terms of ELF, it * is * can be extended by the user. The ELF will depend on a sections such as a serial combination; and this serial can be any length (rather than an array of fixed sizes). These sectors are different from Coff, and they do not need to be fixed in some places, nor do they need to be arranged in some order. If the user wants to capture new data, you can join the new sector to the destination file. ELF also has a stronger and powerful debug Form, called DWARF (Debugging with Attribute Record Format) □ Linux is not fully supported. A link serial in DWARF DIES (Debugging Information Entries) forms a .debug sector in the ELF. Each of the DWARF DIES is not a collection of small and fixed-size information records, but a serial, complicated attributes, and the program's data is written in a scope restricted tree data structure. come out. The large amount of information that DIES can capture is Coff. Debug sector cannot expect its top. (Like a inheritance map of C .)
The ELF file is from SVR4 (Solaris 2.0?) ELF Access Library (ELF Access Library). This library provides a simple and fast interface to ELF. One of the most important grace of using the ELF access library is that you no longer need to look at the QUA of an ELF file. For UNIX files, it is accessed by ELF *; after calling ELF_Open (), from this time, you only need to call ELF_FOOBAR () to handle some part of the file, do not need to put The file actually made a mess on the image on the disk. The advantages and disadvantages of ELF and the various pains required for upgrading to the ELF level have been in Elf-Howto, and I am not intended to be pulsed here. Elf Howto should have the same topic with this document.
ELF shared library
If you want libfoo.so a shared library, the basic steps are like this:
$ gcc-fpic -c * .c * .c
$ gcc -shared -wl, -soname, libfoo.so.1 -o libfoo.so.0 * .o
$ ln -s lobfoo.so.1.0 libfoo.so.1
$ ln -s libfoo.so.1 libfoo.so
$ Ld_library_path = `pwd`: $ ld_library_path; export ld_library_path
This generates a shared library named libfoo.so.1.0, as well as the appropriate link to the LD (libfoo.so), which makes the dynamic loader to find it (libfoo.so.ly). For testing, we will add the current directory to LD_Library_Path.
When you arrive in the subscription system, don't forget to move it below the directory of / usr / local / lib, and reset the correct link path. Libfoo.so.1 and Libfoo.so.1.0 links are constantly updated by LDConfig, and LDConfig will execute during the boot process. Libfoo.so's link must be updated manually. If you upgrade all the components of the library (such as header, etc.), always hold a meticulous attitude, then the easiest way is to let Libfoo.so -> libfoo.so.1; this, ldconfig It will keep your latest link at the same time. If you don't do this, the stuff you set up will appear in a few days later. When I arrive, I don't say that I didn't remind you!
$ SU
# cp libfoo.so.1.0 / usr / local / lib
# / sbin / ldconfig
# (CD / USR / LOCAL / LIB; LN -S LIBFOO.SO.1 LIBFOO.SO)
Version number, Soname and symbol connection
Each library has a Soname. When the link finds that it is searching in the library, there is such a name, the link will clamp the Soname into the binary file in the connection, not the actual file name it is working. During the execution of the program, the dynamic loader searches for files with file names such as Soname instead of the file name of the library. Therefore, a library named libfoo.so can have a libbar.so's Soname. And all the programs connected to libbar.so, when the program starts, it is Libbar.so.
This sounds seems to be a little meaning, but this is a key key for how the same library of several different versions is coexisting on a single system. LINUX library standard naming, such as libfoo.so.1.2, and give this library a libfoo.so.1 Soname. If this library is added to the directory of the standard library (E.G. / USR / LIB), LDConfig will establish a symbol link libfoo.so.1 -> libfoo.so.2.2, making its correct image can be found during execution. You also need to connect libfoo.so -> libfoo.so.1, so that LD can find the correct Soname during the connection. So Luo, when you correct the BUGS in the library, or add a new function to go in (any change that does not have an unfavorable impact on the existing program), you will rebuild this library, keep the original Soname, Then change the library file name. When you change the program library, you only need to increase the number in Soname --- In this example, the new version is libfoo.so. 2.0, and Soname becomes libfoo.so.2 . Then, turn the link of libfoo.so to a new version; here, the world will restore peace!
In fact, you don't need to be named after the library in this way, but this is indeed a good tradition. ELF gives you the elasticity named in the library, which will make people breathless; there is such a flexibility, and do not say you have to use it.
ELF summary: Assumment to find a convention via your wise observation: The main upgrade of the library will damage compatibility; the secondary upgrade may not be; then the following ways are connected, all everything will be Things.
GCC -Shared -wl, -soname, libfoo.so.major -o libfoo.so.major.minor
A.out --- Old Format □
The convenience of establishing a shared program library is one of the main reasons for upgrading to ELF. That is to say, A.out may still be useful. On the FTP station to grasp ftp :/tsx-11.mit.edu/pub/linux/packages/gcc/src/tools-2.17.tar.gz; After the decompression, you will find 20 pages of files can be slow. Read. I don't like the prejudice of my party, but from the above, there should be very clear, I can't smell my blood, I have never touched my own feet! :-)
Zmagic vs qmagic
QMAGIC is an executable format similar to the old format A.out (also known as zmagic), which makes the first pagination unable Map. When there is no mapping in the range of 0-4096, null dereference trapping can be allowed easier. The boundary effect generated is that your execution file is relatively small (about 1K).
Only the upcoming loop is supported ZMAGIC, half of the burying of the coffin has supported these two formats; the current version only supports QMAGIC. In fact, there is no much impact, it is because the current core format can be implemented.
* file * command should confirm that the program is not a QMAGIC format.
File configuration
A a.Out (DLL) shared library contains two real files with a link symbol. In terms of * foo * This file is used for the entire file as an example, these files will be libfoo.sa and libfoo.so.2.2; the link symbol will be libfoo.so.1, and will point to libfoo.so. 1.2. What is these for these?
When compiling, LD will look for libfoo.sa. This is the library's * stub * file. Moreover, there is an indicator of the data and pointing functions that connect the required exported during all execution. Dynamic loading programs will look for libfoo.so during execution. This is just a symbolic link, not a real file. Therefore, the library can be updated to a newer and revised version of the wrong version without damaging any applications that are using this library at this time. In the new version -, if libfoo.so.3.3 --- has been fully presented, LDConfig will connect to the new version with a very small operation, so that any original version of the old version will not feel unhappy. .
DLL library (I know this is unseafered - so puts a lawsuit with me!) Usually more than their static copy. They are in the form of * holes * to keep space for future expansion. This * hole * may not occupy any disk space. A simple CP call, or use the Makehole program, you can achieve this effect. Because their address is fixed in the same location, you can take them off after establishing the library. However, don't try to take off the ELF library.
`` libc-lite ''?
Libc-lite is a lightweight libc version. Can be used to store on disk sheets or end for most low micro UNIX tasks. It does not include program code, etc. Curses, DBM, Termcap, etc. If your /lib/libc.so.4 is a LIBC to connect to a Lite, it is recommended that you replace it with a complete version.
Connection: Common problems
Send it to me when you join you! I may not do anything, but as long as I have accumulated enough quantity, I will write them *.
You want to share, but the default is a static!
Check if you provide the connection to the LD correct, so that the LD can find each corresponding shared library, for ELF, this refers to a symbol link libfoo.so, connects to image; as far as a.out, it is Libfoo .sa file. Many people have upgraded Elf Binutils 2.5 to 2.6, which produced this problem - the earlier version of the search sharing creation library is more wisdom, so there is no settlement of all links. Later, in order to be compatible with other architectures, this kind of wisdom is being deleted, in addition, such * wisdom * is quite high, the problem is quite high, and the trouble caused by the problem is more than what it solves. So, it is also harmful; it is better to return!
DLL's tool program 'mkimage' can't find LibGCC?
Since libc.so.4.5.x, libgcc is no longer a shared format. Therefore, you must appear in * -lgcc * to `GCC -Print-libgc-file-name` replacement (complete back-quotes). Also, remove all / usr / lib / libgcc * files. This is important.
__Needs_shrlib_libc_4 Multiply Defined Messages
Another result caused by the same problem.
`` Assertion Failure '' Message When Rebuilding A DLL?
This mysterious message is most likely to be, in the original Jump.vars file, because the remaining space is too small, so that one of the Jump Table Slots is full. You can execute tools □ The 'getSize' command provided by 2.17.tar.gz suite, and sets out all suspects. Possible solution is to release the main version number of this library, force it to return to an incompatible era. LD: Output File Needs Shared Library Libc.so.4
Usually this is happening when you link the library is not a libc (such as a X library), but also use -G's parameters in the command, but does not use -static, the error message issued.
The. SA Stubs usually have an undefined symbol _needs_shrlib_libc_4; this can be solved by libc.sa stub, however, when compiling with -g, it will connect to libg.a or libc.a. End; so this symbol has not been resolved, and it will cause the above error message.
In short, don't forget to add -static, otherwise don't connect with -static. Typically, when compiling each independent file with -g, the debug information obtained can be sufficient, and it can not be required.
7. Dynamic loading
This chapter is a short thing before it; when I brush Elf Howto, it is the time when I reappeared.
7.1 Basic Concept
Linux has a shared library. If you have been reading the previous chapter before, you will immediately feel dizzy now. There are some practices that are completed during the connection, and must be delayed to the load period.
7.2 Error message
Send me a mistake! I won't do anything, but I can write them **
Can't load library: /lib/libxxx.so, Incompatible Version
(A. Out "This means that you don't have the correct version of the XXX library. Don't think that you will get a connection to your current version. If you are lucky, you will only cause your program paging error. Going to the new version. Alex is similar to what is like this:
ftp: can't loading library 'libreadline.so.s2'
WARNING USING INCOMPATIBLE LIBRARY VERSION XXX
(A. Out Only) The secondary version of your library is compared to this program to compile it. The program is still executable. Just possible! I think, there should be no harm to the promotion!
7.3 Controlling the operation of the dynamic loader
There is a set of environmental variables to make the dynamic loader react. Most of the environment variables are more than the use of LDD more than the general user. Moreover, it can be easily set to be implemented by the LDD to cooperate with various parameters. These variables include,
LD_BIND_NOW --- Normally, the function will not let the program be found before calling. Setting this flag will make the library one load, and all the findings will occur while the starting time is slow. When you want to test the program, you have no problem with all the links, this banner is very useful. LD_PRELOAD can set a file that has the ability to overwrite * function definitions. For example, if you want to test the memory allocation, but also want to replace * malloc *, then you can write it ready for the replacement subprogram, and compile it into mallolc., Then:
$ Ld_preeload = malloc.o; export ld_preeload $ some_test_program
LD_elf_preeload is very similar to LD_AOUT_PRELOAD, but only is applicable to the correct binary format. If you set LD_Something_PreLoad and LD_PRELOAD, the more clear one will be used. LD_LIBRARY_PATH is a series of semicolon-isolated directory names to search for sharing program libraries. For LD, there is no impact; this only has an impact during execution. In addition, this is invalid for the program of executing SETUID and SETGID. And the two flags of LD_AOUT_LIBRARY_PATH and LD_AOUT_LIBRARY_PATH can be directed to different search paths according to each of other two-in-line types. Under normal operation, you should not use ld_library_path; add the directory you need to search to /etc/ld.so.conf/; then re-execute the LDConfig. LD_NOWARN is only available for A.out. Once this is set (LD_NOWARN = true; export ld_nowarn), it will tell the load that a warning message must be handled in Fatal-Warnings (like a secondary version is incompatible, etc.). LD_WARN is only available for ELF. When this is set, it will convert "CAN * T Find Library" that is usually a fatal message to a warning message. For normal operations, this is not much used, but it is important to LDD. LD_TRACE_LOADED_OBJECTS is only available for ELF. And will make the program to be performed by LDD:
$ Ld_trace_loaded_Objects = true / usr / bin / lynx
Libncurses.so.1 => /usr/lib/libncurs.so.1.9.6
Libc.so.5 => /lib/libc.so.2.18
7.4 By dynamic loading
If you are familiar with the dynamic loaded work supported by Solaris 2.x, you will find that Linux is close to it at this point. This part has a broad discussion with the Manual Page of DLOPEN (3) in the H. J. Lu's ELF program design file. Here is a nice simple example: linkage with the -ldl.
#include
#include
Main ()
{
Void * libc;
Void (* printf_call) ();
IF (libc = DLOPEN ("/ lib / libc.so.5", rtLD_LAZY))
{
Printf_call = DLSYM (libc, "printf");
(* printf_call) ("Hello, World / N");
}
}