home *** CD-ROM | disk | FTP | other *** search
- ELF_GETDATA(3E) Last changed: 10-13-98
-
-
- NNAAMMEE
- eellff__ggeettddaattaa, eellff__nneewwddaattaa, eellff__rraawwddaattaa - Gets section data
-
- SSYYNNOOPPSSIISS
- cccc [_f_l_a_g ...] _f_i_l_e ... --lleellff [_l_i_b_r_a_r_y ...]
-
- ##iinncclluuddee <<lliibbeellff..hh>>
-
- EEllff__DDaattaa **eellff__ggeettddaattaa((EEllff__SSccnn **ssccnn,, EEllff__DDaattaa **ddaattaa));;
-
- EEllff__DDaattaa **eellff__nneewwddaattaa((EEllff__SSccnn **ssccnn));;
-
- EEllff__DDaattaa **eellff__rraawwddaattaa((EEllff__SSccnn **ssccnn,, EEllff__DDaattaa **ddaattaa));;
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- These functions access and manipulate the data associated with a
- section descriptor, ssccnn. When reading an existing file, a section
- will have a single data buffer associated with it. A program may
- build a new section in pieces, however, composing the new data from
- multiple data buffers. For this reason, the data for a section should
- be viewed as a list of buffers, each of which is available through a
- data descriptor.
-
- eellff__ggeettddaattaa lets a program step through a section's data list. If the
- incoming data descriptor, ddaattaa, is null, the function returns the
- first buffer associated with the section. Otherwise, ddaattaa should be a
- data descriptor associated with ssccnn, and the function gives the
- program access to the next data element for the section. If ssccnn is
- null or an error occurs, eellff__ggeettddaattaa returns a null pointer.
-
- eellff__ggeettddaattaa translates the data from file representations into memory
- representations [see eellff__xxllaattee(3E)] and presents objects with memory
- data types to the program, based on the file's ccllaassss [see eellff(3E)].
- The working library version [see eellff__vveerrssiioonn(3E)] specifies what
- version of the memory structures the program wants eellff__ggeettddaattaa to
- present.
-
- eellff__nneewwddaattaa creates a new data descriptor for a section, appending it
- to any data elements already associated with the section. As the
- following descriptions state, the new data descriptor appears empty,
- indicating that the element holds no data. For convenience, the
- descriptor's type (dd__ttyyppee) is set to EELLFF__TT__BBYYTTEE, and the version
- (dd__vveerrssiioonn) is set to the working version. The program is responsible
- for setting (or changing) the descriptor members as needed. This
- function implicitly sets the EELLFF__FF__DDIIRRTTYY bit for the section's data
- [see eellff__ffllaagg(3E)]. If ssccnn is null or an error occurs, eellff__nneewwddaattaa
- returns a null pointer.
-
- eellff__rraawwddaattaa differs from eellff__ggeettddaattaa by returning only uninterpreted
- bytes, regardless of the section type. This function typically should
- be used only to retrieve a section image from a file being read, and
- then only when a program must avoid the automatic data translation in
- the following description. Moreover, a program may not close or
- disable [see eellff__ccnnttll(3E)] the file descriptor associated with eellff
- before the initial raw operation, because eellff__rraawwddaattaa might read the
- data from the file to ensure that it does not interfere with
- eellff__ggeettddaattaa. See eellff__rraawwffiillee(3E) for a related facility that applies
- to the entire file. When eellff__ggeettddaattaa provides the right translation,
- its use is recommended over eellff__rraawwddaattaa. If ssccnn is null or an error
- occurs, eellff__rraawwddaattaa returns a null pointer.
-
- The EEllff__DDaattaa structure includes the following members:
-
- vvooiidd **dd__bbuuff;;
-
- EEllff__TTyyppee dd__ttyyppee;;
-
- ssiizzee__tt dd__ssiizzee;;
-
- ooffff__tt dd__ooffff;;
-
- ssiizzee__tt dd__aalliiggnn;;
-
- uunnssiiggnneedd dd__vveerrssiioonn;;
-
- These members are available for direct manipulation by the program.
- The following are member descriptions:
-
- dd__bbuuff Contains a pointer to the data buffer. A data element
- with no data has a null pointer.
-
- dd__ttyyppee This member's value specifies the type of the data to
- which dd__bbuuff points. A section's type determines how to
- interpret the section contents.
-
- dd__ssiizzee This member holds the total size, in bytes, of the
- memory occupied by the data. This may differ from the
- size as represented in the file. The size will be zero
- if no data exist. [See the discussion of SSHHTT__NNOOBBIITTSS
- below for more information.]
-
- dd__ooffff This member gives the offset, within the section, at
- which the buffer resides. This offset is relative to
- the file's section, not the memory object's section.
-
- dd__aalliiggnn This member holds the buffer's required alignment, from
- the beginning of the section. That is, dd__ooffff will be a
- multiple of this member's value. For example, if this
- member's value is four, the beginning of the buffer will
- be four-byte aligned within the section. Moreover, the
- entire section will be aligned to the maximum of its
- constituents, thus ensuring appropriate alignment for a
- buffer within the section and within the file.
-
- dd__vveerrssiioonn This member holds the version number of the objects in
- the buffer. When the library originally read the data
- from the object file, it used the working version to
- control the translation to memory objects.
-
- DDAATTAA AALLIIGGNNMMEENNTT
- As mentioned above, data buffers within a section have explicit
- alignment constraints. Consequently, adjacent buffers sometimes will
- not abut, causing _h_o_l_e_s within a section. Programs that create output
- files have two ways of dealing with these holes.
-
- First, the program can use eellff__ffiillll to tell the library how to set the
- intervening bytes. When the library must generate gaps in the file,
- it uses the fill byte to initialize the data. The library's initial
- fill value is zero, and eellff__ffiillll lets the application change that
- value.
-
- Second, the application can generate its own data buffers to occupy
- the gaps, filling the gaps with values appropriate for the section
- being created. A program might even use different fill values for
- different sections. For example, it could set text sections' bytes to
- no-operation instructions, while filling data section holes with zero.
- Using this technique, the library finds no holes to fill, because the
- application eliminated them.
-
- SSeeccttiioonn aanndd MMeemmoorryy TTyyppeess
- eellff__ggeettddaattaa interprets sections' data according to the section type,
- as noted in the section header available through eellff__ggeettsshhddrr. The
- following table shows the section types and how the library represents
- them with memory data types for the 32-bit file class. Other classes
- would have similar tables. By implication, the memory data types
- control translation by eellff__xxllaattee.
-
- --------------------------------------------------------------------------
- Section Type Elf_Type 32-Bit Type
- --------------------------------------------------------------------------
- SHT_DYNAMIC ELF_T_DYN Elf32_Dyn
- SHT_DYNSYM ELF_T_SYM Elf32_Sym
- SHT_HASH ELF_T_WORD Elf32_Word
- SHT_NOBITS ELF_T_BYTE unsigned char
- SHT_NOTE ELF_T_BYTE unsigned char
- SHT_NULL nnoonnee nnoonnee
- SHT_PROGBITS ELF_T_BYTE unsigned char
- SHT_REL ELF_T_REL Elf32_Rel
- SHT_RELA ELF_T_RELA Elf32_Rela
- SHT_STRTAB ELF_T_BYTE unsigned char
- SHT_SYMTAB ELF_T_SYM Elf32_Sym
- ootthheerr ELF_T_BYTE unsigned char
- --------------------------------------------------------------------------
-
- eellff__rraawwddaattaa creates a buffer with type EELLFF__TT__BBYYTTEE.
-
- As previously mentioned, the program's working version controls what
- structures the library creates for the application. The library
- similarly interprets section types according to the versions. If a
- section type belongs to a version newer than the application's working
- version, the library does not translate the section data. Because the
- application cannot know the data format in this case, the library
- presents an untranslated buffer of type EELLFF__TT__BBYYTTEE, just as it would
- for an unrecognized section type.
-
- A section with a special type, SSHHTT__NNOOBBIITTSS, occupies no space in an
- object file, even when the section header indicates a non-zero size.
- eellff__ggeettddaattaa and eellff__rraawwddaattaa work on such a section, setting the ddaattaa
- structure to have a null buffer pointer and the type previously
- indicated. Although no data are present, the dd__ssiizzee value is set to
- the size from the section header. When a program is creating a new
- section of type SSHHTT__NNOOBBIITTSS, it should use eellff__nneewwddaattaa to add data
- buffers to the section. These empty data buffers should have the
- dd__ssiizzee members set to the desired size and the dd__bbuuff members set to
- null.
-
- NNOOTTEESS
- The 64-bit class functions work identically, simply replacing all
- instances of 32 in the descriptions with 64.
-
- EEXXAAMMPPLLEESS
- The following fragment obtains the string table that holds section
- names (ignoring error checking). See eellff__ssttrrppttrr(3E) for a variation
- of string table handling.
-
- ehdr = elf32_getehdr(elf);
- scn = elf_getscn(elf, (size_t)ehdr->e_shstrndx);
- shdr = elf32_getshdr(scn);
- if (shdr->sh_type != SHT_STRTAB)
- {
- /* not a string table */
- }
- data = 0;
- if ((data = elf_getdata(scn, data)) == 0 || data->d_size == 0)
- {
- /* error or no data */
- }
-
- The ee__sshhssttrrnnddxx member in an ELF header holds the section table index
- of the string table. The program gets a section descriptor for that
- section, verifies it is a string table, and then retrieves the data.
- When this fragment finishes, ddaattaa-->>dd__bbuuff points at the first byte of
- the string table, and ddaattaa-->>dd__ssiizzee holds the string table's size in
- bytes.
-
- SSEEEE AALLSSOO
- eellff(3E), eellff__ccnnttll(3E), eellff__ffiillll(3E), eellff__ffllaagg(3E), eellff__ggeetteehhddrr(3E),
- eellff__ggeettssccnn(3E), eellff__ggeettsshhddrr(3E), eellff__rraawwffiillee(3E), eellff__vveerrssiioonn(3E),
- eellff__xxllaattee(3E)
-
- This man page is available only online.
-
-