[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


ldshread or ldnshread Subroutine

Purpose

Reads a section header of an XCOFF file.

Library

Object File Access Routine Library (libld.a)

Syntax


#include <stdio.h>
#include <ldfcn.h>


int ldshread ( ldPointer, SectionIndex, SectionHead)
LDFILE *ldPointer;
unsigned short SectionIndex;
void *SectionHead;


int ldnshread (ldPointer, SectionName, SectionHead)
LDFILE *ldPointer;
char *SectionName;
void *SectionHead;

Description

The ldshread subroutine reads the section header specified by the SectionIndex parameter of the common object file currently associated with the ldPointer parameter into the area of memory beginning at the location specified by the SectionHead parameter.

The ldnshread subroutine reads the section header named by the SectionName argument into the area of memory beginning at the location specified by the SectionHead parameter. It is the responsibility of the calling routine to provide a pointer to a buffer large enough to contain the section header of the associated object file. Since the ldopen subroutine provides magic number information (via the HEADER(ldPointer ).f_magic macro), the calling application can always determine whether the SectionHead pointer should refer to a 32-bit SCNHDR or 64-bit SCNHDR_64 structure.

Only the first section header named by the SectionName argument is returned by the ldshread subroutine.

Parameters


ldPointer Points to an LDFILE structure that was returned as the result of a successful call to the ldopen, lldopen, or ldaopen subroutine.
SectionIndex Specifies the index of the section header to be read.

Note: The first section has an index of 1.
SectionHead Points to a buffer large enough to accept either a 32-bit or a 64-bit SCNHDR structure, according to the object mode of the file being read.
SectionName Specifies the name of the section header to be read.

Return Values

The ldshread and ldnshread subroutines return a SUCCESS or FAILURE value.

Error Codes

The ldshread subroutine fails if the SectionIndex parameter is greater than the number of sections in the object file. The ldnshread subroutine fails if there is no section with the name specified by the SectionName parameter. Either function fails if it cannot read the specified section header.

Examples

The following is an example of code that opens an object file, determines its mode, and uses the ldnshread subroutine to acquire the .text section header. This code would be compiled with both __XCOFF32__ and __XCOFF64__ defined:

#define __XCOFF32__
#define __XCOFF64__
 
#include <ldfcn.h>
 
 
 
/* for each FileName to be processed */
 
if ( (ldPointer = ldopen(FileName, ldPointer)) != NULL )
{
    SCNHDR    SectionHead32;
    SCNHDR_64 SectionHead64;
    void      *SectionHeader;
 
    if ( HEADER(ldPointer).f_magic == U802TOCMAGIC )
        SectionHeader = &SectionHead32;
    else if ( HEADER(ldPointer).f_magic == U803XTOCMAGIC )
        SectionHeader = &SectionHead64;
    else
        SectionHeader = NULL;
 
    if ( SectionHeader && (ldnshread( ldPointer, ".text", &SectionHeader ) == SUCCESS) )
    {
        /* ...successfully read header... */
        /* ...process according to magic number... */
    }
}

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

Related Information

The ldahread (ldahread Subroutine) subroutine, ldfhread (ldfhread Subroutine) subroutine, ldgetname (ldgetname Subroutine) subroutine, ldlread, ldlinit, or ldlitem (ldlread, ldlinit, or ldlitem Subroutine)subroutine, ldtbread (ldtbread Subroutine) subroutine.

Subroutines, Example Programs, and Libraries in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]