summaryrefslogtreecommitdiff
path: root/usr/src/man/man1/elfedit.1
blob: b8f27fa3a9bee39cd4d26f5e28a81717c108d088 (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
'\" te
.\" Copyright (c) 2008, Sun Microsystems Inc. All
.\" Rights Reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH ELFEDIT 1 "May 17, 2020"
.SH NAME
elfedit \- examine or edit ELF files
.SH SYNOPSIS
.nf
\fBelfedit\fR [\fB-adr\fR] [\fB-e\fR \fIcmd\fR] [\fB-L\fR \fIpath\fR] [\fB-o\fR \fBdefault\fR | \fBsimple\fR | \fBnum\fR]
     [\fIinfile\fR] [\fIoutfile\fR]
.fi

.SH DESCRIPTION
\fBelfedit\fR is a tool for examining or modifying the contents of an existing
ELF object. Specifically, \fBelfedit\fR is used to modify the ELF metadata
contained in the object. Access is provided to most of the ELF data contained
in an object, including the ELF header, section header table, program header
table, dynamic section, hardware and software capabilities, string tables, and
symbol tables.
.SS "Syntax"
\fBelfedit\fR processes commands from the command line (\fB-e\fR option) or
from standard input. If standard input is a terminal, \fBelfedit\fR provides
terminal editing capabilities, as well as extensive command completion. ELF
uses many standard symbolic names for special integer values and bit masks.
\fBelfedit\fR is aware of most possible completions for such names. You can
press TAB at any point while entering an \fBelfedit\fR command to cause
\fBelfedit\fR to display a usage message and any known completions for the text
at the current cursor.
.sp
.LP
\fBelfedit\fR functionality is organized in the form of modules. Each module
delivers a set of commands, focused on related functionality. A command is
specified by combining the module and command names with a colon (\fB:\fR)
delimiter, with no intervening white space. For example, \fBdyn:runpath\fR
refers to the \fBrunpath\fR command provided by the \fBdyn\fR module. Module
names must be unique. The command names within a given module are unique within
that module, but the same command names can be used in more than one module.
.sp
.LP
Some modules designate one of their commands to be the default command for that
module. This command is run when the user specifies only a module name. Most
\fBelfedit\fR modules supply a command named dump, which produces the same
information displayed by the \fBelfdump\fR utility for the part of the ELF file
covered by the module. It is common for a module to specify dump as its default
command.
.sp
.LP
The syntax used to execute an \fBelfedit\fR command is intended to be familiar
to anyone who uses UNIX command line utilities. It consists of white space
delimited tokens. The first token is the command name. Options, which are
arguments that start with the hyphen (\fB-\fR) character follow the command.
Plain arguments (operands) follow the options. There can be \fB0\fR or more
options and operands for a given command, but if they are present, options
always precede plain arguments. The special option, \fB--\fR, (two hyphens) can
be used to delimit the end of the options. When it is encountered, any
remaining arguments are considered to be plain arguments even if they start
with a \fB-\fR.
.sp
.LP
The interpretation of the characters in an \fBelfedit\fR token depends on the
style of quoting used:
.sp
.ne 2
.na
\fBUnquoted\fR
.ad
.RS 17n
Outside of single (') or double (") quotes, backslash (\) acts as an escape
character. When a backslash character is seen, \fBelfedit\fR ignores it, and
treats the character following it literally (even if the following character is
itself a backslash). This feature can be used to insert a white space character
into a string argument to a command without having it split the string into two
separate tokens. Similarly, it can be used to insert a quote or backslash as a
literal character.
.RE

.sp
.ne 2
.na
\fBSingle Quotes\fR
.ad
.RS 17n
Within single quotes ('), white space characters do not delimit tokens, and are
interpreted as literal characters within the token. Double quote (") and
backslash (\) characters are interpreted as literal characters, and have no
special meaning.
.RE

.sp
.ne 2
.na
\fBDouble Quotes\fR
.ad
.RS 17n
Within double quotes ("), white space characters do not delimit tokens. Single
quote characters are interpreted literally and do not have a quoting function.
Backslash (\) is an escape character which operates similarly to the way it is
used in the C programming language within a string literal:
.sp
.ne 2
.na
\fB\ea\fR
.ad
.RS 8n
alert (bell)
.RE

.sp
.ne 2
.na
\fB\\b\fR
.ad
.RS 8n
backspace
.RE

.sp
.ne 2
.na
\fB\ef\fR
.ad
.RS 8n
form feed
.RE

.sp
.ne 2
.na
\fB\en\fR
.ad
.RS 8n
newline
.RE

.sp
.ne 2
.na
\fB\er\fR
.ad
.RS 8n
return
.RE

.sp
.ne 2
.na
\fB\et\fR
.ad
.RS 8n
horizontal tab
.RE

.sp
.ne 2
.na
\fB\\v\fR
.ad
.RS 8n
vertical tab
.RE

.sp
.ne 2
.na
\fB\\\fR
.ad
.RS 8n
backslash
.RE

.sp
.ne 2
.na
\fB\'\fR
.ad
.RS 8n
single quote
.RE

.sp
.ne 2
.na
\fB\e"\fR
.ad
.RS 8n
double quote
.RE

.sp
.ne 2
.na
\fB\\ooo\fR
.ad
.RS 8n
An octal constant, where ooo is one to three octal digits (0...7)
.RE

Any other character following a backslash is an error.
.RE

.sp
.LP
The core commands belong to an internal module named \fBsys\fR. All other
modules are packaged as dynamically loadable sharable objects. \fBelfedit\fR
loads modules on demand, when a command that requires it is executed, or as the
result of executing the \fBsys:load\fR command. Due to its special built in
status, and because its commands are used heavily, \fBelfedit\fR allows you to
specify commands from the \fBsys\fR module without including the \fBsys:\fR
prefix, for example, \fBload\fR rather than \fBsys:load\fR. To access a command
from any other module, you must specify the full \fImodule\fR\fB:\fR\fIcmd\fR
form.
.sp
.LP
\fBelfedit\fR is delivered with the following standard modules:
.sp
.ne 2
.na
\fB\fBcap\fR\fR
.ad
.RS 11n
Capabilities Section
.RE

.sp
.ne 2
.na
\fB\fBdyn\fR\fR
.ad
.RS 11n
Dynamic Section
.RE

.sp
.ne 2
.na
\fB\fBehdr\fR\fR
.ad
.RS 11n
ELF Header
.RE

.sp
.ne 2
.na
\fB\fBphdr\fR\fR
.ad
.RS 11n
Program Header Array
.RE

.sp
.ne 2
.na
\fB\fBshdr\fR\fR
.ad
.RS 11n
Section Header Array
.RE

.sp
.ne 2
.na
\fB\fBstr\fR\fR
.ad
.RS 11n
String Table Section
.RE

.sp
.ne 2
.na
\fB\fBsym\fR\fR
.ad
.RS 11n
Symbol Table Section
.RE

.sp
.ne 2
.na
\fB\fBsyminfo\fR\fR
.ad
.RS 11n
\fBSyminfo\fR Section
.RE

.sp
.ne 2
.na
\fB\fBsys\fR\fR
.ad
.RS 11n
Core built in \fBelfedit\fR commands
.RE

.SS "Status And Command Documentation"
Status And Command Documentation
.sp
.LP
The status (\fBsys:status\fR) command displays information about the current
\fBelfedit\fR session:
.RS +4
.TP
.ie t \(bu
.el o
Input and output files
.RE
.RS +4
.TP
.ie t \(bu
.el o
Option setting
.RE
.RS +4
.TP
.ie t \(bu
.el o
Module search path
.RE
.RS +4
.TP
.ie t \(bu
.el o
Modules loaded
.RE
.sp
.LP
Included with every \fBelfedit\fR module is extensive online documentation for
every command, in a format similar to UNIX manual pages. The \fBhelp\fR
(\fBsys:help\fR) command is used to display this information. To learn more
about \fBelfedit\fR, start \fBelfedit\fR and use the help command without
arguments:
.sp
.in +2
.nf
% elfedit
> help
.fi
.in -2
.sp

.sp
.LP
\fBelfedit\fR displays a welcome message with more information about
\fBelfedit\fR, and on how to use the help system.
.sp
.LP
To obtain summary information for a module:
.sp
.in +2
.nf
> help module
.fi
.in -2
.sp

.sp
.LP
To obtain the full documentation for a specific command provided by a module:
.sp
.in +2
.nf
> help module:command
.fi
.in -2
.sp

.sp
.LP
Using the \fBdyn\fR module and \fBdyn:runpath\fR commands as examples:
.sp
.in +2
.nf
> help dyn
> help dyn:runpath
.fi
.in -2
.sp

.sp
.LP
help (\fBsys:help\fR) can be used to obtain help on itself:
.sp
.in +2
.nf
> help help
.fi
.in -2
.sp

.SS "Module Search Path"
\fBelfedit\fR modules are implemented as sharable objects which are loaded on
demand. When a module is required, \fBelfedit\fR searches a module path in
order to locate the sharable object that implements the module. The path is a
sequence of directory names delimited by colon (\fB:\fR) characters. In
addition to normal characters, the path can also contain any of the following
tokens:
.sp
.ne 2
.na
\fB\fB%i\fR\fR
.ad
.RS 6n
Expands to the current instruction set architecture (ISA) name (\fBsparc\fR,
\fBsparcv9\fR, \fBi386\fR, \fBamd64\fR).
.RE

.sp
.ne 2
.na
\fB\fB%I\fR\fR
.ad
.RS 6n
Expands to the 64-bit ISA. This is the same thing as \fB%i\fR for 64-bit
versions of \fBelfedit\fR, but expands to the empty string for 32-bit versions.
.RE

.sp
.ne 2
.na
\fB\fB%o\fR\fR
.ad
.RS 6n
Expands to the old value of the path being modified. This is useful for
appending or prepending directories to the default path.
.RE

.sp
.ne 2
.na
\fB\fB%r\fR\fR
.ad
.RS 6n
Root of file system tree holding the \fBelfedit\fR program, assuming that
\fBelfedit\fR is installed as \fBusr/bin/elfedit\fR within the tree. On a
standard system, this is simply the standard system root directory (\fB/\fR).
On a development system, where the copy of \fBelfedit\fR can be installed
elsewhere, the use of \fB%r\fR can be used to ensure that the matching set of
modules are used.
.RE

.sp
.ne 2
.na
\fB\fB%%\fR\fR
.ad
.RS 6n
Expands to a single \fB%\fR character
.RE

.sp
.LP
The default module search path for \fBelfedit\fR is:
.sp
.in +2
.nf
%r/usr/lib/elfedit/%I
.fi
.in -2
.sp

.sp
.LP
Expanding the tokens, this is:
.sp
.ne 2
.na
\fB\fB/usr/lib/elfedit\fR\fR
.ad
.RS 28n
32-bit \fBelfedit\fR
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/elfedit/sparcv9\fR\fR
.ad
.RS 28n
64-bit \fBelfedit\fR (\fBsparc\fR)
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/elfedit/amd64\fR\fR
.ad
.RS 28n
64-bit \fBelfedit\fR (\fBx86\fR)
.RE

.sp
.LP
The default search path can be changed by setting the \fBELFEDIT_PATH\fR
environment variable, or by using the \fB-L\fR command line option. If you
specify both, the \fB-L\fR option supersedes the environment variable.
.SH OPTIONS
The following options are supported:
.sp
.ne 2
.na
\fB\fB-a\fR\fR
.ad
.RS 29n
Enable \fBautoprint\fR mode. When \fBautoprint\fR is enabled, \fBelfedit\fR
prints the modified values that result when the ELF file is modified. This
output is shown in the current output style, which can be changed using the
\fB-o\fR option. The default output style is the style used by the
\fBelfdump\fR(1) utility. \fBautoprint\fR mode is the default when
\fBelfedit\fR is used interactively (when \fBstdin\fR and \fBstdout\fR are
terminals). Therefore, the \fB-a\fR option only has meaning when \fBelfedit\fR
is used in non-interactive contexts. To disable \fBautoprint\fR in an
interactive session, use the \fBelfedit\fR command:
.sp
.in +2
.nf
> set a off
.fi
.in -2
.sp

.RE

.sp
.ne 2
.na
\fB\fB-d\fR\fR
.ad
.RS 29n
If set, this option causes \fBelfedit\fR to issue informational messages
describing its internal operations and details of the ELF object being
processed. This can be useful when a deep understanding of the operation being
carried out is desired.
.RE

.sp
.ne 2
.na
\fB\fB-e\fR \fIcmd\fR\fR
.ad
.RS 29n
Specifies an edit command. Multiple \fB-e\fR options can be specified. If edit
commands are present on the command line, \fBelfedit\fR operates in batch mode.
After opening the file, \fBelfedit\fR executes each command in the order given,
after which the modified file is saved and \fBelfedit\fR exits. Batch mode is
useful for performing simple operations from shell scripts and makefiles.
.RE

.sp
.ne 2
.na
\fB\fB-L\fR \fIpath\fR\fR
.ad
.RS 29n
Sets default path for locating \fBelfedit\fR modules. Modules are described in
\fBModule Search Path\fR section of this manual page..
.RE

.sp
.ne 2
.na
\fB\fB-o\fR \fBdefault\fR | \fBsimple\fR | \fBnum\fR\fR
.ad
.RS 29n
The style used to display ELF data. This option establishes the current style
for the session. It can be changed from within the \fBelfedit\fR session by
using the set (\fBsys:set\fR) command, or by providing \fB-o\fR options to the
individual commands executed within the session.
.sp
.ne 2
.na
\fB\fBdefault\fR\fR
.ad
.RS 11n
The default style is to display output in a format intended for human viewing.
This style is similar to that used by the \fBelfdump\fR utility.
.RE

.sp
.ne 2
.na
\fB\fBnum\fR\fR
.ad
.RS 11n
Integer values are always shown in integer form. Strings are shown as the
integer offset into the containing string table.
.RE

.sp
.ne 2
.na
\fB\fBsimple\fR\fR
.ad
.RS 11n
When displaying strings from within the ELF file, only the string is displayed.
Integer values are displayed as symbolic constants if possible, and in integer
form otherwise. No titles, headers, or other supplemental output is shown.
.RE

.RE

.sp
.ne 2
.na
\fB\fB-r\fR\fR
.ad
.RS 29n
Read-only mode. The input file is opened for read-only access, and the results
of the edit session are not saved. \fBelfedit\fR does not allow the
\fIoutfile\fR argument when \fB-r\fR is specified. Read-only mode is highly
recommended when there is no intention to modify the file. In addition to
providing extra protection against accidental modification, it allows for the
examination of files for which the user does not have write permission.
.RE

.SH OPERANDS
The following operands are supported:
.sp
.ne 2
.na
\fB\fIinfile\fR\fR
.ad
.RS 11n
Input file containing an ELF object to process.
.sp
This can be an executable (\fBET_EXEC\fR), shared object (\fBET_DYN\fR), or
relocatable object file, (\fBET_REL\fR). Archives are not directly supported.
To edit an object in an archive, you must extract the object, edit the copy,
and then insert it back into the archive.
.sp
If no \fIinfile\fR is present, \fBelfedit\fR runs in a limited mode that only
allows executing commands from the \fBsys:\fR module. This mode is primarily to
allow access to the command documentation available from the help
(\fBsys:help\fR) command.
.sp
If \fIinfile\fR is present, and no \fIoutfile\fR is given, \fBelfedit\fR edits
the file in place, and writes the results into the same file, causing the
original file contents to be overwritten. It is usually recommended that
\fBelfedit\fR not be used in this mode, and that an output file be specified.
Once the resulting file has been tested and validated, it can be moved into the
place of the original file.
.sp
The \fB-r\fR option can be used to open \fIinfile\fR for read-only access. This
can be useful for examining an existing file that you do not wish to modify.
.RE

.sp
.ne 2
.na
\fB\fIoutfile\fR\fR
.ad
.RS 11n
Output file. If both \fIinfile\fR and \fIoutfile\fR are present, \fIinfile\fR
is opened for read-only access, and the modified object contents are written to
\fIoutfile\fR.
.RE

.SH USAGE
When supported by the system, \fBelfedit\fR runs as a 64-bit application,
capable of processing files greater than or equal to 2 Gbytes (2^31 bytes).
.sp
.LP
At startup, \fBelfedit\fR uses \fBlibelf\fR to open the input file and cache a
copy of its contents in memory for editing. It can then execute one or more
commands. A session finishes by optionally writing the modified object to the
output file, and then exiting.
.sp
.LP
If no \fIinfile\fR is present, \fBelfedit\fR runs in a limited mode that only
allows executing commands from the \fBsys\fR module. This mode is primarily to
allow access to the command documentation available from the help
(\fBsys:help\fR) command.
.sp
.LP
If one or more \fB-e\fR options are specified, the commands they supply are
executed in the order given. \fBelfedit\fR adds implicit calls to write
(\fBsys:write\fR) and quit (\fBsys:qui\fRt) immediately following the given
commands, causing the output file to be written and the \fBelfedit\fR process
to exit. This form of use is convenient in shell scripts and makefiles.
.sp
.LP
If no \fB-e\fR options are specified, \fBelfedit\fR reads commands from
\fBstdin\fR and executes them in the order given. The caller must explicitly
issue the write (\fBsys:write\fR) and quit (\fBsys:quit\fR) commands to save
their work and exit when running in this mode.
.SH EXIT STATUS
The following exit values are returned:
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 5n
Successful completion.
.RE

.sp
.ne 2
.na
\fB\fB1\fR\fR
.ad
.RS 5n
A fatal error occurred.
.RE

.sp
.ne 2
.na
\fB\fB2\fR\fR
.ad
.RS 5n
Invalid command line options were specified.
.RE

.SH EXAMPLES
In the following examples, interactive use of \fBelfedit\fR is shown with the
shell prompt (\fB%\fR) and the \fBelfedit\fR prompt (\fB>\fR). Neither of these
characters should be entered by the user.
.LP
\fBExample 1 \fRChanging the Runpath of an Executable
.sp
.LP
The following example presupposes an executable named \fBprog\fR, installed in
a bin directory that has an adjacent lib directory for sharable objects. The
following command sets the \fBrunpath\fR of that executable to the \fBlib\fR
directory:

.sp
.in +2
.nf
elfedit -e 'dyn:runpath $ORIGIN/../lib'
.fi
.in -2
.sp

.sp
.LP
The use of single quotes with the argument to the \fB-e\fR option is necessary
to ensure that the shell passes the entire command as a single argument to
\fBelfedit\fR.

.sp
.LP
Alternatively, the same operation can be done using \fBelfedit\fR in its
non-batch mode:

.sp
.in +2
.nf
% elfedit prog
> dyn:runpath $ORIGIN/../lib
     index  tag         value
       [30]  RUNPATH     0x3e6      $ORIGIN/../lib
> write
> quit
.fi
.in -2
.sp

.sp
.LP
The addition or modification of elements such as \fBrunpath\fR or needed
entries might only be achievable when \fBpadding\fR exists within the objects.
See \fBNotes\fR.

.LP
\fBExample 2 \fRRemoving a Hardware Capability Bit
.sp
.LP
Objects that require optional hardware support to run are built with a
capability section that contains a mask of bits specifying which capabilities
they need. The runtime linker (\fBld.so.1\fR) checks this mask against the
attributes of the running system to determine whether a given object is able to
be run by the current system. Programs that require abilities not available on
the system are prevented from running.

.sp
.LP
This check prevents a naive program that does not explicitly check for the
hardware support it requires from crashing in a confusing manner. However, it
can be inconvenient for a program that is written to explicitly check the
system capabilities at runtime. Such a program might have optimized code to use
when the hardware supports it while providing a generic fallback version that
can be run, albeit more slowly, otherwise. In this case, the hardware
compatibility mask prevents such a program from running on the older hardware.
In such a case, removing the relevant bit from the mask allows the program to
run.

.sp
.LP
The following example removes the \fBAV_386_SSE\fR3 hardware capability from an
x86 binary that uses the SSE3 CPU extension. This transfers responsibility for
validating the ability to use SSE3 from the runtime linker to the program
itself:

.sp
.in +2
.nf
elfedit -e 'cap:hw1 -and -cmp sse3' prog
.fi
.in -2
.sp

.LP
\fBExample 3 \fRReading Information From an Object
.sp
.LP
\fBelfedit\fR can be used to extract specific targeted information from an
object. The following shell command reads the number of section headers
contained in the file \fB/usr/bin/ls\fR:

.sp
.in +2
.nf
% SHNUM=`elfedit -r -onum -e 'ehdr:e_shnum' /usr/bin/ls`
% echo $SHNUM
29
.fi
.in -2
.sp

.sp
.LP
You might get a different value, depending on the version of Solaris and type
of machine that you are using. The \fB-r\fR option causes the file to be opened
read-only, allowing a user with ordinary access permissions to open the file,
and protecting against accidental damage to an important system executable. The
\fBnum\fR output style is used in order to obtain only the desired value,
without any extraneous text.

.sp
.LP
Similarly, the following extracts the symbol type of the symbol \fBunlink\fR
from the C runtime library:

.sp
.in +2
.nf
% TYPE=`elfedit -r -osimple -e 'sym:st_type unlink' /lib/libc.so`
% echo $TYPE
STT_FUNC
.fi
.in -2
.sp

.SH ENVIRONMENT VARIABLES
.ne 2
.na
\fB\fBELFEDIT_PATH\fR\fR
.ad
.RS 16n
Alters the default module search path. Module search paths are discussed in the
\fBModule Search Path\fR section of this manual page.
.RE

.sp
.ne 2
.na
\fB\fBLD_NOEXEC_64\fR\fR
.ad
.RS 16n
Suppresses the automatic execution of the 64-bit \fBelfedit\fR. By default, the
64-bit version of \fBelfedit\fR runs if the system is 64-bit capable.
.RE

.sp
.ne 2
.na
\fB\fBPAGER\fR\fR
.ad
.RS 16n
Interactively delivers output from \fBelfedit\fR to the screen. If not set,
\fBmore\fR is used. See \fBmore\fR(1).
.RE

.SH FILES
.ne 2
.na
\fB\fB/usr/lib/elfedit\fR\fR
.ad
.RS 20n
Default directory for \fBelfedit\fR modules that are loaded on demand to supply
editing commands.
.RE

.sp
.ne 2
.na
\fB\fB~/.teclarc\fR\fR
.ad
.RS 20n
Personal \fBtecla\fR customization file for command line editing. See
\fBtecla\fR(5).
.RE

.SH ATTRIBUTES
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
.TE

.SH SEE ALSO
\fBdump\fR(1), \fBelfdump\fR(1), \fBld.so.1\fR(1), \fBmore\fR(1), \fBnm\fR(1),
\fBpvs\fR(1), \fBelf\fR(3ELF), \fBlibelf\fR(3LIB), \fBtecla\fR(5),
\fBattributes\fR(5)
.sp
.LP
\fILinker and Libraries Guide\fR
.SH WARNINGS
\fBelfedit\fR is designed to be a tool for testing and development of the ELF
system. It offers the ability to examine and change nearly every piece of ELF
metadata in the object. It quietly allows edits that can produce an invalid or
unusable ELF file. The user is expected to have knowledge of the ELF format and
of the rules and conventions that govern them. The \fILinker and Libraries
Guide\fR can be helpful when using \fBelfedit\fR.
.sp
.LP
\fBelfedit\fR allows the user to alter the ELF metadata in an object, but
cannot understand or alter the code of the actual program. Setting ELF
attributes such as types, sizes, alignments, and so forth in a manner that does
not agree with the actual contents of the file is therefore likely to yield a
broken and unusable output object. Such changes might be useful for testing of
linker components, but should be avoided otherwise.
.sp
.LP
Higher level operations, such as the use of the \fBdyn:runpath\fR command to
change the \fBrunpath\fR of an object, are safe, and can be carried out without
the sort of risk detailed in this section.
.SH NOTES
Not every ELF operation supported by \fBelfedit\fR can be successfully carried
out on every ELF object. \fBelfedit\fR is constrained by the existing sections
found in the file.
.sp
.LP
One area of particular interest is that \fBelfedit\fR might not be able to
modify the \fBrunpath\fR of a given object. To modify a \fBrunpath\fR, the
following must be true:
.RS +4
.TP
.ie t \(bu
.el o
The desired string must already exist in the dynamic string table, or there
must be enough reserved space within this section for the new string to be
added. If your object has a string table reservation area, the value of the
\fB\&.dynamic DT_SUNW_STRPAD\fR element indicates the size of the area. The
following \fBelfedit\fR command can be used to check this:
.sp
.in +2
.nf
% elfedit -r -e 'dyn:tag DT_SUNW_STRPAD' file
.fi
.in -2
.sp

.RE
.RS +4
.TP
.ie t \(bu
.el o
The dynamic section must already have a \fBrunpath\fR element, or there must be
an unused dynamic slot available where one can be inserted. To test for the
presence of an existing \fBrunpath\fR:
.sp
.in +2
.nf
% elfedit -r -e 'dyn:runpath' file
.fi
.in -2
.sp

A dynamic section uses an element of type \fBDT_NULL\fR to terminate the array
found in that section. The final \fBDT_NULL\fR cannot be changed, but if there
are more than one of these, \fBelfedit\fR can convert one of them into a
\fBrunpath\fR element. To test for extra dynamic slots:
.sp
.in +2
.nf
% elfedit -r -e 'dyn:tag DT_NULL' file
.fi
.in -2
.sp

.RE
.sp
.LP
Older objects do not have the extra space necessary to complete such
operations. The space necessary to do so was introduced in the Solaris Express
Community Edition release.
.sp
.LP
When an operation fails, the detailed information printed using the \fB-d\fR
(debug) option can be very helpful in uncovering the reason why.
.sp
.LP
\fBelfedit\fR modules follow a convention by which commands that directly
manipulate a field in an ELF structure have the same name as the field, while
commands that implement higher level concepts do not. For instance, the command
to manipulate the \fBe_flags\fR field in the ELF header is named
\fBehdr:e_flags\fR. Therefore, you generally find the command to modify ELF
fields by identifying the module and looking for a command with the name of the
field.