summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/elfedit/modules/common/dyn.c
blob: d4949e6ee7bdb1b2bd7620b23d51228466da753c (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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
/*
 * CDDL HEADER START
 *
 * 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]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include	<ctype.h>
#include	<elfedit.h>
#include	<sys/elf_SPARC.h>
#include	<strings.h>
#include	<debug.h>
#include	<conv.h>
#include	<dyn_msg.h>


/*
 * Dynamic section
 */

/*
 * This module uses shared code for several of the commands.
 * It is sometimes necessary to know which specific command
 * is active.
 */
typedef enum {
	/* Dump command, used as module default to display dynamic section */
	DYN_CMD_T_DUMP =	0,	/* dyn:dump */

	/* Commands that do not correspond directly to a specific DT tag */
	DYN_CMD_T_TAG =		1,	/* dyn:tag */
	DYN_CMD_T_VALUE =	2,	/* dyn:value */
	DYN_CMD_T_DELETE =	3,	/* dyn:delete */
	DYN_CMD_T_MOVE =	4,	/* dyn:shift */

	/* Commands that embody tag specific knowledge */
	DYN_CMD_T_RUNPATH =	5,	/* dyn:runpath/rpath */
	DYN_CMD_T_POSFLAG1 =	6,	/* dyn:posflag1 */
	DYN_CMD_T_FLAGS =	7,	/* dyn:flags */
	DYN_CMD_T_FLAGS1 =	8,	/* dyn:flags1 */
	DYN_CMD_T_FEATURE1 =	9,	/* dyn:feature1 */
	DYN_CMD_T_CHECKSUM =	10,	/* dyn:checksum */
	DYN_CMD_T_SUNW_LDMACH =	11	/* dyn:sunw_ldmach */
} DYN_CMD_T;



#ifndef _ELF64
/*
 * We supply this function for the msg module
 */
const char *
_dyn_msg(Msg mid)
{
	return (gettext(MSG_ORIG(mid)));
}
#endif


/*
 * This function is supplied to elfedit through our elfedit_module_t
 * definition. It translates the opaque elfedit_i18nhdl_t handles
 * in our module interface into the actual strings for elfedit to
 * use.
 *
 * note:
 *	This module uses Msg codes for its i18n handle type.
 *	So the translation is simply to use MSG_INTL() to turn
 *	it into a string and return it.
 */
static const char *
mod_i18nhdl_to_str(elfedit_i18nhdl_t hdl)
{
	Msg msg = (Msg)hdl;

	return (MSG_INTL(msg));
}



/*
 * The dyn_opt_t enum specifies a bit value for every optional
 * argument allowed by a command in this module.
 */
typedef enum {
	DYN_OPT_F_ADD =		1,	/* -add: Add new elt rather than */
					/*	modifying an existing one */
	DYN_OPT_F_AND =		2,	/* -and: AND (&) values to dest */
	DYN_OPT_F_CMP =		4,	/* -cmp: Complement (~) values */
	DYN_OPT_F_DYNNDX_ELT =	8,	/* -dynndx: 1st plain arg is tag */
					/*	index, not name */
	DYN_OPT_F_DYNNDX_VAL =	16,	/* -dynndx ndx: Index is value to */
					/*	option rather than 1st plain */
					/*	arg. Used for dyn:posflag1 */
	DYN_OPT_F_NEEDED =	32,	/* -needed str: Locate DT_POSFLAG_1 */
					/*	relative to DT_NEEDED element */
	DYN_OPT_F_OR =		64,	/* -or: OR (|) values to dest */
	DYN_OPT_F_STRVAL =	128	/* -s: value is string, not integer */
} dyn_opt_t;


/*
 * A variable of type ARGSTATE is used by each command to maintain
 * information about the arguments and related things. It is
 * initialized by process_args(), and used by the other routines.
 */
typedef struct {
	elfedit_obj_state_t	*obj_state;
	elfedit_section_t	*strsec;	/* Dynamic string table ref */
	struct {
		elfedit_section_t *sec;		/* Dynamic section reference */
		Dyn	*data;			/* Start dynamic section data */
		Word	num;			/* # dynamic elts */
		Word	null_ndx;		/* Index of first DT_NULL */
		Word	num_null_ndx;		/* # of DT_NULL elements */
	} dyn;
	dyn_opt_t		optmask;	/* Mask of options used */
	int			argc;		/* # of plain arguments */
	const char		**argv;		/* Plain arguments */
	const char		*dyn_elt_str;	/* Value string for */
						/*	DYN_OPT_F_DYNNDX_VAL */
						/*	or DYN_OPT_F_NEEDED */
} ARGSTATE;



/*
 * Set argstate null_ndx field for current dynamic area
 */
static void
set_null_ndx(ARGSTATE *argstate)
{
	Word	num, null_ndx;

	num = argstate->dyn.num;
	argstate->dyn.num_null_ndx = 0;
	for (null_ndx = 0; null_ndx < num; null_ndx++)
		if (argstate->dyn.data[null_ndx].d_tag == DT_NULL) {
			argstate->dyn.num_null_ndx++;
			break;
		}
	argstate->dyn.null_ndx = null_ndx;

	/* Count the number of remaining DT_NULL items */
	for (; null_ndx < num; null_ndx++)
		if (argstate->dyn.data[null_ndx].d_tag == DT_NULL)
			argstate->dyn.num_null_ndx++;
}


/*
 * Convert the first available DT_NULL slot in the dynamic section
 * into something else.
 *
 * entry:
 *	argstate - Argument state block
 *	d_tag, d_val - Values to be set in new element
 *
 * exit:
 *	If an extra DT_NULL slot is available, a debug message is
 *	issued, the slot is converted to its new use, and the argstate
 *	block state related to DT_NULL slots is updated.
 *
 *	if no extra DT_NULL slot is present, an error is issued and
 *	this routine does not return to the caller.
 */
static Word
convert_dt_null(ARGSTATE *argstate, Xword d_tag, Xword d_val)
{
	Conv_inv_buf_t inv_buf;
	Word	ndx;
	Dyn	*dyn;
	Ehdr	*ehdr;

	/* If we lack an extra element, we can't continue */
	if (argstate->dyn.num_null_ndx <= 1)
		elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_NOEXTRANULL),
		    EC_WORD(argstate->dyn.sec->sec_shndx),
		    argstate->dyn.sec->sec_name);

	ehdr = argstate->obj_state->os_ehdr;
	elfedit_msg(ELFEDIT_MSG_DEBUG, MSG_INTL(MSG_DEBUG_CONVNULL),
	    EC_WORD(argstate->dyn.sec->sec_shndx), argstate->dyn.sec->sec_name,
	    EC_WORD(argstate->dyn.null_ndx), conv_dyn_tag(d_tag,
	    ehdr->e_ident[EI_OSABI], ehdr->e_machine, 0, &inv_buf));

	ndx = argstate->dyn.null_ndx;
	dyn = &argstate->dyn.data[ndx];
	dyn->d_tag = d_tag;
	dyn->d_un.d_val = d_val;

	/* Recompute the DT_NULL situation */
	set_null_ndx(argstate);

	return (ndx);
}


/*
 * Standard argument processing for dyn module
 *
 * entry
 *	obj_state, argc, argv - Standard command arguments
 *	argstate - Address of ARGSTATE block to be initialized
 *
 * exit:
 *	On success, *argstate is initialized. On error,
 *	an error is issued and this routine does not return.
 */
static void
process_args(elfedit_obj_state_t *obj_state, int argc, const char *argv[],
    ARGSTATE *argstate)
{
	elfedit_getopt_state_t	getopt_state;
	elfedit_getopt_ret_t	*getopt_ret;

	bzero(argstate, sizeof (*argstate));
	argstate->obj_state = obj_state;

	elfedit_getopt_init(&getopt_state, &argc, &argv);

	/* Add each new option to the options mask */
	while ((getopt_ret = elfedit_getopt(&getopt_state)) != NULL) {
		argstate->optmask |= getopt_ret->gor_idmask;
		switch (getopt_ret->gor_idmask) {
		case DYN_OPT_F_DYNNDX_VAL:
		case DYN_OPT_F_NEEDED:
			argstate->dyn_elt_str = getopt_ret->gor_value;
			break;
		}
	}

	/* If there may be an arbitrary amount of output, use a pager */
	if (argc == 0)
		elfedit_pager_init();

	/* Return the updated values of argc/argv */
	argstate->argc = argc;
	argstate->argv = argv;

	/* Locate the dynamic section, and the assocated string table */
	argstate->dyn.sec = elfedit_sec_getdyn(obj_state, &argstate->dyn.data,
	    &argstate->dyn.num);
	argstate->strsec = elfedit_sec_getstr(obj_state,
	    argstate->dyn.sec->sec_shdr->sh_link, 0);

	/* Index of first DT_NULL */
	set_null_ndx(argstate);
}

/*
 * Print ELF header values, taking the calling command, and output style
 * into account.
 *
 * entry:
 *	cmd - DYN_CMD_T_* value giving identify of caller
 *	autoprint - If True, output is only produced if the elfedit
 *		autoprint flag is set. If False, output is always produced.
 *	argstate - Argument state block
 *	print_type - Specifies which dynamic elements to display.
 *	arg - If print_type is PRINT_DYN_T_NDX, displays the index specified.
 *		Otherwise ignored.
 */
typedef enum {
	PRINT_DYN_T_ALL =	0,	/* Show all indexes */
	PRINT_DYN_T_NDX =	1,	/* Show dynamic[arg] only */
	PRINT_DYN_T_TAG =	2,	/* Show all elts with tag type */
					/*	given by arg */
	PRINT_DYN_T_RUNPATH =	3	/* Show all runpath/rpath elts */

} PRINT_DYN_T;

