This chapter discusses the changes to compilers, linkers, and debuggers.
The single most significant change for developers migrating from the SunOS release 4.x to the Solaris 2.6 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 unbundled Sun WorkShop(TM). This compiler produces executables in executable and linking format (ELF), the native object format of Solaris 2.6 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.
Table 15-1 compares the SunOS release 4.x Sun C and ANSI C compilers to the Solaris 2.6 Sun WorkShop(TM) C++ 4.2. It is provided for your information, and is not intended to describe the range of operations available in default Solaris 2.6 software.
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 means the option is not supported by that driver
A "+" in the Sun WorkShop(TM) C++ 4.2 Solaris 2.6 column indicates an option required by SVID specifications.
Option or Flag |
Sun C |
ANSI C |
Sun WorkShop(TM) C++ 4.2 |
Description |
---|---|---|---|---|
-A symbol |
No |
Yes |
Yes |
cpp predicate assertion |
-a |
Yes |
Yes |
-xa |
Counts # basic block executions |
-align |
Yes |
Yes |
No |
Page aligns (ld) |
-assertx |
Yes |
Yes |
-z |
Specifies link-time assertion |
-BX |
Yes |
Yes |
Yes |
Specifies binding type (only for libraries in SunOS release 5.6) |
-bnzero |
Yes |
Yes |
No |
Generates nonzero AR |
-C |
Yes |
Yes |
No |
cpp comments left in |
-c |
Yes |
Yes |
+Yes |
Produces .o file |
-cg87 |
Yes |
Yes |
No |
Sets fp option to -cg87 |
-cg89 |
Yes |
Yes |
Yes |
Sets fp option to -cg89 |
-dryrun |
Yes |
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 double-word aligned |
-dl |
Yes |
Yes |
No |
Generates long data segment refs |
-d[y|n] | -BX | -BX |
Yes |
Dynamic linking [yes|no] |
-E |
Yes |
Yes |
+Yes |
Runs source through cpp |
-e |
No |
No |
No |
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 |
Yes |
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 |
-KPIC |
-PIC |
-PIC |
Yes |
Position independent code |
-Kpic |
-pic |
-pic |
Yes |
PIC with short offsets |
-Kminabi |
No |
No |
No |
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 |
No |
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 |
Yes |
Uses appropriate -cg option |
-noc2 |
Yes |
Yes |
No |
Doesn't do peephole optimization |
-nolibmil |
Yes |
Yes |
-xnolibmil |
Doesn't pass libm.il with -fast |
-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 |
-pg |
Yes |
Yes |
-xpg |
Collects data for gprof |
-pic |
Yes |
Yes |
-Kpic |
pic code with short offset |
-pipe |
Yes |
No |
No |
Uses pipes instead of temp files |
-purecross |
Yes |
No |
No |
Doesn't have slash in VROOT |
-Qdir x |
Yes |
Yes |
-Y* |
Looks for compiler passes in x |
-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 |
No |
Looks for compiler passes in x |
-ql |
No |
No |
No |
Collects data for lprof |
-qp |
-p |
-p |
-p |
Collects data for prof |
-qpath x |
Yes |
Yes |
No |
Same as -Qdir |
-Qoption cpp x |
Yes |
Yes |
Yes |
Passes option x on to program cpp |
-Qoption iropt x |
Yes |
Yes |
Yes |
Passes option x on to program iropt |
-Qoption cg x |
Yes |
Yes |
Yes |
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 |
Yes |
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 lintl x |
Yes |
Yes |
No |
Passes option x on to program lint1 |
-qoption iropt x |
Yes |
Yes |
Yes |
Passes option x on to program iropt |
-qoption cg x |
Yes |
Yes |
Yes |
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 |
-qoption asS x |
Yes |
Yes |
No |
Passes option x on to program asS |
-qoption ld x |
Yes |
Yes |
Yes |
Passes option x on to program ld |
-Qproduce .o |
Yes |
Yes |
Yes |
Produces type .o file (Object file) |
-Qproduce .s |
Yes |
Yes |
Yes |
Produces type .s file (Assembler source) |
-Qproduce .c |
Yes |
Yes |
No |
Produces type .c file (C source) |
-Qproduce .i |
Yes |
Yes |
Yes |
Produces type .i file (C source after cpp) |
-qproduce .o |
Yes |
Yes |
Yes |
Produces type .o file (Object file) |
-qproduce .s |
Yes |
Yes |
Yes |
Produces type .s file (Assembler source) |
-qproduce .c |
Yes |
Yes |
No |
Produces type .c file (C source) |
-qproduce .i |
Yes |
Yes |
Yes |
Produces type .i file (C source after cpp) |
-r |
Yes |
Yes |
No |
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 |
No |
Places string literals in read-only text segment |
-sun2 |
Yes |
No |
No |
Generates code for a Sun-2(TM) system |
-sun3x |
Yes |
No |
No |
Generates code for a Sun-3x(TM) system |
-sun386 |
Yes |
No |
No |
Generates code for a Sun386i(TM) |
-sun3 |
Yes |
No |
No |
Generates code for a Sun-3 system |
-sun4c |
Yes |
No |
No |
Generates code for a Sun4c(TM) system |
-sun4 |
Yes |
No |
No |
Generates code for a Sun-4(TM) system |
-target |
Yes |
No |
-xtarget |
Sets target architecture to x |
-temp=dir |
Yes |
Yes |
Yes |
Set directory for temps to dir |
-time |
Yes |
Yes |
Yes |
Reports the execution times |
-u |
Yes |
Yes |
No |
Enters symbol arg as undef (ld) |
-Ux |
Yes |
Yes |
+Yes |
Undefines cpp symbol x |
-v |
Yes |
Yes |
Yes |
Verbose mode |
-v |
No |
No |
Yes |
Strict semantic checking |
-V |
Yes |
Yes |
+Yes |
Reports versions of programs |
-W |
No |
No |
No |
Arguments to other components |
-w |
Yes |
Yes |
Yes |
Does not print warnings |
-X[t,a,c,s] |
No |
Yes |
No |
Compatibility options |
-Y |
No |
No |
No |
Changes path name to components |
-yx |
Yes |
No |
No |
Traces symbol |
-z |
-assert |
-assert |
No |
Turns on asserts in linker |
-# |
-v |
-v |
No |
Verbose mode |
-EOF |
No |
No |
No |
File argument |
The C compiler accepts the types of file-name arguments shown in Table 15-2.
Table 15-2 File-name Extensions Used by the C Compiler
Suffix |
File Type |
---|---|
.a |
Object library |
.il |
In-line expansion file |
.o |
Object file |
.so |
Shared object |
.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"
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.
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.
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.6 ld command.
The sections following Table 15-3 explain how certain linking tasks are affected by the option differences.
Table 15-3 Comparison of ld Options
SunOS release 4.x Option |
Solaris 2.6 Replacement |
Notes |
---|---|---|
-align datum |
-M mapfile |
Uses mapfile 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 |
-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". |
-Bnosymbolic |
-zdefs |
|
-Bstatic |
-dn & -Bstatic |
The -dn option must be specified to completely eliminate the dynamic linker. Use -Bstatic in dynamic mode to include archive libraries. (Used as a toggle. See "Building Executables".) |
-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 |
mapfile contains 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 |
|
-S |
No replacement |
|
-s |
-s |
|
-t |
No replacement |
|
-T hex |
-M mapfile |
mapfile contains different mechanisms to accomplish desired effect |
-Tdata hex |
-M mapfile |
mapfile contains different mechanisms to accomplish desired effect |
-u name |
-u name |
|
-x |
No replacement |
|
-X |
No replacement |
|
-y sym |
No replacement |
|
-z |
Default |
The procedure for building shared librariesin the Solaris 2.6 operating environment requires the -G option. In the SunOS release 4.x software, 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.
The -Bdynamic and -Bstatic options are still available, but their behavior is different. These options now refer to library inclusions to the executable rather than binding. Executable binding is set exclusively with the new -dy and -dn options in the Solaris 2.6 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.6 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
In the SunOS release 4.x software, 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 -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.
The dynamic linker and the runtime linker determine their search paths through a different algorithm from that used by the SunOS release 4.x linker.
The examples below compare the search paths for the dynamic linker and the runtime linker for SunOS release 4.x and the Solaris 2.6 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.
SunOS release 4.x linker search paths:
Link Editor: -L, LD_LIBRARY_PATH
, /usr/lib, /usr/local/lib
Runtime Linker: LD_LIBRARY_PATH
, -L, /usr/lib, /usr/local/lib
Solaris 2.6 linker search paths (with LD_LIBRARY_PATH
=dirlist1):
Link Editor: -L, dirlist1, /usr/ccs/lib, /usr/lib
Runtime Linker: dirlist1, -R, /usr/lib
Solaris 2.6 linker search paths (with LD_LIBRARY_PATH
=dirlist1,dirlist2):
Link Editor: dirlist1, -L, dirlist2, /usr/ccs/lib, /usr/lib
The SunOS release 4.x software supported both major and minor version numbers on shared libraries. The Solaris 2.6 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 the SunOS release 4.x software.
Table 15-4 shows versions of SunOS release 4.x and Solaris 2.6 shared libraries.
Table 15-4 Example Shared Libraries
SunOS release 4.x |
Solaris 2.6 |
---|---|
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 the Solaris 2.6 environment, 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 file name 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 file name 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. You should build any new shared libraries with major numbers, then create a symbolic link to the version of the library that is used most often.
A new utility, dump(1), makes it easier to debug object files or to check the static and dynamic linking, see "Backing Up and Restoring Files"). 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:
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 |
This section describes changes to debugging tools.
The dbx and dbxtool tools are no longer available with default system software. Enhanced versions of these tools are available as part of Sun WorkShop(TM), an unbundled product.
The adb and kadb tools are available in the Solaris 2.6 operating environment. They offer the same capabilities as the SunOS release 4.x tools. 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.6 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
The kadb macros described below are particularly useful with the new multithreaded kernel.
thread displays the current thread. The current thread pointer is in SPARC global register g7.
kadb[0]: <g7$<thread |
threadlist shows the stack traces of all the kernel threads in the system. This can be a long list.
kadb[0]: $<threadlist |
mutex shows you the address of the owning thread. The following example uses the global unsafe driver mutex.
kadb[0]: unsafe_driver$<mutex |
kadb[0]: moddebug/W 0x80000000 |
moddebug enables you to watch module loading. See the end of <sys/modctl.h> for legal values for moddebug for debugging purposes only.
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 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 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 for complete details on all truss options. There are a number of other Solaris 2.6 debugging tools based on proc(4) such as pmap(1).