or data definition can be either a local definition or global definition. Any reference to a symbol outside the object file is known as an external reference.

To keep track of where all the symbols and external references occur, an object file has a symbol table. The linker uses the symbol tables of all input object files to match external references to global definitions.

Local Definitions

A local definition is a definition of a routine or data that is accessible only within the object file in which it is defined. Such a definition cannot be accessed from another object file. Local definitions are used primarily by debuggers, such as adb. More important for this discussion are the global definitions and external references.

Global Definitions

A global definition is a definition of a procedure, function, or data item that can be accessed by code in another object file. For example, the C compiler generates global definitions for all variable and function definitions that are not static. The FORTRAN compiler generates global definitions for subroutines and common blocks. In Pascal, global definitions are generated for external procedures, external variables, and global data areas for each module.

External References

An external reference is an attempt by code in one object file to access a global definition in another object file. A compiler cannot resolve external references because it works on only one source file at a time. Therefore, the compiler simply places external references in an object file's symbol table; the matching of external references to global definitions is left to the linker or loader.

Compiler-Linker Interaction

As described in “Looking Inside a Compiler” (page 18), the compilers automatically call the linker to create an executable file. To see how the compilers call ld, run the compiler with the -v(verbose) option.

For example, compiling a C program to produce an IPF 32-bit share-bound application, produces the output below:

$ cc -v main.c func.c -lm main.c:

/opt/ansic/lbin/ecom -ia64abi all -architecture 32 -ext on -lang c \ -exception off -sysdir /usr/include - inline_power 1 -link_type dynamic \ -fpeval float - tls_dyn on -target_os 11.23 --sys_include /usr/include \ -D__hpux -D__unix -D__ia64=1 -D_BIG_ENDIAN=1 -D_ILP32 -D__HP_cc=60200 \ -D__STDC_EXT__ -D_HPUX_SOURCE -D_INCLUDE_LONGLONG -D_INLINE_ASM \ -D_BIND_LIBCALLS -D_Math_errhandling=MATH_ERREXCEPT -D_FLT_EVAL_METHOD=O \ -ucode hdriver=optlevel%1% -plusolistoption -O106const! -plusolistoption \

-O113moderate! -plusooption -Oq01,al,ag,cn,sz,ic,vo,Mf,Po,es,rs,Rf,Pr,sp,\ in,cl,om,vc,pi,fa,pe,rr,pa,pv,nf,cp,1x,Pg,ug,1u,lb,uj,dn,sg,pt,kt,em,np,ar,\ rp,dl,fs,bp,wp,pc,mp,1r,cx,cr,pi,so,Rc,fa,ft,fe,ap,st,lc,Bl,sr,ib,pl,sd,ll,\ rl,dl,Lt,ol,fl,lm,ts,rd,dp,If! main.c

func.c:

/opt/ansic/lbin/ecom -ia64abi all -architecture 32 -ext on -lang c \

-exception off -sysdir /usr/include - inline_power 1 -link_type dynamic \

-fpeval float - tls_dyn on -target_os 11.23 --sys_include /usr/include \

Compiling Programs on HP-UX: An Example 19

Page 19
Image 19
HP UX Software Transition Kit (STK) manual Compiler-Linker Interaction, Local Definitions, Global Definitions