static void
print_dyn(DYN_CMD_T cmd, int autoprint, ARGSTATE *argstate,
    PRINT_DYN_T print_type, Word arg)
{
	elfedit_outstyle_t	outstyle;
	Conv_fmt_flags_t	flags_fmt_flags;
	Word	end_ndx, ndx, printed = 0;
	Dyn	*dyn;
	int	header_done = 0;
	Xword	last_d_val;
	int	one_shot;
	int	osabi_solaris;

	if (autoprint && ((elfedit_flags() & ELFEDIT_F_AUTOPRINT) == 0))
		return;

	osabi_solaris =
	    elfedit_test_osabi(argstate->obj_state, ELFOSABI_SOLARIS, 0);

	/*
	 * Pick an output style. dyn:dump is required to use the default
	 * style. The other commands use the current output style.
	 */
	outstyle = (cmd == DYN_CMD_T_DUMP) ?
	    ELFEDIT_OUTSTYLE_DEFAULT : elfedit_outstyle();

	/*
	 * When using the simple output style, omit the
	 * brackets from around the values.
	 */
	flags_fmt_flags = (outstyle == ELFEDIT_OUTSTYLE_SIMPLE) ?
	    CONV_FMT_NOBKT : 0;

	/* Starting index */
	if (print_type == PRINT_DYN_T_NDX) {
		if (arg >= argstate->dyn.num)
			return;		/* Out of range */
		ndx = arg;
	} else {
		ndx = 0;
	}

	/*
	 * one_shot is used by positional elements (e.g. DT_POSFLAG_1)
	 * to get the item following them to be shown even if they
	 * are not of the desired tag type or the count of elements
	 * to be displayed is only 1.
	 */
	one_shot = 0;

	dyn = &argstate->dyn.data[ndx];

	/*
	 * Loop predicate explanation:
	 * Normally, we want to iterate from the starting index
	 * to the end. However, in the case of PRINT_DYN_T_NDX, we
	 * only want to display one item (ndx == arg) and then quit,
	 * with the exception that if we've been through the loop
	 * and encountered a one_shot situation, we want to continue
	 * iterating until the one-shot situation is cleared.
	 */
	for (; (ndx < argstate->dyn.num) &&
	    ((print_type != PRINT_DYN_T_NDX) || ((ndx == arg) || one_shot));
	    dyn++, ndx++) {
		union {
			Conv_inv_buf_t		inv;
			Conv_dyn_flag_buf_t	flag;
			Conv_dyn_flag1_buf_t	flag1;
			Conv_dyn_posflag1_buf_t	posflag1;
			Conv_dyn_feature1_buf_t	feature1;
		} c_buf;
		const char	*name;

		if (one_shot) {
			one_shot = 0;
		} else {
			/*
			 * If we are only displaying certain tag types and
			 * this isn't one of those, move on to next element.
			 */
			switch (print_type) {
			case PRINT_DYN_T_TAG:
				if (dyn->d_tag != arg)
					continue;
				break;
			case PRINT_DYN_T_RUNPATH:
				if ((dyn->d_tag != DT_RPATH) &&
				    (dyn->d_tag != DT_RUNPATH))
					continue;
				break;
			}
		}

		/*
		 * Print the information numerically, and if possible
		 * as a string.
		 */
		name = NULL;
		switch (dyn->d_tag) {
		case DT_NULL:
			if (!((outstyle == ELFEDIT_OUTSTYLE_DEFAULT) &&
			    (print_type == PRINT_DYN_T_ALL) &&
			    (dyn->d_un.d_val == 0)))
				break;
			end_ndx = ndx;
			/*
			 * Special case: DT_NULLs can come in groups
			 * that we prefer to reduce to a single line.
			 */
			while ((end_ndx < (argstate->dyn.num - 1)) &&
			    ((dyn + 1)->d_tag == DT_NULL) &&
			    ((dyn + 1)->d_un.d_val == 0)) {
				dyn++;
				end_ndx++;
			}
			if (header_done == 0) {
				header_done = 1;
				Elf_dyn_title(0);
			}
			Elf_dyn_null_entry(0, dyn, ndx, end_ndx);
			ndx = end_ndx;
			printed = 1;
			last_d_val = dyn->d_un.d_val;
			continue;

		/*
		 * Print the information numerically, and if possible
		 * as a string.
		 */
		case DT_NEEDED:
		case DT_SONAME:
		case DT_FILTER:
		case DT_AUXILIARY:
		case DT_CONFIG:
		case DT_RPATH:
		case DT_RUNPATH:
		case DT_USED:
		case DT_DEPAUDIT:
		case DT_AUDIT:
			name = elfedit_offset_to_str(argstate->strsec,
			    dyn->d_un.d_val, ELFEDIT_MSG_DEBUG, 0);
			break;
		case DT_SUNW_AUXILIARY:
		case DT_SUNW_FILTER:
			if (osabi_solaris)
				name = elfedit_offset_to_str(argstate->strsec,
				    dyn->d_un.d_val, ELFEDIT_MSG_DEBUG, 0);
			break;

		case DT_FLAGS:
			name = conv_dyn_flag(dyn->d_un.d_val,
			    flags_fmt_flags, &c_buf.flag);
			break;
		case DT_FLAGS_1:
			name = conv_dyn_flag1(dyn->d_un.d_val,
			    flags_fmt_flags, &c_buf.flag1);
			break;
		case DT_POSFLAG_1:
			/*
			 * If this is dyn:posflag1, and the print_type
			 * is PRINT_DYN_T_TAG, and the -needed option is
			 * used, then don't show any DT_POSFLAG_1 elements
			 * that are not followed by a DT_NEEDED element
			 * that matches the -needed string.
			 */
			if ((cmd == DYN_CMD_T_POSFLAG1) &&
			    (print_type == PRINT_DYN_T_TAG) &&
			    ((argstate->optmask & DYN_OPT_F_NEEDED) != 0) &&
			    ((ndx + 1) < argstate->dyn.num)) {
				Dyn *dyn1 = &argstate->dyn.data[ndx + 1];

				if (dyn1->d_tag != DT_NEEDED)
					continue;
				name = elfedit_offset_to_str(argstate->strsec,
				    dyn1->d_un.d_val, ELFEDIT_MSG_DEBUG, 0);
				if (strncmp(name, argstate->dyn_elt_str,
				    strlen(argstate->dyn_elt_str)) != 0)
					continue;
			}

			name = conv_dyn_posflag1(dyn->d_un.d_val,
			    flags_fmt_flags, &c_buf.posflag1);
			/*
			 * DT_POSFLAG_1 is a positional element that affects
			 * the following item. If using the default output
			 * style, then show the following item as well.
			 */
			one_shot = (outstyle == ELFEDIT_OUTSTYLE_DEFAULT);
			break;
		case DT_FEATURE_1:
			name = conv_dyn_feature1(dyn->d_un.d_val,
			    flags_fmt_flags, &c_buf.feature1);
			break;
		case DT_DEPRECATED_SPARC_REGISTER:
			name = MSG_INTL(MSG_STR_DEPRECATED);
			break;
		case DT_SUNW_LDMACH:
			if (osabi_solaris)
				name = conv_ehdr_mach((Half)dyn->d_un.d_val, 0,
				    &c_buf.inv);
			break;
		}

		if (outstyle == ELFEDIT_OUTSTYLE_DEFAULT) {
			Ehdr	*ehdr;

			if (header_done == 0) {
				header_done = 1;
				Elf_dyn_title(0);
			}
			if (name == NULL)
				name = MSG_ORIG(MSG_STR_EMPTY);
			ehdr = argstate->obj_state->os_ehdr;
			Elf_dyn_entry(0, dyn, ndx, name,
			    ehdr->e_ident[EI_OSABI], ehdr->e_machine);
		} else {
			/*
			 * In simple or numeric mode under a print type
			 * that is based on tag type rather than on index,
			 * if there are more than one qualifying tag, we
			 * want to skip printing redundant information.
			 */
			switch (print_type) {
			case PRINT_DYN_T_TAG:
				switch (dyn->d_tag) {
				case DT_NEEDED:
					/* Multiple NEEDED entries are normal */
					break;
				case DT_POSFLAG_1:
					/*
					 * Positional flags don't count,
					 * because each one affects a different
					 * item. Don't skip those even if they
					 * have duplicate values.
					 */
					break;
				default:
					/*
					 * Anything else: If we've already
					 * printed this value, don't print
					 * it again.
					 */
					if (printed &&
					    (last_d_val == dyn->d_un.d_val))
						continue;
				}
				break;
			case PRINT_DYN_T_RUNPATH:
				/*
				 * If we've already printed this value,
				 * don't print it again. This commonly
				 * happens when both DT_RPATH and DT_RUNPATH
				 * are present with the same value.
				 */
				if (printed && (last_d_val == dyn->d_un.d_val))
					continue;
				break;
			}

			if ((name != NULL) &&
			    (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)) {
				elfedit_printf(MSG_ORIG(MSG_FMT_STRNL), name);
			} else {
				elfedit_printf(MSG_ORIG(MSG_FMT_HEXXWORDNL),
				    EC_XWORD(dyn->d_un.d_val));
			}
		}
		printed = 1;
		last_d_val = dyn->d_un.d_val;
	}

	/*
	 * If nothing was output under the print types that are
	 * based on tag type, issue an error saying it doesn't exist.
	 */
	if (!printed) {
		if (print_type == PRINT_DYN_T_TAG) {
			Conv_inv_buf_t	inv_buf;
			Ehdr		*ehdr = argstate->obj_state->os_ehdr;

			elfedit_msg(ELFEDIT_MSG_ERR,
			    MSG_INTL(MSG_ERR_NODYNELT),
			    EC_WORD(argstate->dyn.sec->sec_shndx),
			    argstate->dyn.sec->sec_name, conv_dyn_tag(arg,
			    ehdr->e_ident[EI_OSABI], ehdr->e_machine,
			    0, &inv_buf));
		}

		if (print_type == PRINT_DYN_T_RUNPATH)
			elfedit_msg(ELFEDIT_MSG_ERR,
			    MSG_INTL(MSG_ERR_NORUNPATH),
			    EC_WORD(argstate->dyn.sec->sec_shndx),
			    argstate->dyn.sec->sec_name);
	}
}


