内に含ま
その他のドキュメント
サポート リソース
| PDF 文書ファイルをダウンロードする
Compilers, Linkers, and Debuggers
15
- This chapter discusses the changes to compilers, linkers, and debuggers. It contains the following sections:
-
Compilers
- The single most significant change for developers migrating from SunOS release 4.x to the Solaris 2.5 operating environment is the unbundling of the C compiler. One of the factors that allowed the compiler to be unbundled is the dynamic kernel. The compiler is no longer required to reconfigure the kernel as devices are now automatically loaded by the kernel as needed.
- An ANSI C compiler is available with the unbundled SPARCworks(TM) product. This compiler produces executables in executable and linking format (ELF), the native object format of Solaris 2.5 executables. lint and the lint libraries are also unbundled.
-
Source Compatibility Guide describes the differences between the C language as implemented by the SunOS release 4.x C compiler (Sun C) and as described by the ANSI Programming Language C document (ANSI C). These differences should be addressed when porting source written for the Sun C compiler to an ANSI C conforming compiler.
Compiler Option Differences
-
Table 15-1 compares the SunOS release 4.x Sun C and ANSI C compilers to the Solaris 2.5 SPARCompiler C++ 3.0.1. It is provided for your information, and is not intended to describe the range of operations available in default Solaris 2.5 software.
-
Note - Table 15-1 presents information based on the publicly available copies of the American National Standard for Information Systems - Programming Language XX3.159-1989, approved December 14, 1989.
- Please note the following:
-
- A "yes" in any column indicates that the option is supported by that compiler.
- If the option has changed, the new option is listed.
- A "no" in any column if the option is not supported by that driver
- A "+" in the SPARCompiler C++ 3.0.1 Solaris 2.5 column indicates an option required by SVID specifications.
-
Table 15-1
| Option or Flag | Sun C (SunOS release 4.x) | ANSI C (SunOS release 4.x) | SPARCompiler C++ 3.0.1 (Solaris 2.5) | Description |
| -A symbol | No | Yes | Yes | cpp predicate assertion |
| -a | Yes | Yes | -xa | Counts # basic block executions |
| -assertx | Yes | Yes | -z | Specifies link time assertion |
| -align | Yes | Yes | No | Page aligns (ld) |
| -BX | Yes | Yes | -d[y|n] | Specifies binding type (only for libraries in SunOS release 5.5) |
| -bnzero | Yes | Yes | No | Generates nonzero AR |
| -C | Yes | Yes | +Yes | cpp comments left in |
| -c | Yes | Yes | +Yes | Produces .o file |
| -cg87 | Yes | Yes | No | Sets fp option to -cg87 |
| -cg89 | Yes | Yes | No | Sets fp option to -cg89 |
-
Table 15-1 (Continued)
| Option or Flag | Sun C (SunOS release 4.x) | ANSI C (SunOS release 4.x) | SPARCompiler C++ 3.0.1 (Solaris 2.5) | Description |
| -dryrun | Yes | Yes | -# | Shows commands constructed by driver |
| -Dx | Yes | Yes | +Yes | Defines cpp symbol x |
| -d | Yes | Yes | No | Forces definition of common (ld) |
| -dalign | Yes | Yes | Yes | Assumes doubles are doubleword aligned |
| -dl | Yes | Yes | No | Generates long data segment refs |
| -d[y|n] | -BX | -BX | Yes | Dynamics linking [yes|no] |
| -E | Yes | Yes | +Yes | Runs source through cpp |
| -e | No | No | Yes | Entry point for ld |
| -F | -O* | -O* | +No | Optimization directives |
| -f | No | No | No | Floating-point support |
| -fast | Yes | Yes | Yes | Options for best performance |
| -fsingle | Yes | No | No | Floats are single precision |
| -fsingle2 | Yes | No | No | Passes float as float not double |
| -fnonstd | Yes | Yes | Yes | Non-standard float option |
| -fstore | Yes | No | No | Forces writes on store |
| -G | No | No | Yes | Creates shared library, not available with the -dn option |
| -g | Yes | Yes | +Yes | Generates info for dbx |
| -go | Yes | No | No | Generates info for adb |
| -H | Yes | Yes | Yes | Prints paths of included files |
| -h name | No | No | Yes | Uses name as internal identifier; soname passed to linker |
| -help | Yes | Yes | -flags | Lists options |
| -Ix | Yes | Yes | +Yes | Adds x to include path |
| -J | sun3 | No | No | Generates long offset for switch|case |
-
Table 15-1 (Continued)
| Option or Flag | Sun C (SunOS release 4.x) | ANSI C (SunOS release 4.x) | SPARCompiler C++ 3.0.1 (Solaris 2.5) | Description |
| -KPIC | -PIC | -PIC | Yes | Position independent code |
| -Kpic | -pic | -pic | Yes | PIC with short offsets |
| -Kminabi | No | No | Yes | ABI compliant code |
| -libmil | Yes | Yes | -xlibmil | Passes libm.il as part of -fast |
| -lx | Yes | Yes | Yes | Reads object library (for ld) |
| -Lx | Yes | Yes | Yes | Adds x to ld library path |
| -M | Yes | Yes | No | Collects dependencies |
| -M mapfile | Yes | No | Yes | Passes mapfile to the linker |
| -misalign | Yes | Yes | Yes | Handles misaligned Sun-4 data |
| -N | Yes | No | No | Does not make shared |
| -n | Yes | No | No | Makes shared |
| -native | Yes | Yes | No | Uses appropriate -cg option |
| -nolibmil | Yes | Yes | -xnolibmil | Doesn't pass libm.il with -fast |
| -noc2 | Yes | Yes | No | Doesn't do peephole optimization |
| -o file | Yes | Yes | +Yes | Sets name of output file |
| -O[1,2,3,4] | Yes | Yes | -x0[1,2,3,4] | Generates optimized code |
| -O | Yes | Yes | +Yes | Generates optimized code |
| -P | Yes | Yes | +Yes | Runs source through cpp, output to .i |
| -PIC | Yes | No | -KPIC | Generates pic code with long offset |
| -p | Yes | Yes | +Yes | Collects data for prof |
| -pic | Yes | Yes | -Kpic | pic code with short offset |
| -pipe | Yes | No | No | Uses pipes instead of temp files |
| -pg | Yes | Yes | -xpg | Collects data for gprof |
| -purecross | Yes | No | No | Doesn't have slash in VROOT |
| -Qdir x | Yes | Yes | -Y* | Looks for compiler passes in x |
-
Table 15-1 (Continued)
| Option or Flag | Sun C (SunOS release 4.x) | ANSI C (SunOS release 4.x) | SPARCompiler C++ 3.0.1 (Solaris 2.5) | Description |
| -Qpath x | Yes | Yes | -Y* | Same as -Qdir |
| -Qn | No | No | Yes | Doesn't add version stamp info |
| -Qy | No | No | Yes | Adds version stamp info |
| -qdir x | Yes | Yes | -Y* | Looks for compiler passes in x |
| -qp | -p | -p | +Yes | Collects data for prof |
| -ql | No | No | +Yes | Collects data for lprof |
| -qpath x | Yes | Yes | -Y* | Same as -Qdir |
| -Qoption cpp x | Yes | Yes | No | Passes option x on to program cpp |
| -Qoption iropt x | Yes | Yes | No | Passes option x on to program iropt |
| -Qoption cg x | Yes | Yes | No | Passes option x on to program cg |
| -Qoption inline x | Yes | Yes | No | Passes option x on to program inline |
| -Qoption as x | Yes | Yes | No | Passes option x on to program as |
| -Qoption asS x | Yes | Yes | No | Passes option x on to program asS |
| -Qoption ld x | Yes | Yes | No | Passes option x on to program ld |
| -qoption cpp x | Yes | Yes | No | Passes option x on to program cpp |
| -qoption ccom x | Yes | Yes | No | Passes option x on to program ccom |
| -qoption lint1 x | Yes | Yes | No | Passes option x on to program lint1 |
| -qoption iropt x | Yes | Yes | No | Passes option x on to program iropt |
| -qoption cg x | Yes | Yes | No | Passes option x on to program cg |
| -qoption inline x | Yes | Yes | No | Passes option x on to program inline |
| -qoption cat x | Yes | Yes | No | Passes option x on to program cat |
| -qoption c2 x | Yes | Yes | No | Passes option x on to program c2 |
| -qoption as x | Yes | Yes | No | Passes option x on to program as |
-
Table 15-1 (Continued)
| Option or Flag | Sun C (SunOS release 4.x) | ANSI C (SunOS release 4.x) | SPARCompiler C++ 3.0.1 (Solaris 2.5) | Description |
| -qoption asS x | Yes | Yes | No | Passes option x on to program asS |
| -qoption ld x | Yes | Yes | No | Passes option x on to program ld |
| -Qproduce .o | Yes | Yes | No | Produces type .o file (Object file) |
| -Qproduce .s | Yes | Yes | No | Produces type .s file (Assembler source) |
| -Qproduce .c | Yes | Yes | No | Produces type .c file (C source) |
| -Qproduce .i | Yes | Yes | No | Produces type .i file (C source after cpp) |
| -qproduce .o | Yes | Yes | No | Produces type .o file (Object file) |
| -qproduce .s | Yes | Yes | No | Produces type .s file (Assembler source) |
| -qproduce .c | Yes | Yes | No | Produces type .c file (C source) |
| -qproduce .i | Yes | Yes | No | Produces type .i file (C source after cpp) |
| -r | Yes | Yes | Yes | Makes relocatable; pass to linker |
| -R | Yes | Yes | No | Merges data into text segment |
| -R | No | No | Yes | Specifies search directories for the run-time linker |
| -S | Yes | Yes | +Yes | Produces .s file only |
| -s | Yes | Yes | Yes | Strips (4.1); pass to linker |
| -sb | Yes | Yes | -xsb | Collects information for code browser |
| -strconst | No | Yes | -xstrconst | Places string literals in read-only text segment |
| -sun2 | Yes | No | No | Generates code for a Sun-2 system |
| -sun3x | Yes | No | No | Generates code for a Sun-3ax system |
| -sun386 | Yes | No | No | Generates code for a Sun386i |
| -sun3 | Yes | No | No | Generates code for a Sun-3 system |
-
Table 15-1 (Continued)
| Option or Flag | Sun C (SunOS release 4.x) | ANSI C (SunOS release 4.x) | SPARCompiler C++ 3.0.1 (Solaris 2.5) | Description |
| -sun4c | Yes | No | No | Generates code for a Sun-4c system |
| -sun4 | Yes | No | No | Generates code for a Sun-4 system |
| -target x | Yes | No | No | Sets target architecture to x |
| -temp=dir | Yes | Yes | No | Set directory for temps to dir |
| -time | Yes | Yes | No | Reports the execution times |
| -u | Yes | Yes | Yes | Enters symbol arg as undef (ld) |
| -Ux | Yes | Yes | +Yes | Undefines cpp symbol x |
| -v | Yes | Yes | -# | Verbose mode |
| -v | No | No | Yes | Strict semantic checking |
| -V | Yes | Yes | +Yes | Reports versions of programs |
| -W | No | No | +Yes | Arguments to other components |
| -w | Yes | Yes | Yes | Does not print warnings |
| -X[t,a,c,s] | No | Yes | Yes | Compatibility options |
| -Y | No | No | +Yes | Changes pathname to components |
| -yx | Yes | No | No | Traces symbol |
| -z | -assert | -assert | Yes | Turns on asserts in linker |
| -# | -v | -v | Yes | Verbose mode |
| EOF | No | No | Yes | File argument |
- The C compiler accepts the types of filename arguments shown in Table 15-2.
-
Table 15-2
| Suffix | File Type |
| .a | Object library |
| .il | In-line expansion file |
| .o | Object file |
| .so | Shared object |
-
Table 15-2 (Continued)
| Suffix | File Type |
| .s | Assembler source |
| .S | Assembler source for cpp |
| .c | C source |
| .i | C source after cpp |
- "file.X=.Y" will read the file "file.X" but treat it as if it had suffix "Y"
Linkers
- There are several changes to the link editor, ld(1), in this release. The most important change is its ability to handle the new ELF native file format.
-
Note - The recommended method for building libraries and executables is through the compiler driver rather than by invoking the linker directly. The compiler automatically supplies several files needed by the linker.
Link Editor Option Differences
- Some options have been renamed in the new linker, some have remained the same, and others are no longer needed. Table 15-3 compares the SunOS release 4.x ld command to the Solaris 2.5 ld command.
- The sections following Table 15-3 explain how certain linking tasks are affected by the option differences.
-
Table 15-3 ld
| SunOS release 4.x Option | Solaris 2.5 Replacement | Notes |
| -align datum | -M mapfile | Uses mapfiles and distinct sections |
| -assert definitions | default |
| -assert nodefinitions | -znodefs | Issues a fatal error instead of a warning |
| -assert nosymbolic | -zdefs | Issues a fatal error instead of a warning |
| -assert pure-text | -ztext | Issues a fatal error instead of a warning |
-
Table 15-3 ld(Continued)
| SunOS release 4.x Option | Solaris 2.5 Replacement | Notes |
| -A name | No replacement | dlopen(3X) and dlclose(3X) can approximate this behavior |
| -Bdynamic | -Bdynamic | Applies only to the inclusion of shared libraries; use -dy (the default) to build dynamically linked executables. See "Building Executables" on page 148. |
| -Bnosymbolic | -zdefs |
| -Bstatic | -dn & -Bstatic | Used with the -dn option to completely eliminate the dynamic linker, the -dn option must be specified; use -Bstatic in dynamic mode to include archive libraries. (Used as a toggle. See "Building Executables" on page 148.) |
| -Bsymbolic | -Bsymbolic | Also gets -assert nosymbolic with this option |
| -d -dc -dp | Default | Use -b option in SVR4 to turn off |
| -D hex | -M mapfile | mapfiles contain different mechanisms to accomplish desired effect |
| -e entry | -e entry |
| no -e | -G | Creates a shared object |
| -lx[.v] | -lx | Only major number versioning of shared libraries is currently supported |
| -Ldir | -Ldir | dir not recorded in executable; use -R option instead. |
| -M | -m |
| -n | Default | SVR4 executable format compresses disk image as -n |
| -N | No replacement |
| -o name | -o name |
| -p | Default | Can override with -M mapfile |
| -r | -r |
-
Table 15-3 ld(Continued)
| SunOS release 4.x Option | Solaris 2.5 Replacement | Notes |
| -S | No replacement |
|
| -s | -s |
|
| -t | no replacement |
|
| -T hex | -M mapfile | mapfiles contain different mechanisms to accomplish desired effect |
| -Tdata hex | -M mapfile | mapfiles contain different mechanisms to accomplish desired effect |
| -u name | -u name |
| -x | No replacement |
| -X | No replacement |
| -ysym | No replacement |
| -z | default | SVR4 executable format demand pages as -z |
Building Shared Libraries
- The procedure for building shared libraries has changed in the Solaris 2.5 operating environment. The -G option is now required to build a shared library. In SunOS release 4.x, the linker would infer that a shared library was being built by the absense of the -e option. As shared libraries may have entry points, this option can no longer be used.
Building Executables
- The -Bdynamic and -Bstatic options are still available, but their behavior is different. These options now refer to library inclusions; not to the executable binding. Executable binding is set exclusively with the new -dy and -dn options in the Solaris 2.5 software. The
-
-dy option is the default. It is
- required to create a dynamically linked executable. The -dn option is required to create a statically linked executable.
- The -Bdynamic and -Bstatic options apply only when using the -dy option. -Bdynamic tells the link editor to include shared libraries, while -Bstatic tells it to include archive libraries. These options act as a toggle governing subsequent -l arguments until the next -Bdynamic or -Bstatic option is encountered.
- The following examples show SunOS release 4.x and Solaris 2.5 commands that can be used to create similar executables.
-
sunos4.1% ld -Bstatic test.o -lx # uses libx.a and creates a static executable
sunos5.x% cc -dn test.o -lx # uses libx.a and creates a static executable
sunos4.1% ld -Bdynamic test.o -lx # uses libx.so and creates a dynamic
# executable
sunos5.x% cc test.o -lx # uses libx.so and creates a dynamic
# executable
sunos4.1% ld -Bdynamic test.o -Bstatic -lx # uses libx.a and creates a dynamic
# executable
sunos5.x% cc test.o -Bstatic -lx # uses libx.a and creates a dynamic
# executable
|
Specifying Library Search Paths
- In SunOS release 4.x, directories specified with the -L option were searched at link time and the information retained for use at execution time. This behavior is now divided between the -L and -R options. The -L option specifies the directories to search at link time; the new -R option tells the linker the search paths to be retained for use at run time. See "Search Path Rules," in the next section for more information.
- As with the -Bdynamic and -Bstatic options, the position of the -L option has significance; it applies only to the subsequent -l options.
Search Path Rules
- The dynamic linker and the run time linker determine their search paths through a different algorithm from that used by the SunOS release 4.x linker.
-
Table 15-4 through Table 15-6 compare the search paths for the dynamic linker and the run time linker for SunOS release 4.x and the Solaris 2.5 operating environment. Notice that in the latter, the search path for the link editor and the runtime linker are affected by the LD_LIBRARY_PATH setting.
-
Table 15-4
| Library Search Path |
| Link Editor | -L, LD_LIBRARY_PATH, /usr/lib, /usr/local/lib |
| Runtime Linker | LD_LIBRARY_PATH, -L, /usr/lib, /usr/local/lib |
-
Table 15-5 LD_LIBRARY_PATHdirlist1
| Library Search Path
LD_LIBRARY_PATH=dirlist1 |
| Link Editor | -L, dirlist1, /usr/ccs/lib, /usr/lib |
| Runtime Linker | dirlist1, -R, /usr/lib |
-
Table 15-6 LD_LIBRARY_PATHdirlist1dirlist2
| Library Search Path
LD_LIBRARY_PATH=dirlist1; dirlist2 |
| Link Editor | dirlist1,-L, dirlist2, /usr/ccs/lib, /usr/lib |
| Runtime Linker | dirlist1, dirlist2, -R, /usr/lib |
Version Numbering
- SunOS release 4.x supported both major and minor version numbers on shared libraries. The Solaris 2.5 operating environment supports only the major version number. For binary compatibility support, major and minor version
- numbers are recognized on SunOS release 4.x shared libraries. These libraries are required to retain the same major and minor version number they had in SunOS release 4.x.
-
Table 15-7 shows versions of SunOS release 4.x and Solaris 2.5 shared libraries.
-
Table 15-7
| SunOS release 4.x | Solaris 2.5 |
| libc.so.1.7 | libc.so.1 |
| libdl.so.1.0 | libdl.so.1 |
- In SunOS release 4.x system software, when the -l option was specified, the build environment linker searched for a library with both major and minor numbers. For example, if -ldl was specified, the library, libdl.so.1.0 was linked. In Solaris 2.5, even though major numbers are still supported, the default behavior of the link editor is to ignore version numbers. Using the previous example, the build environment link editor now searches for libdl.so and a symbolic link points to a specific version file.
- The recording of a dependency in a dynamic executable or shared object is, by default, the filename of the associated shared object as it is referenced by the link-editor. To provide a more consistent means of specifying dependencies, shared objects can record within themselves the filename by which they should be referenced at runtime.This is specified with the -h option when linking the library file.
- Symbolic links have been created for most libraries in this release. Build any new shared libraries with major numbers, then create a symbolic link to the version of the library that is used most often. .
Examples
- A new utility, dump(1) (See "Backing Up and Restoring Files" on page 101), makes it easier to debug object files or to check the static and dynamic linking. The dump -L option displays the information needed by the runtime linker that is contained in the executable. This information is contained in the dynamic section of an ELF file. The RPATH entry displays search paths specified by the -R option to ld.
- The following example:
-
- Builds a shared library, libx.so.1, using libx.o
- Creates a link from libx.so.1 to libx.so
- Shows dump output, including the SONAME field, which stores the information passed with the -h option.
-
examples% cc -G -o libx.so.1 -h libx.so.1 libx.o
examples% cp libx.so.1 /mylibs
examples% ln -s /mylibs/libx.so.1 /mylibs/libx.so
examples% dump -Lv libx.so.1
libx.so.1:
**** DYNAMIC SECTION INFORMATION ****
.dynamic :
[INDEX] Tag Value
[1] INIT 0x3b8
[2] FINI 0x3f4
[3] SONAME libx.so.1
[4] HASH 0x94
[5] STRTAB 0x33c
[6] SYMTAB 0x14c
[7] STRSZ 0x62
[8] SYMENT 0x10
[9] PLTGOT 0x10404
[10] PLTSZ 0xc
[11] PLTREL 0x7
[12] JMPREL 0x3ac
[13] RELA 0x3a0
[14] RELASZ 0x18
[15] RELAENT 0xc
|
- If a library needs other dynamic libraries, they should be specified along with an RPATH, as the next example shows.
- The next example compiles prog.c, dynamically linking libx.so (as built in the previous example), and specifies that the binary retain the current directory information for execution. This example shows the output of dump from the
- compiled program, prog.c. Here, the information stored in the SONAME field of the previous example is shown as NEEDED by prog. When prog is run, it will use libx.so.1, even if libx.so is linked to a different version.
-
examples% cc -o prog prog.c -L/mylibs -R/mylibs -lx
example% dump -Lv prog
prog:
**** DYNAMIC SECTION INFORMATION ****
.dynamic :
[INDEX] Tag Value
[1] NEEDED libx.so.1
[2] NEEDED libc.so.1
[3] INIT 0x1b1ac
[4] FINI 0x1b248
[5] RPATH /mylibs
[6] HASH 0x100e8
[7] STRTAB 0x17f90
[8] SYMTAB 0x12be0
[9] STRSZ 0x31e1
[10] SYMENT 0x10
[11] DEBUG 0x0
[12] PLTGOT 0x2b25c
[13] PLTSZ 0x30
[14] PLTREL 0x7
[15] JMPREL 0x1b180
[16] RELA 0x1b174
[17] RELASZ 0x3c
[18] RELAENT 0xc
|
Debuggers
- This section describes changes to debugging tools.
dbx and dbxtool
- These tools are no longer available with default system software. Enhanced versions of these tools are available as the SPARCworks Debugger, an unbundled product.
adb and kadb
- These tools are available in the Solaris 2.5 operating environment. They offer the same capabilities as the tools in SunOS release 4.x. kadb has been enhanced to recognize multiple processors. The processor ID is displayed in the kadb prompt. In the following examples, it is 0.
- To make kernel debugging under the Solaris 2.5 operating environment easier:
-
- Enable savecore (uncomment the savecore lines in the /etc/init.d/sysetup file)
- Boot under kadb (type $c when the system crashes)
- Use adb and crash
kadb Macros
- The following kadb macros are particularly useful with the new multithreaded kernel:
-
thread Displays the current thread. The current thread pointer is in SPARC global register g7.
-
-
threadlist Shows the stack traces of all the kernel threads in the system. This can be a long list.
-
-
-
mutex
Shows you the address of the owning thread, given a mutex. This example
uses the global unsafe driver mutex.
-
kadb[0]: unsafe_driver$<mutex
|
-
-
moddebug
-
kadb[0]: moddebug/W 0x80000000
|
- Allows you to watch module loading. See the end of <sys/modctl.h> for legal values for moddebug for debugging purposes only.
Debugging a Live Kernel
- Use the following command to debug a live kernel.
-
# adb -k /dev/ksyms /dev/mem
|
-
/dev/ksyms is a pseudo device that contains the complete name list of the running kernel.
truss Command
-
truss is a new utility, provided to trace system calls performed, signals received, and machine faults incurred. truss offers several significant improvements over the SunOS release 4.x trace(1) command: including the ability to follow forked processes and the ability to deal with multithreaded processes.
- The following example shows a summary of traced calls for the date command. With the -c option, truss does not display the trace line-by-line. Instead, it counts the system calls, signals, and faults, and displays a summary.
-
example% truss -c date
Fri Sep 18 14:31:30 PDT 1992
syscall seconds calls errors
_exit .00 1
read .00 7
write .00 1
open .03 12
close .00 12
time .00 1
brk .01 4
lseek .00 1
fstat .00 4
ioctl .00 1
execve .00 1
mmap .01 17
munmap .00 8
---- --- ---
sys totals: .05 70 0
usr time: .03
elapsed: .28
|
- See the truss(1) man page in man Pages(1): User Commands for complete details on all truss options.. In Solaris 2.5 there are a number of other new debugging tools which are based on proc(4) such as pmap(1).
|
|