Reads a section header of an XCOFF file.
Object File Access Routine Library (libld.a)
#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;
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.
The ldshread and ldnshread subroutines return a SUCCESS or FAILURE value.
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.
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... */ } }
These subroutines are part of Base Operating System (BOS) Runtime.
The ldahread subroutine, ldfhread subroutine, ldgetname subroutine, ldlread, ldlinit, or ldlitem subroutine, ldtbread subroutine.
Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.