File: elf_flagelf.3

package info (click to toggle)
elfutils 0.194-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,680 kB
  • sloc: ansic: 114,970; sh: 35,537; cpp: 4,998; makefile: 1,986; yacc: 1,388; lex: 130; asm: 77; sed: 39; awk: 35
file content (187 lines) | stat: -rw-r--r-- 4,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
.TH ELF_FLAGELF 3 2025-06-23 "Libelf" "Libelf Programmer's Manual"

.SH NAME
elf_flagelf, elf_flagdata, elf_flagehdr, elf_flagphdr, elf_flagscn, elf_flagshdr \- set or clear flags on ELF descriptors and components
.SH SYNOPSIS
.nf
.B #include <libelf.h>

.BI "unsigned int elf_flagelf(Elf * " elf ", Elf_Cmd " cmd ", unsigned int " flags ");"
.BI "unsigned int elf_flagehdr(Elf * " elf ", Elf_Cmd " cmd ", unsigned int " flags ");"
.BI "unsigned int elf_flagphdr(Elf * " elf ", Elf_Cmd " cmd ", unsigned int " flags ");"
.BI "unsigned int elf_flagscn(Elf_Scn * " scn ", Elf_Cmd " cmd ", unsigned int " flags ");"
.BI "unsigned int elf_flagshdr(Elf_Scn * " scn ", Elf_Cmd " cmd ", unsigned int " flags ");"
.BI "unsigned int elf_flagdata(Elf_Data * " data ", Elf_Cmd " cmd ", unsigned int " flags ");"
.fi

.SH DESCRIPTION
These functions allow the caller to set or clear flags on various ELF
components managed by
.B libelf .
They are typically used to indicate that a component has been modified
(dirty), or to control layout behavior during output.

.BR elf_flagelf ()
modifies flags on the top-level
.B Elf
descriptor.

.BR elf_flagdata ()
modifies flags on an
.B Elf_Data
descriptor, typically retrieved using
.BR elf_getdata (3)
or created with
.BR elf_newdata (3).

.BR elf_flagehdr ()
modifies flags on the ELF header for a ELF descriptor (e.g., the result of
.BR gelf_getehdr (3)).

.BR elf_flagphdr ()
modifies flags on the program header table of an ELF descriptor.

.BR elf_flagscn ()
modifies flags on an
.B Elf_Scn
(section) descriptor.

.BR elf_flagshdr ()
modifies flags on the section header of a given
.B Elf_Scn .

The
.I cmd
argument determines whether the given flags should be set (
.B ELF_C_SET
) or cleared (
.B ELF_C_CLR
).

The following flag values may be passed via the
.I flags
parameter:

.TP
.B ELF_F_DIRTY
Marks the object as modified. This ensures changes to the component is written
out during
.BR elf_update (3).

.TP
.B ELF_F_LAYOUT
Indicates that the layout of the ELF component is managed manually. Offsets and
sizes will be preserved as provided.  This flag is only used with
.BR elf_flagelf ()
and is ignored when used with other functions.
If this flag is set the user must set Ehdr
.IR e_phoff ,
.IR e_shoff ,
as well as
.B Elf_Data
.I d_off
and Shdr
.IR sh_offset .
If not set, then these offsets will be recalculated when
.B elf_update
is called.
If
.B ELF_F_LAYOUT
is set then changes to phdr offsets will prevent elf_update from automatically
adjusting shdr offsets.

.TP
.B ELF_F_PERMISSIVE
Enables relaxed validation of object structure. This flag permits nonstandard
layouts without strict checks.  Specifically this removes a check in
.BR elf_update ()
that the section
.I sh_size
is a multiple of the section
.I sh_entsize
(if not zero).  This flag is only used with
.BR elf_flagelf ()
and is ignored when used with other functions.
.B ELF_F_PERMISSIVE
is an elfutils libelf extention and may not be available in other libelf
implementations.

.SH PARAMETERS
.TP
.I obj
The object to be modified:
For
.BR elf_flagelf ,
.BR elf_flagehdr ,
.BR elf_flagphdr ,
this is an
.B Elf *
descriptor.
For
.B elf_flagscn
and
.B elf_flagshdr ,
this is an
.B Elf_Scn *
descriptor.
For
.B elf_flagdata ,
an
.B Elf_Data *
buffer.

.TP
.I cmd
Must be either:
.B ELF_C_SET
to set the given flags, or
.B ELF_C_CLR
to clear them.

.TP
.I flags
Bitmask of flags to modify. May include any combination of
.B ELF_F_DIRTY ,
.B ELF_F_LAYOUT ,
and
.B ELF_F_PERMISSIVE .

Note that
.B ELF_F_LAYOUT
and
.B ELF_F_PERMISSIVE
are only used with
.BR elf_flagelf ()
and are ignored for other functions.

.SH RETURN VALUE
Returns the new value of the flags after the set/clear operation.

Returns 0 on error, and sets an error code retrievable via
.BR elf_errmsg (3).
If the first argument is NULL then 0 is return and no error code is set.

If the last flag is cleared, 0 will be returned as the new flag value.
In this case 0 is not an error indicator and no error code is set.

.SH SEE ALSO
.BR elf_errmsg (3),
.BR elf_update (3),
.BR libelf (3),
.BR elf (5)

.SH ATTRIBUTES
.TS
allbox;
lbx lb lb
l l l.
Interface	Attribute	Value
T{
.na
.nh
.BR elf_flagelf (),\~elf_flagehdr(),\~elf_flagphdr(),\~elf_flagscn(),\~elf_flagshdr(),\~elf_flagdata()
T}	Thread safety	MT-Unsafe race
.TE

.SH REPORTING BUGS
Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.