/*
 * Determine the index(s) of the dynamic element(s) to be displayed and/or
 * manipulated.
 *
 * entry:
 *	argstate - Argument state block
 *	arg - If the command being called accepts a first plain argument
 *		named 'elt' which is used to specify the dynamic element,
 *		arg is the value of argv[0] for that command. If the
 *		command does not accept an 'elt' argument and instead
 *		implicitly assumes a tag type, arg is the constant string
 *		for that type (e.g. "DT_POSFLAG_1").
 *	print_request - True if the command is to print the current
 *		value(s) and return without changing anything.
 *	print_type - Address of variable containing PRINT_DYN_T_
 *		code specifying how the elements will be displayed.
 *
 * exit:
 *	If print_request is False: This routine always returns the index
 *	of a single dynamic element. *print_type is set to PRINT_DYN_T_NDX.
 *	The 'elt' argument as well as any modifier options (-dynndx, -needed)
 *	are examined to determine this index. If there are no modifier options,
 *	the dynamic section contains no element of the desired type, and there
 *	is an extra DT_NULL element in the section, then a new element of
 *	the desired type is created and its index returned. Otherwise an
 *	error is issued.
 *
 *	If print_request is True: If a modifier (-dynndx, -needed) was used,
 *	*print_type is set to PRINT_DYN_T_NDX and the index of the
 *	corresponding single dynamic element is returned. If no modifier
 *	was used, *print_type is set to PRINT_DYN_T_TAG, and the tag
 *	type code is returned.
 */
static Word
arg_to_index(ARGSTATE *argstate, const char *arg,
    int print_request, PRINT_DYN_T *print_type)
{
	Word	ndx;
	Xword	dt_value;
	Dyn	*dyn;


	/* Assume we are returning an index, alter as needed below */
	*print_type = PRINT_DYN_T_NDX;

	/*
	 * All the commands that accept the DYN_OPT_F_DYNNDX_ELT form
	 * of -dynndx require a plain argument named 'elt' as their first
	 * argument. -dynndx is a modifier that means that 'elt' is a
	 * simple numeric section index. Routines that accept this form
	 * of -dynndx are willing to handle any tag type, so all we need
	 * to check is that the value is in range.
	 */
	if ((argstate->optmask & DYN_OPT_F_DYNNDX_ELT) != 0)
		return ((Word) elfedit_atoui_range(arg, MSG_ORIG(MSG_STR_ELT),
		    0, argstate->dyn.num - 1, NULL));

	/* arg is a DT_ tag type, not a numeric index */
	dt_value = (Word) elfedit_atoconst(arg, ELFEDIT_CONST_DT);

	/*
	 * Commands that accept the DYN_OPT_F_DYNNDX_VAL form  of
	 * dynndx do not accept the 'elt' argument. The index is a
	 * value that follows the option, and was saved in argstate by
	 * process_args(). Routines that accept this form of -dynndx
	 * require the specified element to have a specific tag type,
	 * so we test for this as well as for the index being in range.
	 */
	if ((argstate->optmask & DYN_OPT_F_DYNNDX_VAL) != 0) {
		ndx = ((Word) elfedit_atoui_range(argstate->dyn_elt_str,
		    MSG_ORIG(MSG_STR_INDEX), 0, argstate->dyn.num - 1, NULL));
		if (argstate->dyn.data[ndx].d_tag != dt_value) {
			Ehdr	*ehdr = argstate->obj_state->os_ehdr;
			uchar_t	osabi = ehdr->e_ident[EI_OSABI];
			Half	mach = ehdr->e_machine;
			Conv_inv_buf_t	is, want;

			elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_WRONGTAG),
			    EC_WORD(argstate->dyn.sec->sec_shndx),
			    argstate->dyn.sec->sec_name, ndx,
			    conv_dyn_tag(dt_value, osabi, mach, 0, &want),
			    conv_dyn_tag(argstate->dyn.data[ndx].d_tag,
			    osabi, mach, 0, &is));
		}
		return (ndx);
	}

	/*
	 * If this is a printing request, then we let print_dyn() show
	 * all the items with this tag type.
	 */
	if (print_request) {
		*print_type = PRINT_DYN_T_TAG;
		return (dt_value);
	}

	/*
	 * Commands that accept -needed are looking for the dt_value element
	 * (usually DT_POSFLAG_1) that immediately preceeds the DT_NEEDED
	 * element with the string given by argstate->dyn_elt_str.
	 */
	if ((argstate->optmask & DYN_OPT_F_NEEDED) != 0) {
		Word	retndx = argstate->dyn.num;	/* Out of range value */
		const char	*name;
		size_t		len;

		len = strlen(argstate->dyn_elt_str);
		for (ndx = 0, dyn = argstate->dyn.data;
		    ndx < argstate->dyn.num; dyn++, ndx++) {
			/*
			 * If the immediately preceeding item has the
			 * tag type we're looking for, and the current item
			 * is a DT_NEEDED with a string that matches,
			 * then the preceeding item is the one we want.
			 */
			if ((dyn->d_tag == DT_NEEDED) &&
			    (ndx > 0) && (retndx == (ndx - 1))) {
				name = elfedit_offset_to_str(argstate->strsec,
				    dyn->d_un.d_val, ELFEDIT_MSG_DEBUG, 0);

				if (strncmp(name,
				    argstate->dyn_elt_str, len) == 0)
					return (retndx);
				continue;
			}

			/*
			 * If the current item has the tag type we're
			 * looking for, make it our current candidate.
			 * If the next item is a DT_NEEDED with the right
			 * string value, we'll use it then.
			 */
			if (dyn->d_tag == dt_value)
				retndx = ndx;
		}

		/* If we get here, no matching DT_NEEDED was found */
		elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_NEEDEDNOMATCH),
		    EC_WORD(argstate->dyn.sec->sec_shndx),
		    argstate->dyn.sec->sec_name, argstate->dyn_elt_str);
	}

	/* Locate the first entry with the given tag type */
	for (ndx = 0; ndx < argstate->dyn.num; ndx++) {
		if (argstate->dyn.data[ndx].d_tag == dt_value) {
			elfedit_msg(ELFEDIT_MSG_DEBUG,
			    MSG_INTL(MSG_DEBUG_DT2NDX),
			    EC_WORD(argstate->dyn.sec->sec_shndx),
			    argstate->dyn.sec->sec_name, EC_WORD(ndx), arg);
			return (ndx);
		}
	}

	/* Not found. Can we create one? */
	if (argstate->dyn.num_null_ndx > 1)
		return (convert_dt_null(argstate, dt_value, 0));

	/* No room to create one, so we're out of options and must fail */
	elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_NODTELT),
	    EC_WORD(argstate->dyn.sec->sec_shndx),
	    argstate->dyn.sec->sec_name, arg);

	/*NOTREACHED*/
	return (0);		/* For lint */
}


/*
 * Called by cmd_body() for dyn:value. Implements the core functionality
 * for that command.
 *
 * This routine expects that both the index and value arguments are
 * present.
 */
