1elf_update(3ELF)             ELF Library Functions            elf_update(3ELF)
2
3
4

NAME

6       elf_update - update an ELF descriptor
7

SYNOPSIS

9       cc [ flag ... ] file ... -lelf [ library ... ]
10       #include <libelf.h>
11
12       off_t elf_update(Elf *elf, Elf_Cmd cmd);
13
14

DESCRIPTION

16       The elf_update() function causes the library to examine the information
17       associated with an ELF descriptor, elf, and to recalculate  the  struc‐
18       tural data needed to generate the file's image.
19
20
21       The cmd argument can have the following values:
22
23       ELF_C_NULL     This  value  tells  elf_update()  to recalculate various
24                      values, updating only the ELF descriptor's memory struc‐
25                      tures.  Any  modified  structures  are  flagged with the
26                      ELF_F_DIRTY bit. A program thus can  update  the  struc‐
27                      tural information and then reexamine them without chang‐
28                      ing the file associated with the ELF descriptor. Because
29                      this  does  not  change the file, the ELF descriptor may
30                      allow reading, writing, or both reading and writing (see
31                      elf_begin(3ELF)).
32
33
34       ELF_C_WRITE    If  cmd  has  this  value,  elf_update()  duplicates its
35                      ELF_C_NULL actions and also writes any ``dirty''  infor‐
36                      mation  associated  with the ELF descriptor to the file.
37                      That is, when a program has  used  elf_getdata(3ELF)  or
38                      the  elf_flagdata(3ELF)  facilities  to  supply  new (or
39                      update existing)  information  for  an  ELF  descriptor,
40                      those  data will be examined, coordinated, translated if
41                      necessary (see elf32_xlatetof(3ELF)), and written to the
42                      file.  When  portions  of  the  file  are  written,  any
43                      ELF_F_DIRTY bits are reset, indicating  those  items  no
44                      longer  need  to  be  written to the file (see elf_flag‐
45                      data(3ELF)). The sections' data are written in the order
46                      of  their section header entries, and the section header
47                      table is written to the end of the file.  When  the  ELF
48                      descriptor  was  created  with elf_begin(), it must have
49                      allowed writing the file. That is, the elf_begin()  com‐
50                      mand must have been either ELF_C_RDWR or ELF_C_WRITE.
51
52
53
54       If  elf_update()  succeeds, it returns the total size of the file image
55       (not the memory image), in bytes. Otherwise an error occurred, and  the
56       function returns −1.
57
58
59       When  updating  the internal structures, elf_update() sets some members
60       itself. Members listed below are the application's  responsibility  and
61       retain the values given by the program.
62
63
64       The following table shows ELF Header members:
65
66
67
68
69       Member             Notes
70
71       e_ident[EI_DATA]   Library controls other e_ident values
72       e_type
73       e_machine
74       e_version
75       e_entry
76       e_phoff            Only when ELF_F_LAYOUT asserted
77       e_shoff            Only when ELF_F_LAYOUT asserted
78       e_flags
79       e_shstrndx
80
81
82
83       The following table shows the Program Header members:
84
85
86
87
88       Member             Notes
89
90       p_type             The application controls all
91       p_offset           program header entries
92       p_vaddr
93       p_paddr
94       p_filesz
95       p_memsz
96       p_flags
97       p_align
98
99
100
101       The following table shows the Section Header members:
102
103
104
105
106       Member             Notes
107
108       sh_name
109       sh_type
110       sh_flags
111       sh_addr
112       sh_offset          Only when ELF_F_LAYOUT asserted
113       sh_size            Only when ELF_F_LAYOUT asserted
114       sh_link
115       sh_info
116       sh_addralign       Only when ELF_F_LAYOUT asserted
117       sh_entsize
118
119
120
121       The following table shows the Data Descriptor members:
122
123
124
125
126       Member             Notes
127
128       d_buf
129       d_type
130       d_size
131       d_off              Only when ELF_F_LAYOUT asserted
132
133       d_align
134       d_version
135
136
137
138       Note  that  the  program  is responsible for two particularly important
139       members (among others) in the ELF header. The e_version member controls
140       the  version  of data structures written to the file. If the version is
141       EV_NONE,   the   library   uses   its   own   internal   version.   The
142       e_ident[EI_DATA]  entry controls the data encoding used in the file. As
143       a special case, the value may be ELFDATANONE to request the native data
144       encoding  for  the  host  machine.  An error occurs in this case if the
145       native encoding doesn't match a file encoding known by the library.
146
147
148       Further note that the program is responsible for the sh_entsize section
149       header  member.  Although  the  library sets it for sections with known
150       types, it cannot reliably know the correct value for all sections. Con‐
151       sequently,  the library relies on the program to provide the values for
152       unknown section types. If the entry size is unknown or not  applicable,
153       the value should be set to 0.
154
155
156       When  deciding  how  to  build  the output file, elf_update() obeys the
157       alignments of individual data buffers to create output sections. A sec‐
158       tion's  most strictly aligned data buffer controls the section's align‐
159       ment. The library also inserts padding between buffers,  as  necessary,
160       to ensure the proper alignment of each buffer.
161

ATTRIBUTES

163       See attributes(5) for descriptions of the following attributes:
164
165
166
167
168       ┌─────────────────────────────┬─────────────────────────────┐
169       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
170       ├─────────────────────────────┼─────────────────────────────┤
171       │Interface Stability          │Stable                       │
172       ├─────────────────────────────┼─────────────────────────────┤
173       │MT-Level                     │MT-Safe                      │
174       └─────────────────────────────┴─────────────────────────────┘
175

SEE ALSO

177       elf(3ELF), elf32_fsize(3ELF), elf32_getehdr(3ELF), elf32_getshdr(3ELF),
178       elf32_xlatetof(3ELF),  elf_begin(3ELF),  elf_flagdata(3ELF),   elf_get‐
179       data(3ELF), libelf(3LIB), attributes(5)
180

NOTES

182       As  mentioned  above, the ELF_C_WRITE command translates data as neces‐
183       sary, before writing them to the file. This translation is  not  always
184       transparent  to  the  application  program.  If  a program has obtained
185       pointers to data associated with a file (for example,  see  elf32_gete‐
186       hdr(3ELF)  and  elf_getdata(3ELF)),  the program should reestablish the
187       pointers after calling elf_update().
188
189
190
191SunOS 5.11                        11 Jul 2001                 elf_update(3ELF)
Impressum