ldfcn(4) — File Formats
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. 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(3) 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:
LDFILE ∗ldptr;
TYPE(ldptr)The file magic number, used to distinguish between archive members and simple object files.
IOPTR(ldptr)Not used, because files are memory mapped.
OFFSET(ldptr)
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.
HEADER(ldptr)
The file header structure of the object file.
SYMHEADER(ldptr)
The symbolic header structure for the symbol table associated with the object file.
PFD(ldptr)The file table associated with the symbol table.
SYMTAB(ldptr)
A pointer to a copy of the symbol table in memory. It is accessed through the pCHDR structure (see <cmplrs/stsupport.h>). If no symbol table is present, this field is NULL.
Note
This macro causes the whole symbol table to be read.
LDSWAP(ldptr)
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:
1.Functions that open or close an object file
ldopen(3) and ldaopen open a common object file. ldclose(3) and ldaclose close a common object file.
2.Functions that return header or symbol table information
ldahread(3) reads the archive header of a member of an archive file.
ldfhread(3) reads the file header of a common object file.
ldshread(3) and ldnshread read a section header of a common object file.
ldtbread(3) reads a symbol table entry of a common object file.
ldgetname(3) retrieves a symbol name from a symbol table entry or from the string table.
ldgetaux(3) retrieves a pointer into the aux table for the specified ldptr.
ldgetpd(3) retrieves a procedure descriptor.
3.Functions that position an object file at (seek to) the start of the section, relocation, or line number information for a particular section
ldohseek(3) seeks to the optional file header of a common object file. ldsseek(3) and ldnsseek seek to a section of a common object file.
ldrseek(3) and ldnrseek seek to the relocation information for a section of a common object file.
ldlseek(3) and ldnlseek seek to the line number information for a section of a common object file.
ldtbseek(3) seeks to the symbol table of a common object file.
4.Miscellaneous functions
ldtbindex(3) returns the index of a particular common object file symbol table entry.
ranhashinit (see ranhash(3)) initializes the tables and constants so that the archive hash and lookup routines can work.
ranhash(3) gives a string return the hash index for it.
ranlookup (see ranhash(3)) returns an archive hash bucket that is empty or matches the string argument.
disassembler(3) prints assembly instructions.
These functions are described in detail in the manual pages identified for each function.
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 input/output 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 manual entries for the corresponding standard input/output library functions for details on the use of these macros. (The functions are identified as 3 in Section 3 of this manual.)
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(3). 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), ldlread(3), ldlseek(3), ldohseek(3), ldopen(3), ldrseek(3), ldshread(3), ldtbread(3), ldtbseek(3).