static elfedit_cmdret_t
cmd_body_value(ARGSTATE *argstate, Word *ret_ndx)
{
	elfedit_section_t	*dynsec = argstate->dyn.sec;
	elfedit_section_t	*strsec = argstate->strsec;
	elfedit_dyn_elt_t	strpad_elt;
	Word	i;
	Dyn	*dyn = argstate->dyn.data;
	Word	numdyn = argstate->dyn.num;
	int	minus_add, minus_s, minus_dynndx;
	Word	tmp_val;
	Xword	arg1, arg2;
	int	arg2_known = 1;

	minus_add = ((argstate->optmask & DYN_OPT_F_ADD) != 0);
	minus_s = ((argstate->optmask & DYN_OPT_F_STRVAL) != 0);
	minus_dynndx = ((argstate->optmask & DYN_OPT_F_DYNNDX_ELT) != 0);

	elfedit_dyn_elt_init(&strpad_elt);

	/*
	 * The first argument is an index if -dynndx is used, and is a
	 * tag value otherwise.
	 */
	arg1 = minus_dynndx ?
	    elfedit_atoui_range(argstate->argv[0], MSG_ORIG(MSG_STR_ELT),
	    0, numdyn - 1, NULL) :
	    elfedit_atoconst(argstate->argv[0], ELFEDIT_CONST_DT);

	if (minus_s) {
		/*
		 * Don't allow the user to specify -s when manipulating a
		 * DT_SUNW_STRPAD element. Since DT_SUNW_STRPAD is used to
		 * manage the extra space used for strings, this would break
		 * our ability to add the string.
		 */
		if ((!minus_dynndx && (arg1 == DT_SUNW_STRPAD)) ||
		    (minus_dynndx && (dyn[arg1].d_tag == DT_SUNW_STRPAD)))
			elfedit_msg(ELFEDIT_MSG_ERR,
			    MSG_INTL(MSG_ERR_STRPADSTRVAL),
			    EC_WORD(dynsec->sec_shndx), dynsec->sec_name);

		/* Locate DT_SUNW_STRPAD element if present */
		strpad_elt.dn_dyn.d_un.d_val = 0;
		(void) elfedit_dynstr_getpad(argstate->obj_state,
		    argstate->dyn.sec, &strpad_elt);

		/*
		 * Look up the string: If the user specified the -dynndx
		 * -option, then we will insert it if possible, and
		 * fail with an error if not. However, if they did not
		 * specify -dynndx, we want to look up the string if it is
		 * already there, but defer the insertion. The reason for
		 * this is that we may have to grab an unused DT_NULL element
		 * below, and if there are none available, we won't want
		 * to have modified the string table.
		 *
		 * This isn't a problem, because if the string isn't
		 * in the string table, it can't be used by a dynamic element.
		 * Hence, we don't need to insert it to know that there is
		 * no match.
		 */
		if (minus_dynndx == 0) {
			if (elfedit_sec_findstr(strsec,
			    strpad_elt.dn_dyn.d_un.d_val, argstate->argv[1],
			    &tmp_val) == 0) {
				arg2_known = 0;
			} else {
				arg2 = tmp_val;
			}
		} else {
			arg2 = elfedit_dynstr_insert(dynsec, strsec,
			    &strpad_elt, argstate->argv[1]);
		}
	} else {		/* Argument 2 is an integer */
		arg2 = elfedit_atoui(argstate->argv[1], NULL);
	}


	if (!minus_dynndx && !(minus_add && !arg2_known)) {
		/*
		 * Search the dynamic section and see if an item with the
		 * specified tag value already exists. We can reduce this
		 * to a simple update of an existing value if -add is not
		 * specified or the existing d_un value matches the new one.
		 *
		 * In either of these cases, we will change arg1 to be the
		 * index, and set minus_dynndx, causing the simple update to
		 * happen immediately below.
		 */
		for (i = 0; i < numdyn; i++) {
			if ((dyn[i].d_tag == arg1) &&
			    (!minus_add || (dyn[i].d_un.d_val == arg2))) {
				arg1 = i;
				minus_dynndx = 1;
				break;
			}
		}
	}

	/*
	 * If -dynndx is used, then this is a relatively simple
	 * operation, as we simply write over the specified index.
	 */
	if (minus_dynndx) {
		/*
		 * If we held back from inserting a new string into
		 * the dynstr above, we insert it now, because we
		 * have a slot in the dynamic section, and we need
		 * the string offset ot finish.
		 */
		if (!arg2_known)
			arg2 = elfedit_dynstr_insert(dynsec, strsec,
			    &strpad_elt, argstate->argv[1]);

		*ret_ndx = arg1;
		if (dyn[arg1].d_un.d_val == arg2) {
			elfedit_msg(ELFEDIT_MSG_DEBUG,
			    MSG_INTL(MSG_DEBUG_X_OK),
			    dynsec->sec_shndx, dynsec->sec_name,
			    EC_WORD(arg1), EC_XWORD(arg2));
			return (ELFEDIT_CMDRET_NONE);
		} else {
			/* Warn if setting DT_NULL value to non-zero */
			if ((dyn[arg1].d_tag == DT_NULL) && (arg2 != 0))
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_DTNULLVALUE),
				    dynsec->sec_shndx, dynsec->sec_name,
				    EC_WORD(arg1), EC_XWORD(arg2));

			elfedit_msg(ELFEDIT_MSG_DEBUG,
			    MSG_INTL(MSG_DEBUG_X_CHG),
			    dynsec->sec_shndx, dynsec->sec_name,
			    EC_WORD(arg1), EC_XWORD(dyn[arg1].d_un.d_val),
			    EC_XWORD(arg2));
			dyn[arg1].d_un.d_val = arg2;
			return (ELFEDIT_CMDRET_MOD);
		}
	}

	/*
	 * We need a new slot in the dynamic section. If we can't have
	 * one, then we fail.
	 */
	if (argstate->dyn.num_null_ndx <= 1)
		elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_NOEXTRANULL),
		    EC_WORD(dynsec->sec_shndx), dynsec->sec_name);

	/*
	 * If we still need to insert a new string into the dynstr,
	 * then it is safe now, because if we succeed, we know that
	 * there is an available slot to receive it. If we fail, we
	 * haven't claimed the extra slot yet, and it will be unharmed.
	 */
	if (!arg2_known)
		arg2 = elfedit_dynstr_insert(dynsec, strsec,
		    &strpad_elt, argstate->argv[1]);

	/* Use an extra DT_NULL slot and enter the new element */
	*ret_ndx = convert_dt_null(argstate, arg1, arg2);
	return (ELFEDIT_CMDRET_MOD);
}



/*
 * Called by cmd_body() for dyn:runpath. Implements the core functionality
 * for that command.
 *
 * History Lesson And Strategy:
 *
 * This routine handles both DT_RPATH and DT_RUNPATH entries, altering
 * either or both if they are present.
 *
 * The original SYSV ABI only had DT_RPATH, and the runtime loader used
 * it to search for things in the following order:
 *
 *	DT_RPATH, LD_LIBRARY_PATH, defaults
 *
 * Solaris did not follow this rule, an extremely rare deviation from
 * the ABI. Environment variables should supercede everything else,
 * otherwise they are not very useful. This decision was made at the
 * very beginning of the SunOS 5.x development, so we have always
 * deviated from the ABI and and instead search in the order
 *
 *	LD_LIBRARY_PATH, DT_RPATH, defaults
 *
 * Other Unix variants initially followed the ABI, but in recent years
 * have come to agree with the early Solaris folks that it was a mistake.
 * Hence, DT_RUNPATH was invented, with the search order:
 *
 *	LD_LIBRARY_PATH, DT_RUNPATH, defaults
 *
 * So for Solaris, DT_RPATH and DT_RUNPATH mean the same thing. If both
 * are present (which does happen), we set them both to the new
 * value. If either one is present, we set that one. If neither is
 * present, and we have a spare DT_NULL slot, we create a DT_RUNPATH, but
 * not a DT_RPATH, to conserve available slots for other uses.
 */
static elfedit_cmdret_t
cmd_body_runpath(ARGSTATE *argstate)
{
	elfedit_section_t	*dynsec = argstate->dyn.sec;
	elfedit_section_t	*strsec = argstate->strsec;
	elfedit_dyn_elt_t	rpath_elt;
	elfedit_dyn_elt_t	runpath_elt;
	elfedit_dyn_elt_t	strpad_elt;
	Word			i;
	Dyn			*dyn = argstate->dyn.data;
	Word			numdyn = argstate->dyn.num;

	/* Go through the tags and gather what we need */
	elfedit_dyn_elt_init(&rpath_elt);
	elfedit_dyn_elt_init(&runpath_elt);
	elfedit_dyn_elt_init(&strpad_elt);
	for (i = 0; i < numdyn; i++) {
		switch (dyn[i].d_tag) {
		case DT_RPATH:
			elfedit_dyn_elt_save(&rpath_elt, i, &dyn[i]);
			break;

		case DT_RUNPATH:
			elfedit_dyn_elt_save(&runpath_elt, i, &dyn[i]);
			break;

		case DT_SUNW_STRPAD:
			if (elfedit_test_osabi(argstate->obj_state,
			    ELFOSABI_SOLARIS, 0))
				elfedit_dyn_elt_save(&strpad_elt, i, &dyn[i]);
			break;
		}
	}

	/*  Do we have an available dynamic section entry to use? */
	if (rpath_elt.dn_seen || runpath_elt.dn_seen) {
		/*
		 * We have seen a DT_RPATH, or a DT_RUNPATH, or both.
		 * If all of these have the same string as the desired
		 * new value, then we don't need to alter anything and can
		 * simply return. Otherwise, we'll modify them all to have
		 * the new string (below).
		 */
		if ((!rpath_elt.dn_seen ||
		    (strcmp(elfedit_dyn_offset_to_str(strsec, &rpath_elt),
		    argstate->argv[0]) == 0)) &&
		    (!runpath_elt.dn_seen ||
		    (strcmp(elfedit_dyn_offset_to_str(strsec, &runpath_elt),
		    argstate->argv[0]) == 0))) {
			if (rpath_elt.dn_seen)
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_OLDRPATHOK),
				    EC_WORD(dynsec->sec_shndx),
				    dynsec->sec_name, EC_WORD(rpath_elt.dn_ndx),
				    elfedit_atoconst_value_to_str(
				    ELFEDIT_CONST_DT, DT_RPATH, 1));
			if (runpath_elt.dn_seen)
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_OLDRPATHOK),
				    EC_WORD(dynsec->sec_shndx),
				    dynsec->sec_name,
				    EC_WORD(runpath_elt.dn_ndx),
				    elfedit_atoconst_value_to_str(
				    ELFEDIT_CONST_DT, DT_RUNPATH, 1));
			return (ELFEDIT_CMDRET_NONE);
		}
	} else if (argstate->dyn.num_null_ndx <= 1) {
		/*
		 * There is no DT_RPATH or DT_RUNPATH in the dynamic array,
		 * and there are no extra DT_NULL entries that we can
		 * convert into one. We cannot proceed.
		 */
		elfedit_msg(ELFEDIT_MSG_ERR, MSG_INTL(MSG_ERR_NOEXTRANULL),
		    EC_WORD(dynsec->sec_shndx), dynsec->sec_name);
	}

	/* Does the string exist in the table already, or can we add it? */
	rpath_elt.dn_dyn.d_un.d_val = runpath_elt.dn_dyn.d_un.d_val =
	    elfedit_dynstr_insert(dynsec, strsec, &strpad_elt,
	    argstate->argv[0]);

	/* Update DT_RPATH entry if present */
	if (rpath_elt.dn_seen) {
		elfedit_msg(ELFEDIT_MSG_DEBUG, MSG_INTL(MSG_DEBUG_PREVRPATH),
		    EC_WORD(dynsec->sec_shndx), dynsec->sec_name,
		    EC_WORD(rpath_elt.dn_ndx),
		    elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_RPATH, 1),
		    elfedit_dyn_offset_to_str(strsec, &rpath_elt));
		dyn[rpath_elt.dn_ndx] = rpath_elt.dn_dyn;
	}

	/*
	 * Update the DT_RUNPATH entry in the dynamic section, if present.
	 * If one is not present, and there is also no DT_RPATH, then
	 * we use a spare DT_NULL entry to create a new DT_RUNPATH.
	 */
	if (runpath_elt.dn_seen || !rpath_elt.dn_seen) {
		if (runpath_elt.dn_seen) {
			elfedit_msg(ELFEDIT_MSG_DEBUG,
			    MSG_INTL(MSG_DEBUG_PREVRPATH),
			    EC_WORD(dynsec->sec_shndx), dynsec->sec_name,
			    EC_WORD(runpath_elt.dn_ndx),
			    elfedit_atoconst_value_to_str(
			    ELFEDIT_CONST_DT, DT_RUNPATH, 1),
			    elfedit_dyn_offset_to_str(strsec, &runpath_elt));
			dyn[runpath_elt.dn_ndx] = runpath_elt.dn_dyn;
		} else {	/* Using a spare DT_NULL entry */
			(void) convert_dt_null(argstate, DT_RUNPATH,
			    runpath_elt.dn_dyn.d_un.d_val);
		}
	}

	return (ELFEDIT_CMDRET_MOD);
}



