Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ldopen(3x) [ultrix man page]

ldopen(3x)																ldopen(3x)

Name
       ldopen, ldaopen, ldreadst - open a common object file for reading

Syntax
       #include <stdio.h>
       #include <filehdr.h>
       #include <syms.h>
       #include <ldfcn.h>

       LDFILE *ldopen (filename, ldptr)
       char *filename;
       LDFILE *ldptr;

       LDFILE *ldaopen (filename, oldptr)
       char *filename;
       LDFILE *oldptr;

       ldreadst (ldptr, flags)
       LDFILE *ldptr;
       intflags;

Description
       The  and functions provide uniform access to simple object files and to object files that are members of archive files.	An archive of com-
       mon object files can be processed as if it is a series of simple common object files.

       If ldptr has the value null, opens filename, allocates and initializes the LDFILE structure, and returns a pointer to the structure to  the
       calling program.

       If ldptr is valid and TYPE(ldptr) is the archive magic number, reinitializes the LDFILE structure for the next archive member of filename.

       The  and  functions work in concert.  The function returns failure only when only when TYPE(ldptr) is the archive magic number and there is
       another file in the archive to be processed.  Only then should be called with the current value of ldptr.  In all other	cases,	but  espe-
       cially when a new filename is opened, should be called with a null ldptr argument.

       The following is a prototype for the use of and
       /* for each filename to be processed*/

       ldptr = NULL;
       do
	    if ( (ldptr = ldopen(filename, ldptr)) != NULL )

	    {
		 /* check magic number */
		 /* process the file */
	    }
       } while (ldclose(ldptr) == FAILURE );

       If  the	value  of  oldptr  is  not NULL, opens filename anew and allocates and initializes a new LDFILE structure, copying the fields from
       oldptr.	The function returns a pointer to the new LDFILE structure.  This new pointer is independent of the old pointer, oldptr.  The  two
       pointers  can  be  used	concurrently to read separate parts of the object file.  For example, one pointer can be used to step sequentially
       through the relocation information while the other is used to read indexed symbol table entries.

       The and functions open filename for reading.  If filename cannot be opened or if memory for the LDFILE structure cannot be allocated,  both
       functions return NULL.  A successful open does not ensure that the given file is a common object file or an archived object file.

       The  function  causes  the symbol table header and file descriptor table to be read.  Further access, using ldptr, causes other appropriate
       sections of the symbol table to be read (for example, if you call the symbols or externals are read).  To force sections  for  each  symbol
       table in memory, call with ST_P* constants or'ed together from st_support.h.

See Also
       fopen(3s), ldclose(3x), ldfcn(5)

								       RISC								ldopen(3x)

Check Out this Related Man Page

ldfcn(4)						     Kernel Interfaces Manual							  ldfcn(4)

NAME
ldfcn - Common object file access routines SYNOPSIS
#include <stdio.h> #include <filehdr.h> #include <syms.h> #include <ldfcn.h> DESCRIPTION
The common object file access routines are a collection of functions for reading an object file that is in common object file form (COFF). Although the calling program must know the detailed structure of the parts of the object file that it processes, the routines effectively insulate the calling program from knowledge of the overall structure of the object file. The interface between the calling program and the object file access routines is based on the defined type LDFILE (defined as struct ldfile), which is declared in the header file ldfcn.h. Primarily, this structure provides uniform access to simple object files and object files that are members of an archive file. The function ldopen allocates and initializes the LDFILE structure, reads in the symbol table header, if present, and returns a pointer to the structure to the calling program. The fields of the LDFILE structure can be accessed individually through macros defined in ldfcn.h. The fields contain the following information: The file magic number, used to distinguish between archive members and simple object files. Not used because files are memory mapped. The file address of the beginning of the object file or archive entry; if the object file is a member of an archive file, the offset is nonzero. The file header structure of the object file. The symbolic header structure for the symbol table associated with the object file. The file table associated with the symbol table. A pointer to a copy of the symbol table in memory. It is accessed through the pCHDR structure (see /usr/include/cmplrs/stsupport.h). If no symbol table is present, this field is NULL. (Note: This macro causes the whole symbol table to be read.) If the header and symbol table structures are swapped within the object file and all access requires using libsex, this field is set to true. (Note: If you use libmld routines, all structures except the optional header and auxiliaries are swapped.) The object file access functions can be divided into four categories: Functions that open or close an object file: ldopen and ldaopen open an object file. ldclose and ldaclose close an object file. Functions that return header or symbol table information: ldahread reads the archive header of a member of an archive file. ldfhread reads the file header of an object file. ldshread and ldnshread read a section header of an object file. ldtbread reads a symbol table entry of an object file. ldgetname retrieves a symbol name from a symbol table entry or from the string table. ldgetaux retrieves a pointer into the aux table for the specified ldptr. ldgetpd retrieves a procedure descriptor. Functions that seek to specified portions of an object file: ldohseek seeks to the optional file header of an object file. ldsseek and ldnsseek seek to a section of an object file. ldrseek and ldnrseek seek to the relocation information for a section of an object file. ldlseek and ldnlseek seek to the line number information for an object file. ldlseek and ldnlseek ignore section number and name arguments, respectively. ldtbseek seeks to the symbol table of an object file. Miscellaneous functions ranhashinit (see ranhash(3)) initializes the tables and constants so that the archive hash and lookup routines can work. Given a string, ranhash returns the hash index for it. ranlookup returns an archive hash bucket that is empty or matches the string argument. disassembler prints assembly instructions. These functions are described in detail in their own reference pages. The ldopen and ldaopen functions both return pointers to a LDFILE structure. MACROS
Additional access to an object file is provided through a set of macros defined in ldfcn.h. These macros parallel the standard inputoutput file reading and manipulating functions. They translate a reference of the LDFILE structure into a reference to its file descriptor field. The following macros are provided: GETC(ldptr) FGETC(ldptr) GETW(ldptr) UNGETC(c, ldptr) FGETS(s, n, ldptr) FREADM((char *) ptr, sizeof (*ptr), nitems, ldptr) FSEEK(ldptr, offset, ptrname) FTELL(ldptr) REWIND(ldptr) FEOF(ldptr) FERROR(ldptr) FILENO(ldptr) SETBUF(ldptr, buf) STROFFSET(ldptr) The STROFFSET macro calculates the address of the local symbol's string table in an object file. See the reference pages for the corre- sponding standard input/output library functions for details on the use of these macros. The program must be loaded with the object file access routine library libmld.a. WARNINGS
The FSEEK macro defined in the header file ldfcn.h translates into a call to the standard input/output function fseek. FSEEK should not be used to seek from the end of an archive file because the end of an archive file cannot be the same as the end of one of its object file members. RELATED INFORMATION
Commands: ar(1) Functions: fopen(3), fseek(3), ldahread(3), ldclose(3), ldfhread(3), ldgetname(3), ldlseek(3), ldohseek(3), ldopen(3), ldrseek(3), ldshread(3), ldtbread(3), ldtbseek(3). delim off ldfcn(4)
Man Page