/*
 * Argument processing for the bitmask commands. Convert the arguments
 * to integer form, apply -and/-cmp/-or, and return the resulting value.
 *
 * entry:
 *	argstate - Argument state block
 *	orig - Value of original bitmask
 *	const_type - ELFEDIT_CONST_* value for type of constants
 */
static Word
flag_bitop(ARGSTATE *argstate, Word orig, elfedit_const_t const_type)
{
	Word flags = 0;
	int i;

	/* Collect the arguments */
	for (i = 0; i < argstate->argc; i++)
		flags |= (Word) elfedit_atoconst(argstate->argv[i], const_type);

	/* Complement the value? */
	if (argstate->optmask & DYN_OPT_F_CMP)
		flags = ~flags;

	/* Perform any requested bit operations */
	if (argstate->optmask & DYN_OPT_F_AND)
		flags &= orig;
	else if (argstate->optmask & DYN_OPT_F_OR)
		flags |= orig;

	return (flags);
}



/*
 * Common body for the dyn: module commands. These commands
 * share a large amount of common behavior, so it is convenient
 * to centralize things and use the cmd argument to handle the
 * small differences.
 *
 * entry:
 *	cmd - One of the DYN_CMD_T_* constants listed above, specifying
 *		which command to implement.
 *	obj_state, argc, argv - Standard command arguments
 */
static elfedit_cmdret_t
cmd_body(DYN_CMD_T cmd, elfedit_obj_state_t *obj_state,
    int argc, const char *argv[])
{
	ARGSTATE		argstate;
	Dyn			*dyn;
	const char		*dyn_name;
	Word			dyn_ndx, dyn_num, null_ndx;
	elfedit_cmdret_t	ret = ELFEDIT_CMDRET_NONE;
	PRINT_DYN_T		print_type = PRINT_DYN_T_ALL;
	Word			ndx;
	int			print_only = 0;
	int			do_autoprint = 1;

	/* Process the optional arguments */
	process_args(obj_state, argc, argv, &argstate);

	dyn = argstate.dyn.data;
	dyn_num = argstate.dyn.num;
	dyn_name = argstate.dyn.sec->sec_name;
	dyn_ndx = argstate.dyn.sec->sec_shndx;

	/* Check number of arguments, gather information */
	switch (cmd) {
	case DYN_CMD_T_DUMP:
		/* dyn:dump can accept an optional index argument */
		if (argstate.argc > 1)
			elfedit_command_usage();
		print_only = 1;
		if (argstate.argc == 1)
			ndx = arg_to_index(&argstate, argstate.argv[0],
			    print_only, &print_type);
		break;

	case DYN_CMD_T_TAG:
		print_only = (argstate.argc != 2);
		if (argstate.argc > 0) {
			if (argstate.argc > 2)
				elfedit_command_usage();
			ndx = arg_to_index(&argstate, argstate.argv[0],
			    print_only, &print_type);
		}
		break;

	case DYN_CMD_T_VALUE:
		print_only = (argstate.argc != 2);
		if (argstate.argc > 2)
			elfedit_command_usage();
		if (argstate.argc > 0) {
			if (print_only) {
				ndx = arg_to_index(&argstate, argstate.argv[0],
				    print_only, &print_type);
			} else {
				print_type = PRINT_DYN_T_NDX;
			}
		}
		break;

	case DYN_CMD_T_DELETE:
		if ((argstate.argc < 1) || (argstate.argc > 2))
			elfedit_command_usage();
		ndx = arg_to_index(&argstate, argstate.argv[0],
		    0, &print_type);
		do_autoprint = 0;
		break;

	case DYN_CMD_T_MOVE:
		if ((argstate.argc < 2) || (argstate.argc > 3))
			elfedit_command_usage();
		ndx = arg_to_index(&argstate, argstate.argv[0],
		    0, &print_type);
		do_autoprint = 0;
		break;

	case DYN_CMD_T_RUNPATH:
		if (argstate.argc > 1)
			elfedit_command_usage();
		/*
		 * dyn:runpath does not accept an explicit index
		 * argument, so we implicitly only show the DT_RPATH and
		 * DT_RUNPATH elements.
		 */
		print_type = PRINT_DYN_T_RUNPATH;
		print_only = (argstate.argc == 0);
		break;

	case DYN_CMD_T_POSFLAG1:
		print_only = (argstate.argc == 0);
		ndx = arg_to_index(&argstate, elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_POSFLAG_1, 1),
		    print_only, &print_type);
		break;

	case DYN_CMD_T_FLAGS:
		print_only = (argstate.argc == 0);
		ndx = arg_to_index(&argstate, elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_FLAGS, 1),
		    print_only, &print_type);
		break;

	case DYN_CMD_T_FLAGS1:
		print_only = (argstate.argc == 0);
		ndx = arg_to_index(&argstate, elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_FLAGS_1, 1),
		    print_only, &print_type);
		break;

	case DYN_CMD_T_FEATURE1:
		print_only = (argstate.argc == 0);
		ndx = arg_to_index(&argstate, elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_FEATURE_1, 1),
		    print_only, &print_type);
		break;

	case DYN_CMD_T_CHECKSUM:
		ndx = arg_to_index(&argstate, elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_CHECKSUM, 1),
		    print_only, &print_type);
		break;

	case DYN_CMD_T_SUNW_LDMACH:
		if (argstate.argc > 1)
			elfedit_command_usage();
		/* DT_SUNW_LDMACH is an ELFOSABI_SOLARIS feature */
		(void) elfedit_test_osabi(argstate.obj_state,
		    ELFOSABI_SOLARIS, 1);
		print_only = (argstate.argc == 0);
		ndx = arg_to_index(&argstate, elfedit_atoconst_value_to_str(
		    ELFEDIT_CONST_DT, DT_SUNW_LDMACH, 1),
		    print_only, &print_type);
		break;

	default:
		/* Note expected: All commands should have been caught above */
		elfedit_command_usage();
		break;
	}


	/* If this is a request to print current values, do it and return */
	if (print_only) {
		print_dyn(cmd, 0, &argstate, print_type, ndx);
		return (ELFEDIT_CMDRET_NONE);
	}


	switch (cmd) {
		/*
		 * DYN_CMD_T_DUMP can't get here: It is a print-only
		 * command.
		 */

	case DYN_CMD_T_TAG:
		{
			Ehdr		*ehdr = argstate.obj_state->os_ehdr;
			uchar_t		osabi = ehdr->e_ident[EI_OSABI];
			Half		mach = ehdr->e_machine;
			Conv_inv_buf_t	inv_buf1, inv_buf2;
			Xword d_tag = (Xword) elfedit_atoconst(argstate.argv[1],
			    ELFEDIT_CONST_DT);

			if (dyn[ndx].d_tag == d_tag) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_OK), dyn_ndx, dyn_name,
				    EC_WORD(ndx), conv_dyn_tag(d_tag, osabi,
				    mach, 0, &inv_buf1));
			} else {
				Xword orig_d_tag = dyn[ndx].d_tag;

				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_tag = d_tag;

				/*
				 * Update null termination index. Warn if we
				 * just clobbered the only DT_NULL termination
				 * for the array.
				 */
				null_ndx = argstate.dyn.null_ndx;
				set_null_ndx(&argstate);
				if ((argstate.dyn.null_ndx >=
				    argstate.dyn.num) &&
				    (null_ndx != argstate.dyn.null_ndx))
					elfedit_msg(ELFEDIT_MSG_DEBUG,
					    MSG_INTL(MSG_DEBUG_NULLTERM),
					    dyn_ndx, dyn_name,
					    EC_WORD(ndx), conv_dyn_tag(d_tag,
					    osabi, mach, 0, &inv_buf1));

				/*
				 * Warning if
				 *	- Inserting a DT_NULL cuts off following
				 *		non-null elements.
				 *	- Inserting a non-DT_NULL after the
				 *		first null element, will be
				 *		ignored by rtld.
				 */
				if (d_tag == DT_NULL) {
					if ((ndx + 1) < null_ndx)
						elfedit_msg(ELFEDIT_MSG_DEBUG,
						    MSG_INTL(MSG_DEBUG_NULCLIP),
						    dyn_ndx, dyn_name,
						    EC_WORD(ndx),
						    conv_dyn_tag(d_tag, osabi,
						    mach, 0, &inv_buf1));
				} else {
					if ((ndx + 1) > argstate.dyn.null_ndx)
						elfedit_msg(ELFEDIT_MSG_DEBUG,
						    MSG_INTL(MSG_DEBUG_NULHIDE),
						    dyn_ndx, dyn_name,
						    EC_WORD(ndx),
						    conv_dyn_tag(d_tag, osabi,
						    mach, 0, &inv_buf1));
				}

				/* Debug message that we changed it */
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    conv_dyn_tag(orig_d_tag, osabi, mach, 0,
				    &inv_buf1),
				    conv_dyn_tag(d_tag, osabi, mach, 0,
				    &inv_buf2));
			}
		}
		break;

	case DYN_CMD_T_VALUE:
		ret = cmd_body_value(&argstate, &ndx);
		break;

	case DYN_CMD_T_DELETE:
		{
			Word cnt = (argstate.argc == 1) ? 1 :
			    (Word) elfedit_atoui_range(argstate.argv[1],
			    MSG_ORIG(MSG_STR_COUNT), 1, dyn_num - ndx, NULL);
			const char *msg_prefix =
			    elfedit_sec_msgprefix(argstate.dyn.sec);

			elfedit_array_elts_delete(msg_prefix, argstate.dyn.data,
			    sizeof (Dyn), dyn_num, ndx, cnt);
			ret = ELFEDIT_CMDRET_MOD;
		}
		break;

	case DYN_CMD_T_MOVE:
		{
			Dyn	save;
			Word	cnt;
			Word	dstndx;
			const char *msg_prefix =
			    elfedit_sec_msgprefix(argstate.dyn.sec);

			dstndx = (Word)
			    elfedit_atoui_range(argstate.argv[1],
			    MSG_ORIG(MSG_STR_DST_INDEX), 0, dyn_num - 1,
			    NULL);
			if (argstate.argc == 2) {
				cnt = 1;
			} else {
				cnt = (Word) elfedit_atoui_range(
				    argstate.argv[2], MSG_ORIG(MSG_STR_COUNT),
				    1, dyn_num, NULL);
			}
			elfedit_array_elts_move(msg_prefix, argstate.dyn.data,
			    sizeof (save), dyn_num, ndx, dstndx, cnt, &save);
			ret = ELFEDIT_CMDRET_MOD;
		}
		break;


	case DYN_CMD_T_RUNPATH:
		ret = cmd_body_runpath(&argstate);
		break;

	case DYN_CMD_T_POSFLAG1:
		{
			Conv_dyn_posflag1_buf_t buf1, buf2;
			Word flags;

			flags = flag_bitop(&argstate, dyn[ndx].d_un.d_val,
			    ELFEDIT_CONST_DF_P1);

			/* Set the value */
			if (dyn[ndx].d_un.d_val == flags) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_OK), dyn_ndx,
				    dyn_name, EC_WORD(ndx),
				    conv_dyn_posflag1(dyn[ndx].d_un.d_val, 0,
				    &buf1));
			} else {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    conv_dyn_posflag1(dyn[ndx].d_un.d_val, 0,
				    &buf1),
				    conv_dyn_posflag1(flags, 0, &buf2));
				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_un.d_val = flags;
			}
		}
		break;

	case DYN_CMD_T_FLAGS:
		{
			Conv_dyn_flag_buf_t buf1, buf2;
			Word flags;

			flags = flag_bitop(&argstate, dyn[ndx].d_un.d_val,
			    ELFEDIT_CONST_DF);

			/* Set the value */
			if (dyn[ndx].d_un.d_val == flags) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_OK), dyn_ndx,
				    dyn_name, EC_WORD(ndx),
				    conv_dyn_flag(dyn[ndx].d_un.d_val, 0,
				    &buf1));
			} else {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    conv_dyn_flag(dyn[ndx].d_un.d_val, 0,
				    &buf1),
				    conv_dyn_flag(flags, 0, &buf2));
				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_un.d_val = flags;
			}
		}
		break;

	case DYN_CMD_T_FLAGS1:
		{
			Conv_dyn_flag1_buf_t buf1, buf2;
			Word flags1;

			flags1 = flag_bitop(&argstate, dyn[ndx].d_un.d_val,
			    ELFEDIT_CONST_DF_1);

			/* Set the value */
			if (dyn[ndx].d_un.d_val == flags1) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_OK), dyn_ndx,
				    dyn_name, EC_WORD(ndx),
				    conv_dyn_flag1(dyn[ndx].d_un.d_val,
				    0, &buf1));
			} else {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    conv_dyn_flag1(dyn[ndx].d_un.d_val,
				    0, &buf1),
				    conv_dyn_flag1(flags1, 0, &buf2));
				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_un.d_val = flags1;
			}
		}
		break;

	case DYN_CMD_T_FEATURE1:
		{
			Conv_dyn_feature1_buf_t buf1, buf2;
			Word flags;

			flags = flag_bitop(&argstate, dyn[ndx].d_un.d_val,
			    ELFEDIT_CONST_DTF_1);

			/* Set the value */
			if (dyn[ndx].d_un.d_val == flags) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_OK), dyn_ndx,
				    dyn_name, EC_WORD(ndx),
				    conv_dyn_feature1(dyn[ndx].d_un.d_val, 0,
				    &buf1));
			} else {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    conv_dyn_feature1(dyn[ndx].d_un.d_val, 0,
				    &buf1),
				    conv_dyn_feature1(flags, 0, &buf2));
				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_un.d_val = flags;
			}
		}
		break;

	case DYN_CMD_T_CHECKSUM:
		{
			long checksum = elf_checksum(obj_state->os_elf);

			/* Set the value */
			if (dyn[ndx].d_un.d_val == checksum) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_X_OK), dyn_ndx,
				    dyn_name, EC_WORD(ndx), EC_XWORD(checksum));
			} else {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_X_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    EC_XWORD(dyn[ndx].d_un.d_val),
				    EC_XWORD(checksum));
				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_un.d_val = checksum;
			}

		}
		break;

	case DYN_CMD_T_SUNW_LDMACH:
		{
			Conv_inv_buf_t buf1, buf2;
			Half ldmach;

			ldmach = (Half) elfedit_atoconst(argstate.argv[0],
			    ELFEDIT_CONST_EM);

			/* Set the value */
			if (dyn[ndx].d_un.d_val == ldmach) {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_OK), dyn_ndx,
				    dyn_name, EC_WORD(ndx),
				    conv_ehdr_mach(dyn[ndx].d_un.d_val, 0,
				    &buf1));
			} else {
				elfedit_msg(ELFEDIT_MSG_DEBUG,
				    MSG_INTL(MSG_DEBUG_S_CHG),
				    dyn_ndx, dyn_name, EC_WORD(ndx),
				    conv_ehdr_mach(dyn[ndx].d_un.d_val, 0,
				    &buf1),
				    conv_ehdr_mach(ldmach, 0, &buf2));
				ret = ELFEDIT_CMDRET_MOD;
				dyn[ndx].d_un.d_val = ldmach;
			}
		}
		break;

	}

	/*
	 * If we modified the dynamic section header, tell libelf.
	 */
	if (ret == ELFEDIT_CMDRET_MOD)
		elfedit_modified_data(argstate.dyn.sec);

	/* Do autoprint */
	if (do_autoprint)
		print_dyn(cmd, 1, &argstate, print_type, ndx);

	return (ret);
}



/*
 * Command completion functions for the commands
 */

/*
 * Command completion for the first argument, which specifies
 * the dynamic element to use. Examines the options to see if
 * -dynndx is present, and if not, supplies the completion
 * strings for argument 1.
 */
/*ARGSUSED*/
static void
cpl_eltarg(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	elfedit_section_t	*cache;
	Dyn			*dyn;
	Word			i;
	const char		*s;
	char			*s2;
	char			buf[128];

	/* Make sure it's the first argument */
	if ((argc - num_opt) != 1)
		return;

	/* Is -dynndx present? If so, we don't complete tag types */
	for (i = 0; i < num_opt; i++)
		if (strcmp(argv[i], MSG_ORIG(MSG_STR_MINUS_DYNNDX)) == 0)
			return;

	/*
	 * If there is no object, or if there is no dynamic section,
	 * then supply all possible names.
	 */
	if ((obj_state == NULL) || (obj_state->os_dynndx == SHN_UNDEF)) {
		elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_DT);
		return;
	}

	/* Supply completions for the tags present in the dynamic section */
	cache = &obj_state->os_secarr[obj_state->os_dynndx];
	dyn = (Dyn *) cache->sec_data->d_buf;
	i = cache->sec_shdr->sh_size / cache->sec_shdr->sh_entsize;
	for (; i-- > 0; dyn++) {
		s = elfedit_atoconst_value_to_str(ELFEDIT_CONST_DT,
		    dyn->d_tag, 0);
		if (s == NULL)
			continue;
		elfedit_cpl_match(cpldata, s, 1);

		/*
		 * To get the informal tag names that are lowercase
		 * and lack the leading DT_, we copy the string we
		 * have into a buffer and process it.
		 */
		if (strlen(s) < 3)
			continue;
		(void) strlcpy(buf, s + 3, sizeof (buf));
		for (s2 = buf; *s2 != '\0'; s2++)
			if (isupper(*s2))
				*s2 = tolower(*s2);
		elfedit_cpl_match(cpldata, buf, 1);
	}
}


/*ARGSUSED*/
static void
cpl_tag(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	/* First argument */
	if ((argc - num_opt) == 1) {
		cpl_eltarg(obj_state, cpldata, argc, argv, num_opt);
		return;
	}

	/* The second argument is always a tag value */
	if ((argc - num_opt) == 2)
		elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_DT);
}

/*ARGSUSED*/
static void
cpl_posflag1(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	/*
	 * dyn:posflag1 accepts two mutually exclusive options that have
	 * a corresponding value argument: -dynndx and -needed. If we
	 * are being called to supply options for the value, handle that here.
	 */
	if ((num_opt > 1) && (argc == num_opt)) {
		elfedit_section_t	*dynsec, *strsec;
		const char		*opt = argv[num_opt - 2];
		dyn_opt_t		type;
		Dyn			*dyn;
		Word			i, num;

		/*
		 * If there is no object available, or if the object has no
		 * dynamic section, then there is nothing to report.
		 */
		if ((obj_state == NULL) || obj_state->os_dynndx == SHN_UNDEF)
			return;

		/*
		 * Determine which option it is, bail if it isn't one of
		 * the ones we are concerned with.
		 */
		if ((strcmp(opt, MSG_ORIG(MSG_STR_MINUS_NEEDED)) == 0))
			type = DYN_OPT_F_NEEDED;
		else if ((strcmp(opt, MSG_ORIG(MSG_STR_MINUS_DYNNDX)) == 0))
			type = DYN_OPT_F_DYNNDX_VAL;
		else
			return;

		dynsec = elfedit_sec_getdyn(obj_state, &dyn, &num);
		switch (type) {
		case DYN_OPT_F_NEEDED:
			strsec = elfedit_sec_getstr(obj_state,
			    dynsec->sec_shdr->sh_link, 0);
			for (; num-- > 0; dyn++)
				if (dyn->d_tag == DT_NEEDED)
					elfedit_cpl_match(cpldata,
					    elfedit_offset_to_str(strsec,
					    dyn->d_un.d_val, ELFEDIT_MSG_DEBUG,
					    0), 0);
			break;

		case DYN_OPT_F_DYNNDX_VAL:
			for (i = 0; i < num; i++, dyn++)
				if (dyn->d_tag == DT_POSFLAG_1)
					elfedit_cpl_ndx(cpldata, i);
			break;
		}
		return;
	}

	/* This routine allows multiple flags to be specified */
	elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_DF_P1);
}

/*ARGSUSED*/
static void
cpl_flags(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	/* This routine allows multiple flags to be specified */
	elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_DF);
}

/*ARGSUSED*/
static void
cpl_flags1(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	/* This routine allows multiple flags to be specified */
	elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_DF_1);
}

/*ARGSUSED*/
static void
cpl_feature1(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	/* This routine allows multiple flags to be specified */
	elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_DTF_1);
}

/*ARGSUSED*/
static void
cpl_sunw_ldmach(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
    const char *argv[], int num_opt)
{
	/*
	 * This command doesn't accept options, so num_opt should be
	 * 0. This is a defensive measure, in case that should change.
	 */
	argc -= num_opt;
	argv += num_opt;

	if (argc == 1)
		elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EM);
}


/*
 * Implementation functions for the commands
 */
static elfedit_cmdret_t
cmd_dump(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_DUMP, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_tag(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_TAG, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_value(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_VALUE, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_delete(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_DELETE, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_move(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_MOVE, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_runpath(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_RUNPATH, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_posflag1(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_POSFLAG1, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_flags(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_FLAGS, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_flags1(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_FLAGS1, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_feature1(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_FEATURE1, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_checksum(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_CHECKSUM, obj_state, argc, argv));
}

static elfedit_cmdret_t
cmd_sunw_ldmach(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
{
	return (cmd_body(DYN_CMD_T_SUNW_LDMACH, obj_state, argc, argv));
}



/*ARGSUSED*/
elfedit_module_t *
elfedit_init(elfedit_module_version_t version)
{
	/* For commands that only accept -o */
	static elfedit_cmd_optarg_t opt_ostyle[] = {
		{ ELFEDIT_STDOA_OPT_O, 0,
		    ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
		{ NULL }
	};

	/* For commands that only accept -and, -cmp, -o, -or */
	static elfedit_cmd_optarg_t opt_ostyle_bitop[] = {
		{ ELFEDIT_STDOA_OPT_AND, 0,
		    ELFEDIT_CMDOA_F_INHERIT, DYN_OPT_F_AND, DYN_OPT_F_OR },
		{ ELFEDIT_STDOA_OPT_CMP, 0,
		    ELFEDIT_CMDOA_F_INHERIT, DYN_OPT_F_CMP, 0 },
		{ ELFEDIT_STDOA_OPT_O, 0,
		    ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
		{ ELFEDIT_STDOA_OPT_OR, 0,
		    ELFEDIT_CMDOA_F_INHERIT, DYN_OPT_F_OR, DYN_OPT_F_AND },
		{ NULL }
	};

	/* For commands that only accept -dynndx */
	static elfedit_cmd_optarg_t opt_minus_dynndx[] = {
		{ MSG_ORIG(MSG_STR_MINUS_DYNNDX),
		    /* MSG_INTL(MSG_OPTDESC_DYNNDX_ELT) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_DYNNDX_ELT), 0,
		    DYN_OPT_F_DYNNDX_ELT, 0 },
		{ NULL }
	};

	/* dyn:dump */
	static const char *name_dump[] = {
	    MSG_ORIG(MSG_CMD_DUMP),
	    MSG_ORIG(MSG_STR_EMPTY),	/* "" makes this the default command */
	    NULL
	};
	static elfedit_cmd_optarg_t arg_dump[] = {
		{ MSG_ORIG(MSG_STR_ELT),
		    /* MSG_INTL(MSG_ARGDESC_ELT) */
		    ELFEDIT_I18NHDL(MSG_ARGDESC_ELT),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};


	/* dyn:tag */
	static const char *name_tag[] = { MSG_ORIG(MSG_CMD_TAG), NULL };
	static elfedit_cmd_optarg_t opt_tag[] = {
		{ MSG_ORIG(MSG_STR_MINUS_DYNNDX),
		    /* MSG_INTL(MSG_OPTDESC_DYNNDX_ELT) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_DYNNDX_ELT), 0,
		    DYN_OPT_F_DYNNDX_ELT, 0 },
		{ ELFEDIT_STDOA_OPT_O, 0,
		    ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
		{ NULL }
	};
	static elfedit_cmd_optarg_t arg_tag[] = {
		{ MSG_ORIG(MSG_STR_ELT),
		    /* MSG_INTL(MSG_A1_TAG_ELT) */
		    ELFEDIT_I18NHDL(MSG_A1_TAG_ELT),
		    ELFEDIT_CMDOA_F_OPT },
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A2_TAG_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A2_TAG_VALUE),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};


	/* dyn:value */
	static const char *name_value[] = { MSG_ORIG(MSG_CMD_VALUE), NULL };
	static elfedit_cmd_optarg_t opt_value[] = {
		{ MSG_ORIG(MSG_STR_MINUS_ADD),
		    /* MSG_INTL(MSG_OPTDESC_ADD) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_ADD), 0,
		    DYN_OPT_F_ADD, DYN_OPT_F_DYNNDX_ELT },
		{ MSG_ORIG(MSG_STR_MINUS_DYNNDX),
		    /* MSG_INTL(MSG_OPTDESC_DYNNDX_ELT) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_DYNNDX_ELT), 0,
		    DYN_OPT_F_DYNNDX_ELT, DYN_OPT_F_ADD },
		{ ELFEDIT_STDOA_OPT_O, 0,
		    ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
		{ MSG_ORIG(MSG_STR_MINUS_S),
		    /* MSG_INTL(MSG_OPTDESC_S) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_S), 0,
		    DYN_OPT_F_STRVAL, 0 },
		{ NULL }
	};
	static elfedit_cmd_optarg_t arg_value[] = {
		{ MSG_ORIG(MSG_STR_ELT),
		    /* MSG_INTL(MSG_ARGDESC_ELT) */
		    ELFEDIT_I18NHDL(MSG_ARGDESC_ELT),
		    ELFEDIT_CMDOA_F_OPT },
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A2_VALUE_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A2_VALUE_VALUE),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};

	/* dyn:delete */
	static const char *name_delete[] = { MSG_ORIG(MSG_CMD_DELETE), NULL };
	static elfedit_cmd_optarg_t arg_delete[] = {
		{ MSG_ORIG(MSG_STR_ELT),
		    /* MSG_INTL(MSG_ARGDESC_ELT) */
		    ELFEDIT_I18NHDL(MSG_ARGDESC_ELT),
		    0 },
		{ MSG_ORIG(MSG_STR_COUNT),
		    /* MSG_INTL(MSG_A2_DELETE_COUNT) */
		    ELFEDIT_I18NHDL(MSG_A2_DELETE_COUNT),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};

	/* dyn:move */
	static const char *name_move[] = { MSG_ORIG(MSG_CMD_MOVE), NULL };
	static elfedit_cmd_optarg_t arg_move[] = {
		{ MSG_ORIG(MSG_STR_ELT),
		    /* MSG_INTL(MSG_ARGDESC_ELT) */
		    ELFEDIT_I18NHDL(MSG_ARGDESC_ELT),
		    0 },
		{ MSG_ORIG(MSG_STR_DST_INDEX),
		    /* MSG_INTL(MSG_A2_MOVE_DST_INDEX) */
		    ELFEDIT_I18NHDL(MSG_A2_MOVE_DST_INDEX),
		    0 },
		{ MSG_ORIG(MSG_STR_COUNT),
		    /* MSG_INTL(MSG_A3_MOVE_COUNT) */
		    ELFEDIT_I18NHDL(MSG_A3_MOVE_COUNT),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};

	/* dyn:runpath / dyn:rpath */
	static const char *name_runpath[] = { MSG_ORIG(MSG_CMD_RUNPATH),
	    MSG_ORIG(MSG_CMD_RUNPATH_A1), NULL };
	static elfedit_cmd_optarg_t arg_runpath[] = {
		{ MSG_ORIG(MSG_STR_NEWPATH),
		    /* MSG_INTL(MSG_A1_RUNPATH_NEWPATH) */
		    ELFEDIT_I18NHDL(MSG_A1_RUNPATH_NEWPATH),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};

	/* dyn:posflag1 */
	static const char *name_posflag1[] = { MSG_ORIG(MSG_CMD_POSFLAG1),
	    NULL };
	static elfedit_cmd_optarg_t opt_posflag1[] = {
		{ ELFEDIT_STDOA_OPT_AND, 0,
		    ELFEDIT_CMDOA_F_INHERIT, DYN_OPT_F_AND, DYN_OPT_F_OR },
		{ ELFEDIT_STDOA_OPT_CMP, 0,
		    ELFEDIT_CMDOA_F_INHERIT, DYN_OPT_F_CMP, 0 },
		{ MSG_ORIG(MSG_STR_MINUS_DYNNDX),
		    /* MSG_INTL(MSG_OPTDESC_DYNNDX_VAL) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_DYNNDX_VAL),
		    ELFEDIT_CMDOA_F_VALUE,
		    DYN_OPT_F_DYNNDX_VAL, DYN_OPT_F_NEEDED },
		{ MSG_ORIG(MSG_STR_INDEX), 0, 0, 0 },
		{ MSG_ORIG(MSG_STR_MINUS_NEEDED),
		    /* MSG_INTL(MSG_OPTDESC_NEEDED) */
		    ELFEDIT_I18NHDL(MSG_OPTDESC_NEEDED),
		    ELFEDIT_CMDOA_F_VALUE,
		    DYN_OPT_F_NEEDED, DYN_OPT_F_DYNNDX_VAL },
		{ MSG_ORIG(MSG_STR_PREFIX), 0, 0, 0 },
		{ ELFEDIT_STDOA_OPT_O, 0,
		    ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
		{ ELFEDIT_STDOA_OPT_OR, 0,
		    ELFEDIT_CMDOA_F_INHERIT, DYN_OPT_F_OR, DYN_OPT_F_AND },
		{ NULL }
	};
	static elfedit_cmd_optarg_t arg_posflag1[] = {
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A1_POSFLAG1_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A1_POSFLAG1_VALUE),
		    ELFEDIT_CMDOA_F_OPT | ELFEDIT_CMDOA_F_MULT },
		{ NULL }
	};

	/* dyn:flags */
	static const char *name_flags[] = { MSG_ORIG(MSG_CMD_FLAGS), NULL };
	static elfedit_cmd_optarg_t arg_flags[] = {
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A1_FLAGS_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A1_FLAGS_VALUE),
		    ELFEDIT_CMDOA_F_OPT | ELFEDIT_CMDOA_F_MULT },
		{ NULL }
	};

	/* dyn:flags1 */
	static const char *name_flags1[] = { MSG_ORIG(MSG_CMD_FLAGS1), NULL };
	static elfedit_cmd_optarg_t arg_flags1[] = {
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A1_FLAGS1_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A1_FLAGS1_VALUE),
		    ELFEDIT_CMDOA_F_OPT | ELFEDIT_CMDOA_F_MULT },
		{ NULL }
	};

	/* dyn:feature1 */
	static const char *name_feature1[] = { MSG_ORIG(MSG_CMD_FEATURE1),
	    NULL };
	static elfedit_cmd_optarg_t arg_feature1[] = {
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A1_FEATURE1_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A1_FEATURE1_VALUE),
		    ELFEDIT_CMDOA_F_OPT | ELFEDIT_CMDOA_F_MULT },
		{ NULL }
	};

	/* dyn:checksum */
	static const char *name_checksum[] = { MSG_ORIG(MSG_CMD_CHECKSUM),
	    NULL };

	/* dyn:sunw_ldmach */
	static const char *name_sunw_ldmach[] = { MSG_ORIG(MSG_CMD_SUNW_LDMACH),
	    NULL };
	static elfedit_cmd_optarg_t arg_sunw_ldmach[] = {
		{ MSG_ORIG(MSG_STR_VALUE),
		    /* MSG_INTL(MSG_A1_SUNW_LDMACH_VALUE) */
		    ELFEDIT_I18NHDL(MSG_A1_SUNW_LDMACH_VALUE),
		    ELFEDIT_CMDOA_F_OPT },
		{ NULL }
	};



	static elfedit_cmd_t cmds[] = {
		/* dyn:dump */
		{ cmd_dump, cpl_eltarg, name_dump,
		    /* MSG_INTL(MSG_DESC_DUMP) */
		    ELFEDIT_I18NHDL(MSG_DESC_DUMP),
		    /* MSG_INTL(MSG_HELP_DUMP) */
		    ELFEDIT_I18NHDL(MSG_HELP_DUMP),
		    opt_minus_dynndx, arg_dump },

		/* dyn:tag */
		{ cmd_tag, cpl_tag, name_tag,
		    /* MSG_INTL(MSG_DESC_TAG) */
		    ELFEDIT_I18NHDL(MSG_DESC_TAG),
		    /* MSG_INTL(MSG_HELP_TAG) */
		    ELFEDIT_I18NHDL(MSG_HELP_TAG),
		    opt_tag, arg_tag },

		/* dyn:value */
		{ cmd_value, cpl_eltarg, name_value,
		    /* MSG_INTL(MSG_DESC_VALUE) */
		    ELFEDIT_I18NHDL(MSG_DESC_VALUE),
		    /* MSG_INTL(MSG_HELP_VALUE) */
		    ELFEDIT_I18NHDL(MSG_HELP_VALUE),
		    opt_value, arg_value },

		/* dyn:delete */
		{ cmd_delete, cpl_eltarg, name_delete,
		    /* MSG_INTL(MSG_DESC_DELETE) */
		    ELFEDIT_I18NHDL(MSG_DESC_DELETE),
		    /* MSG_INTL(MSG_HELP_DELETE) */
		    ELFEDIT_I18NHDL(MSG_HELP_DELETE),
		    opt_minus_dynndx, arg_delete },

		/* dyn:move */
		{ cmd_move, cpl_eltarg, name_move,
		    /* MSG_INTL(MSG_DESC_MOVE) */
		    ELFEDIT_I18NHDL(MSG_DESC_MOVE),
		    /* MSG_INTL(MSG_HELP_MOVE) */
		    ELFEDIT_I18NHDL(MSG_HELP_MOVE),
		    opt_minus_dynndx, arg_move },

		/* dyn:runpath */
		{ cmd_runpath, NULL, name_runpath,
		    /* MSG_INTL(MSG_DESC_RUNPATH) */
		    ELFEDIT_I18NHDL(MSG_DESC_RUNPATH),
		    /* MSG_INTL(MSG_HELP_RUNPATH) */
		    ELFEDIT_I18NHDL(MSG_HELP_RUNPATH),
		    opt_ostyle, arg_runpath },

		/* dyn:posflag1 */
		{ cmd_posflag1, cpl_posflag1, name_posflag1,
		    /* MSG_INTL(MSG_DESC_POSFLAG1) */
		    ELFEDIT_I18NHDL(MSG_DESC_POSFLAG1),
		    /* MSG_INTL(MSG_HELP_POSFLAG1) */
		    ELFEDIT_I18NHDL(MSG_HELP_POSFLAG1),
		    opt_posflag1, arg_posflag1 },

		/* dyn:flags */
		{ cmd_flags, cpl_flags, name_flags,
		    /* MSG_INTL(MSG_DESC_FLAGS) */
		    ELFEDIT_I18NHDL(MSG_DESC_FLAGS),
		    /* MSG_INTL(MSG_HELP_FLAGS) */
		    ELFEDIT_I18NHDL(MSG_HELP_FLAGS),
		    opt_ostyle_bitop, arg_flags },

		/* dyn:flags1 */
		{ cmd_flags1, cpl_flags1, name_flags1,
		    /* MSG_INTL(MSG_DESC_FLAGS1) */
		    ELFEDIT_I18NHDL(MSG_DESC_FLAGS1),
		    /* MSG_INTL(MSG_HELP_FLAGS1) */
		    ELFEDIT_I18NHDL(MSG_HELP_FLAGS1),
		    opt_ostyle_bitop, arg_flags1 },

		/* dyn:feature1 */
		{ cmd_feature1, cpl_feature1, name_feature1,
		    /* MSG_INTL(MSG_DESC_FEATURE1) */
		    ELFEDIT_I18NHDL(MSG_DESC_FEATURE1),
		    /* MSG_INTL(MSG_HELP_FEATURE1) */
		    ELFEDIT_I18NHDL(MSG_HELP_FEATURE1),
		    opt_ostyle_bitop, arg_feature1 },

		/* dyn:checksum */
		{ cmd_checksum, NULL, name_checksum,
		    /* MSG_INTL(MSG_DESC_CHECKSUM) */
		    ELFEDIT_I18NHDL(MSG_DESC_CHECKSUM),
		    /* MSG_INTL(MSG_HELP_CHECKSUM) */
		    ELFEDIT_I18NHDL(MSG_HELP_CHECKSUM),
		    NULL, NULL },

		/* dyn:sunw_ldmach */
		{ cmd_sunw_ldmach, cpl_sunw_ldmach, name_sunw_ldmach,
		    /* MSG_INTL(MSG_DESC_SUNW_LDMACH) */
		    ELFEDIT_I18NHDL(MSG_DESC_SUNW_LDMACH),
		    /* MSG_INTL(MSG_HELP_SUNW_LDMACH) */
		    ELFEDIT_I18NHDL(MSG_HELP_SUNW_LDMACH),
		    opt_ostyle, arg_sunw_ldmach },

		{ NULL }
	};

	static elfedit_module_t module = {
	    ELFEDIT_VER_CURRENT, MSG_ORIG(MSG_MOD_NAME),
	    /* MSG_INTL(MSG_MOD_DESC) */
	    ELFEDIT_I18NHDL(MSG_MOD_DESC), cmds, mod_i18nhdl_to_str };

	return (&module);
}