object 0.40.0

A unified interface for reading and writing object file formats.
Documentation
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
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
//! ELF definitions.
//!
//! These definitions are independent of read/write support, although we do implement
//! some traits useful for those.
//!
//! This module is the equivalent of /usr/include/elf.h, and is based heavily on it.

#![allow(missing_docs)]
#![allow(clippy::identity_op)]

#[cfg(feature = "names")]
use crate::constants::{ConstantNames, FlagNames};
use crate::endian::{Endian, I32, I64, U16, U32, U64};
use crate::pod::Pod;

/// Platform-specific constant names for an ELF file.
///
/// Returned by [`names`] and [`machine_names`].
#[cfg(feature = "names")]
#[derive(Debug)]
#[non_exhaustive]
pub struct Names {
    /// Values for `FileHeader*::e_type`.
    pub et: &'static ConstantNames<FileType>,
    /// Values for `FileHeader*::e_flags`.
    pub ef: &'static FlagNames<FileFlags>,
    /// Special values for `Sym*::st_shndx` and `FileHeader*::e_shstrndx`.
    pub shn: &'static ConstantNames<SymbolSection>,
    /// Values for `SectionHeader*::sh_type`.
    pub sht: &'static ConstantNames<SectionType>,
    /// Values for `SectionHeader*::sh_flags`.
    pub shf: &'static FlagNames<SectionFlags>,
    /// Values for `st_bind` field of `Sym*::st_info`.
    pub stb: &'static ConstantNames<SymbolBind>,
    /// Values for `st_type` field of `Sym*::st_info`.
    pub stt: &'static ConstantNames<SymbolType>,
    /// Values for `Sym*::st_other`.
    pub sto: &'static FlagNames<SymbolOther>,
    /// Values for `ProgramHeader*::p_type`.
    pub pt: &'static ConstantNames<ProgramType>,
    /// Values for `ProgramHeader*::p_flags`.
    pub pf: &'static FlagNames<ProgramFlags>,
    /// Values for `Dyn*::d_tag`.
    pub dt: &'static ConstantNames<DynamicTag>,
    /// Values for `r_type` field of `Rel*::r_info`.
    pub r: &'static ConstantNames<RelocationType>,
}

names! {
    struct Base;
    consts et = NAMES_ET;
    flags ef: FileFlags(u32) = {};
    consts shn = NAMES_SHN;
    consts sht = NAMES_SHT;
    flags shf = NAMES_SHF;
    consts stb = NAMES_STB;
    consts stt = NAMES_STT;
    flags sto = NAMES_STO;
    consts pt = NAMES_PT;
    flags pf = NAMES_PF;
    consts dt = NAMES_DT;
    consts r: RelocationType = {};
}

/// Return the platform independent names for constants.
#[cfg(feature = "names")]
pub const fn names() -> &'static Names {
    Base::names()
}

/// Return the platform specific names for constants.
///
/// Note that these also include the values returned by [`names`].
///
/// `machine` corresponds to the `FileHeader*::e_machine` field.
#[cfg(feature = "names")]
pub const fn machine_names(machine: Machine) -> &'static Names {
    match machine {
        EM_386 => I386::names(),
        EM_68K => M68k::names(),
        EM_AARCH64 => Aarch64::names(),
        EM_ALPHA => Alpha::names(),
        EM_ALTERA_NIOS2 => Nios2::names(),
        EM_ARM => Arm::names(),
        EM_AVR => Avr::names(),
        EM_BPF => Bpf::names(),
        EM_CRIS => Cris::names(),
        EM_CSKY => Csky::names(),
        EM_HEXAGON => Hex::names(),
        EM_MCST_ELBRUS => E2k::names(),
        EM_IA_64 => Ia64::names(),
        EM_LOONGARCH => Larch::names(),
        EM_M32R => M32r::names(),
        EM_METAG => Metag::names(),
        EM_MICROBLAZE => Microblaze::names(),
        EM_MIPS => Mips::names(),
        EM_MN10300 => Mn10300::names(),
        EM_MSP430 => Msp430::names(),
        EM_NDS32 => Nds32::names(),
        EM_PARISC => Parisc::names(),
        EM_PPC => Ppc::names(),
        EM_PPC64 => Ppc64::names(),
        EM_RISCV => Riscv::names(),
        EM_S390 => S390::names(),
        EM_SBF => Sbf::names(),
        EM_SH => Sh::names(),
        EM_SHARC => Sharc::names(),
        // TODO: might need to be separated
        EM_SPARC | EM_SPARC32PLUS => Sparc::names(),
        EM_SPARCV9 => SparcV9::names(),
        EM_TILEGX => Tilegx::names(),
        EM_TILEPRO => Tilepro::names(),
        EM_X86_64 => X86_64::names(),
        EM_XTENSA => Xtensa::names(),
        _ => Base::names(),
    }
}

/// The header at the start of every 32-bit ELF file.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct FileHeader32<E: Endian> {
    /// Magic number and other information.
    pub e_ident: Ident,
    /// Object file type. One of the `ET_*` constants.
    pub e_type: U16<E, FileType>,
    /// Architecture. One of the `EM_*` constants.
    pub e_machine: U16<E, Machine>,
    /// Object file version. Must be `EV_CURRENT`.
    pub e_version: U32<E>,
    /// Entry point virtual address.
    pub e_entry: U32<E>,
    /// Program header table file offset.
    pub e_phoff: U32<E>,
    /// Section header table file offset.
    pub e_shoff: U32<E>,
    /// Processor-specific flags.
    ///
    /// A combination of the `EF_*` constants.
    pub e_flags: U32<E, FileFlags>,
    /// Size in bytes of this header.
    pub e_ehsize: U16<E>,
    /// Program header table entry size.
    pub e_phentsize: U16<E>,
    /// Program header table entry count.
    ///
    /// If the count is greater than or equal to `PN_XNUM` then this field is set to
    /// `PN_XNUM` and the count is stored in the `sh_info` field of section 0.
    pub e_phnum: U16<E>,
    /// Section header table entry size.
    pub e_shentsize: U16<E>,
    /// Section header table entry count.
    ///
    /// If the count is greater than or equal to `SHN_LORESERVE` then this field is set to
    /// `0` and the count is stored in the `sh_size` field of section 0.
    /// first section header.
    pub e_shnum: U16<E>,
    /// Section header string table index.
    ///
    /// If the index is greater than or equal to `SHN_LORESERVE` then this field is set to
    /// `SHN_XINDEX` and the index is stored in the `sh_link` field of section 0.
    pub e_shstrndx: U16<E, SymbolSection>,
}

/// The header at the start of every 64-bit ELF file.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct FileHeader64<E: Endian> {
    /// Magic number and other information.
    pub e_ident: Ident,
    /// Object file type. One of the `ET_*` constants.
    pub e_type: U16<E, FileType>,
    /// Architecture. One of the `EM_*` constants.
    pub e_machine: U16<E, Machine>,
    /// Object file version. Must be `EV_CURRENT`.
    pub e_version: U32<E>,
    /// Entry point virtual address.
    pub e_entry: U64<E>,
    /// Program header table file offset.
    pub e_phoff: U64<E>,
    /// Section header table file offset.
    pub e_shoff: U64<E>,
    /// Processor-specific flags.
    ///
    /// A combination of the `EF_*` constants.
    pub e_flags: U32<E, FileFlags>,
    /// Size in bytes of this header.
    pub e_ehsize: U16<E>,
    /// Program header table entry size.
    pub e_phentsize: U16<E>,
    /// Program header table entry count.
    ///
    /// If the count is greater than or equal to `PN_XNUM` then this field is set to
    /// `PN_XNUM` and the count is stored in the `sh_info` field of section 0.
    pub e_phnum: U16<E>,
    /// Section header table entry size.
    pub e_shentsize: U16<E>,
    /// Section header table entry count.
    ///
    /// If the count is greater than or equal to `SHN_LORESERVE` then this field is set to
    /// `0` and the count is stored in the `sh_size` field of section 0.
    /// first section header.
    pub e_shnum: U16<E>,
    /// Section header string table index.
    ///
    /// If the index is greater than or equal to `SHN_LORESERVE` then this field is set to
    /// `SHN_XINDEX` and the index is stored in the `sh_link` field of section 0.
    pub e_shstrndx: U16<E, SymbolSection>,
}

/// Magic number and other information.
///
/// Contained in the file header.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Ident {
    /// Magic number. Must be `ELFMAG`.
    pub magic: [u8; 4],
    /// File class. One of the `ELFCLASS*` constants.
    pub class: FileClass,
    /// Data encoding. One of the `ELFDATA*` constants.
    pub data: DataEncoding,
    /// ELF version. Must be `EV_CURRENT`.
    pub version: FileVersion,
    /// OS ABI identification. One of the `ELFOSABI*` constants.
    pub os_abi: OsAbi,
    /// ABI version.
    ///
    /// The meaning of this field depends on the `os_abi` value.
    pub abi_version: u8,
    /// Padding bytes.
    pub padding: [u8; 7],
}

/// File identification bytes stored in `Ident::magic`.
pub const ELFMAG: [u8; 4] = [0x7f, b'E', b'L', b'F'];

newtype!(
    /// Values for `Ident::class`.
    #[repr(transparent)]
    struct FileClass(u8);
);

newtype_constant_names!(NAMES_CLASS: FileClass(u8) = {
    /// Invalid class.
    ELFCLASSNONE = 0,
    /// 32-bit object.
    ELFCLASS32 = 1,
    /// 64-bit object.
    ELFCLASS64 = 2,
});

newtype!(
    /// Values for `Ident::data`.
    #[repr(transparent)]
    struct DataEncoding(u8);
);

newtype_constant_names!(NAMES_DATA: DataEncoding(u8) = {
    /// Invalid data encoding.
    ELFDATANONE = 0,
    /// 2's complement, little endian.
    ELFDATA2LSB = 1,
    /// 2's complement, big endian.
    ELFDATA2MSB = 2,
});

newtype!(
    /// Values for `Ident::os_abi`.
    #[repr(transparent)]
    struct OsAbi(u8);
);

newtype_constant_names!(NAMES_ELFOSABI: OsAbi(u8) = {
    /// UNIX System V ABI.
    ELFOSABI_SYSV = 0,
    /// UNIX System V ABI.
    ///
    /// Alias.
    ELFOSABI_NONE = 0,
    /// HP-UX.
    ELFOSABI_HPUX = 1,
    /// NetBSD.
    ELFOSABI_NETBSD = 2,
    /// Object uses GNU ELF extensions.
    ELFOSABI_GNU = 3,
    /// Object uses GNU ELF extensions.
    ///
    /// Compatibility alias.
    ELFOSABI_LINUX = ELFOSABI_GNU.0,
    /// GNU/Hurd.
    ELFOSABI_HURD = 4,
    /// Sun Solaris.
    ELFOSABI_SOLARIS = 6,
    /// IBM AIX.
    ELFOSABI_AIX = 7,
    /// SGI Irix.
    ELFOSABI_IRIX = 8,
    /// FreeBSD.
    ELFOSABI_FREEBSD = 9,
    /// Compaq TRU64 UNIX.
    ELFOSABI_TRU64 = 10,
    /// Novell Modesto.
    ELFOSABI_MODESTO = 11,
    /// OpenBSD.
    ELFOSABI_OPENBSD = 12,
    /// OpenVMS.
    ELFOSABI_OPENVMS = 13,
    /// Hewlett-Packard Non-Stop Kernel.
    ELFOSABI_NSK = 14,
    /// AROS
    ELFOSABI_AROS = 15,
    /// FenixOS
    ELFOSABI_FENIXOS = 16,
    /// Nuxi CloudABI
    ELFOSABI_CLOUDABI = 17,
    /// ARM EABI.
    ELFOSABI_ARM_AEABI = 64,
    /// ARM.
    ELFOSABI_ARM = 97,
    /// Standalone (embedded) application.
    ELFOSABI_STANDALONE = 255,
});

newtype!(
    /// Values for `FileHeader*::e_type`.
    struct FileType(u16);
);

impl FileType {
    /// Return true if the type is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= ET_LOOS && self.0 <= ET_HIOS
    }
    /// Return true if the type is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        debug_assert_eq!(ET_HIPROC, !0);
        self.0 >= ET_LOPROC
    }
}

newtype_constant_names!(NAMES_ET: FileType(u16) = {
    /// No file type.
    ET_NONE = 0,
    /// Relocatable file.
    ET_REL = 1,
    /// Executable file.
    ET_EXEC = 2,
    /// Shared object file.
    ET_DYN = 3,
    /// Core file.
    ET_CORE = 4,
});

/// OS-specific range start.
pub const ET_LOOS: u16 = 0xfe00;
/// OS-specific range end.
pub const ET_HIOS: u16 = 0xfeff;
/// Processor-specific range start.
pub const ET_LOPROC: u16 = 0xff00;
/// Processor-specific range end.
pub const ET_HIPROC: u16 = 0xffff;

newtype!(
    /// Values for `FileHeader*::e_machine`.
    struct Machine(u16);
);

newtype_constant_names!(NAMES_EM: Machine(u16) = {
    /// No machine
    EM_NONE = 0,
    /// AT&T WE 32100
    EM_M32 = 1,
    /// SUN SPARC
    EM_SPARC = 2,
    /// Intel 80386
    EM_386 = 3,
    /// Motorola m68k family
    EM_68K = 4,
    /// Motorola m88k family
    EM_88K = 5,
    /// Intel MCU
    EM_IAMCU = 6,
    /// Intel 80860
    EM_860 = 7,
    /// MIPS R3000 big-endian
    EM_MIPS = 8,
    /// IBM System/370
    EM_S370 = 9,
    /// MIPS R3000 little-endian
    EM_MIPS_RS3_LE = 10,
    /// HPPA
    EM_PARISC = 15,
    /// Fujitsu VPP500
    EM_VPP500 = 17,
    /// Sun's "v8plus"
    EM_SPARC32PLUS = 18,
    /// Intel 80960
    EM_960 = 19,
    /// PowerPC
    EM_PPC = 20,
    /// PowerPC 64-bit
    EM_PPC64 = 21,
    /// IBM S390
    EM_S390 = 22,
    /// IBM SPU/SPC
    EM_SPU = 23,
    /// NEC V800 series
    EM_V800 = 36,
    /// Fujitsu FR20
    EM_FR20 = 37,
    /// TRW RH-32
    EM_RH32 = 38,
    /// Motorola RCE
    EM_RCE = 39,
    /// ARM
    EM_ARM = 40,
    /// Digital Alpha
    EM_FAKE_ALPHA = 41,
    /// Hitachi SH
    EM_SH = 42,
    /// SPARC v9 64-bit
    EM_SPARCV9 = 43,
    /// Siemens Tricore
    EM_TRICORE = 44,
    /// Argonaut RISC Core
    EM_ARC = 45,
    /// Hitachi H8/300
    EM_H8_300 = 46,
    /// Hitachi H8/300H
    EM_H8_300H = 47,
    /// Hitachi H8S
    EM_H8S = 48,
    /// Hitachi H8/500
    EM_H8_500 = 49,
    /// Intel Merced
    EM_IA_64 = 50,
    /// Stanford MIPS-X
    EM_MIPS_X = 51,
    /// Motorola Coldfire
    EM_COLDFIRE = 52,
    /// Motorola M68HC12
    EM_68HC12 = 53,
    /// Fujitsu MMA Multimedia Accelerator
    EM_MMA = 54,
    /// Siemens PCP
    EM_PCP = 55,
    /// Sony nCPU embeeded RISC
    EM_NCPU = 56,
    /// Denso NDR1 microprocessor
    EM_NDR1 = 57,
    /// Motorola Start*Core processor
    EM_STARCORE = 58,
    /// Toyota ME16 processor
    EM_ME16 = 59,
    /// STMicroelectronic ST100 processor
    EM_ST100 = 60,
    /// Advanced Logic Corp. Tinyj emb.fam
    EM_TINYJ = 61,
    /// AMD x86-64 architecture
    EM_X86_64 = 62,
    /// Sony DSP Processor
    EM_PDSP = 63,
    /// Digital PDP-10
    EM_PDP10 = 64,
    /// Digital PDP-11
    EM_PDP11 = 65,
    /// Siemens FX66 microcontroller
    EM_FX66 = 66,
    /// STMicroelectronics ST9+ 8/16 mc
    EM_ST9PLUS = 67,
    /// STmicroelectronics ST7 8 bit mc
    EM_ST7 = 68,
    /// Motorola MC68HC16 microcontroller
    EM_68HC16 = 69,
    /// Motorola MC68HC11 microcontroller
    EM_68HC11 = 70,
    /// Motorola MC68HC08 microcontroller
    EM_68HC08 = 71,
    /// Motorola MC68HC05 microcontroller
    EM_68HC05 = 72,
    /// Silicon Graphics SVx
    EM_SVX = 73,
    /// STMicroelectronics ST19 8 bit mc
    EM_ST19 = 74,
    /// Digital VAX
    EM_VAX = 75,
    /// Axis Communications 32-bit emb.proc
    EM_CRIS = 76,
    /// Infineon Technologies 32-bit emb.proc
    EM_JAVELIN = 77,
    /// Element 14 64-bit DSP Processor
    EM_FIREPATH = 78,
    /// LSI Logic 16-bit DSP Processor
    EM_ZSP = 79,
    /// Donald Knuth's educational 64-bit proc
    EM_MMIX = 80,
    /// Harvard University machine-independent object files
    EM_HUANY = 81,
    /// SiTera Prism
    EM_PRISM = 82,
    /// Atmel AVR 8-bit microcontroller
    EM_AVR = 83,
    /// Fujitsu FR30
    EM_FR30 = 84,
    /// Mitsubishi D10V
    EM_D10V = 85,
    /// Mitsubishi D30V
    EM_D30V = 86,
    /// NEC v850
    EM_V850 = 87,
    /// Mitsubishi M32R
    EM_M32R = 88,
    /// Matsushita MN10300
    EM_MN10300 = 89,
    /// Matsushita MN10200
    EM_MN10200 = 90,
    /// picoJava
    EM_PJ = 91,
    /// OpenRISC 32-bit embedded processor
    EM_OPENRISC = 92,
    /// ARC International ARCompact
    EM_ARC_COMPACT = 93,
    /// Tensilica Xtensa Architecture
    EM_XTENSA = 94,
    /// Alphamosaic VideoCore
    EM_VIDEOCORE = 95,
    /// Thompson Multimedia General Purpose Proc
    EM_TMM_GPP = 96,
    /// National Semi. 32000
    EM_NS32K = 97,
    /// Tenor Network TPC
    EM_TPC = 98,
    /// Trebia SNP 1000
    EM_SNP1K = 99,
    /// STMicroelectronics ST200
    EM_ST200 = 100,
    /// Ubicom IP2xxx
    EM_IP2K = 101,
    /// MAX processor
    EM_MAX = 102,
    /// National Semi. CompactRISC
    EM_CR = 103,
    /// Fujitsu F2MC16
    EM_F2MC16 = 104,
    /// Texas Instruments msp430
    EM_MSP430 = 105,
    /// Analog Devices Blackfin DSP
    EM_BLACKFIN = 106,
    /// Seiko Epson S1C33 family
    EM_SE_C33 = 107,
    /// Sharp embedded microprocessor
    EM_SEP = 108,
    /// Arca RISC
    EM_ARCA = 109,
    /// PKU-Unity & MPRC Peking Uni. mc series
    EM_UNICORE = 110,
    /// eXcess configurable cpu
    EM_EXCESS = 111,
    /// Icera Semi. Deep Execution Processor
    EM_DXP = 112,
    /// Altera Nios II
    EM_ALTERA_NIOS2 = 113,
    /// National Semi. CompactRISC CRX
    EM_CRX = 114,
    /// Motorola XGATE
    EM_XGATE = 115,
    /// Infineon C16x/XC16x
    EM_C166 = 116,
    /// Renesas M16C
    EM_M16C = 117,
    /// Microchip Technology dsPIC30F
    EM_DSPIC30F = 118,
    /// Freescale Communication Engine RISC
    EM_CE = 119,
    /// Renesas M32C
    EM_M32C = 120,
    /// Altium TSK3000
    EM_TSK3000 = 131,
    /// Freescale RS08
    EM_RS08 = 132,
    /// Analog Devices SHARC family
    EM_SHARC = 133,
    /// Cyan Technology eCOG2
    EM_ECOG2 = 134,
    /// Sunplus S+core7 RISC
    EM_SCORE7 = 135,
    /// New Japan Radio (NJR) 24-bit DSP
    EM_DSP24 = 136,
    /// Broadcom VideoCore III
    EM_VIDEOCORE3 = 137,
    /// RISC for Lattice FPGA
    EM_LATTICEMICO32 = 138,
    /// Seiko Epson C17
    EM_SE_C17 = 139,
    /// Texas Instruments TMS320C6000 DSP
    EM_TI_C6000 = 140,
    /// Texas Instruments TMS320C2000 DSP
    EM_TI_C2000 = 141,
    /// Texas Instruments TMS320C55x DSP
    EM_TI_C5500 = 142,
    /// Texas Instruments App. Specific RISC
    EM_TI_ARP32 = 143,
    /// Texas Instruments Prog. Realtime Unit
    EM_TI_PRU = 144,
    /// STMicroelectronics 64bit VLIW DSP
    EM_MMDSP_PLUS = 160,
    /// Cypress M8C
    EM_CYPRESS_M8C = 161,
    /// Renesas R32C
    EM_R32C = 162,
    /// NXP Semi. TriMedia
    EM_TRIMEDIA = 163,
    /// QUALCOMM Hexagon
    EM_HEXAGON = 164,
    /// Intel 8051 and variants
    EM_8051 = 165,
    /// STMicroelectronics STxP7x
    EM_STXP7X = 166,
    /// Andes Tech. compact code emb. RISC
    EM_NDS32 = 167,
    /// Cyan Technology eCOG1X
    EM_ECOG1X = 168,
    /// Dallas Semi. MAXQ30 mc
    EM_MAXQ30 = 169,
    /// New Japan Radio (NJR) 16-bit DSP
    EM_XIMO16 = 170,
    /// M2000 Reconfigurable RISC
    EM_MANIK = 171,
    /// Cray NV2 vector architecture
    EM_CRAYNV2 = 172,
    /// Renesas RX
    EM_RX = 173,
    /// Imagination Tech. META
    EM_METAG = 174,
    /// MCST Elbrus
    EM_MCST_ELBRUS = 175,
    /// Cyan Technology eCOG16
    EM_ECOG16 = 176,
    /// National Semi. CompactRISC CR16
    EM_CR16 = 177,
    /// Freescale Extended Time Processing Unit
    EM_ETPU = 178,
    /// Infineon Tech. SLE9X
    EM_SLE9X = 179,
    /// Intel L10M
    EM_L10M = 180,
    /// Intel K10M
    EM_K10M = 181,
    /// ARM AARCH64
    EM_AARCH64 = 183,
    /// Amtel 32-bit microprocessor
    EM_AVR32 = 185,
    /// STMicroelectronics STM8
    EM_STM8 = 186,
    /// Tileta TILE64
    EM_TILE64 = 187,
    /// Tilera TILEPro
    EM_TILEPRO = 188,
    /// Xilinx MicroBlaze
    EM_MICROBLAZE = 189,
    /// NVIDIA CUDA
    EM_CUDA = 190,
    /// Tilera TILE-Gx
    EM_TILEGX = 191,
    /// CloudShield
    EM_CLOUDSHIELD = 192,
    /// KIPO-KAIST Core-A 1st gen.
    EM_COREA_1ST = 193,
    /// KIPO-KAIST Core-A 2nd gen.
    EM_COREA_2ND = 194,
    /// Synopsys ARCompact V2
    EM_ARC_COMPACT2 = 195,
    /// Open8 RISC
    EM_OPEN8 = 196,
    /// Renesas RL78
    EM_RL78 = 197,
    /// Broadcom VideoCore V
    EM_VIDEOCORE5 = 198,
    /// Renesas 78KOR
    EM_78KOR = 199,
    /// Freescale 56800EX DSC
    EM_56800EX = 200,
    /// Beyond BA1
    EM_BA1 = 201,
    /// Beyond BA2
    EM_BA2 = 202,
    /// XMOS xCORE
    EM_XCORE = 203,
    /// Microchip 8-bit PIC(r)
    EM_MCHP_PIC = 204,
    /// KM211 KM32
    EM_KM32 = 210,
    /// KM211 KMX32
    EM_KMX32 = 211,
    /// KM211 KMX16
    EM_EMX16 = 212,
    /// KM211 KMX8
    EM_EMX8 = 213,
    /// KM211 KVARC
    EM_KVARC = 214,
    /// Paneve CDP
    EM_CDP = 215,
    /// Cognitive Smart Memory Processor
    EM_COGE = 216,
    /// Bluechip CoolEngine
    EM_COOL = 217,
    /// Nanoradio Optimized RISC
    EM_NORC = 218,
    /// CSR Kalimba
    EM_CSR_KALIMBA = 219,
    /// Zilog Z80
    EM_Z80 = 220,
    /// Controls and Data Services VISIUMcore
    EM_VISIUM = 221,
    /// FTDI Chip FT32
    EM_FT32 = 222,
    /// Moxie processor
    EM_MOXIE = 223,
    /// AMD GPU
    EM_AMDGPU = 224,
    /// RISC-V
    EM_RISCV = 243,
    /// Linux BPF -- in-kernel virtual machine
    EM_BPF = 247,
    /// C-SKY
    EM_CSKY = 252,
    /// Loongson LoongArch
    EM_LOONGARCH = 258,
    /// Solana Binary Format
    EM_SBF = 263,
    /// Digital Alpha
    EM_ALPHA = 0x9026,
});

newtype!(
    /// Values for `FileHeader*::e_version` and `Ident::version`.
    #[repr(transparent)]
    struct FileVersion(u8);
);

newtype_constant_names!(NAMES_VERSION: FileVersion(u8) = {
    /// Invalid ELF version.
    EV_NONE = 0,
    /// Current ELF version.
    EV_CURRENT = 1,
});

newtype!(
    /// Values for `FileHeader*::e_flags`.
    struct FileFlags(u32);
);

// Names depend on machine.
newtype_flag_names!(FileFlags(u32) = {});

impl FileFlags {
    /// Get the MIPS ABI field.
    ///
    /// One of the `EF_MIPS_ABI_*` constants.
    pub fn mips_abi(self) -> FileFlags {
        FileFlags(self.0 & EF_MIPS_ABI)
    }

    /// Set the MIPS ABI field.
    ///
    /// One of the `EF_MIPS_ABI_*` constants.
    pub fn with_mips_abi(self, abi: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_MIPS_ABI | abi.0 & EF_MIPS_ABI)
    }

    /// Get the MIPS architecture field.
    ///
    /// One of the `EF_MIPS_ARCH_*` constants.
    pub fn mips_arch(self) -> FileFlags {
        FileFlags(self.0 & EF_MIPS_ARCH)
    }

    /// Set the MIPS architecture field.
    ///
    /// One of the `EF_MIPS_ARCH_*` constants.
    pub fn with_mips_arch(self, arch: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_MIPS_ARCH | arch.0 & EF_MIPS_ARCH)
    }

    /// Get the PA-RISC architecture field.
    ///
    /// One of the `EFA_PARISC_*` constants.
    pub fn parisc_arch(self) -> FileFlags {
        FileFlags(self.0 & EF_PARISC_ARCH)
    }

    /// Set the PA-RISC architecture field.
    ///
    /// One of the `EFA_PARISC_*` constants.
    pub fn with_parisc_arch(self, arch: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_PARISC_ARCH | arch.0 & EF_PARISC_ARCH)
    }

    /// Get the PPC64 ABI field.
    ///
    /// See [`EF_PPC64_ABI`] for values.
    pub fn ppc64_abi(self) -> u32 {
        self.0 & EF_PPC64_ABI
    }

    /// Set the PPC64 ABI field.
    ///
    /// See [`EF_PPC64_ABI`] for values.
    pub fn with_ppc64_abi(self, abi: u32) -> FileFlags {
        FileFlags(self.0 & !EF_PPC64_ABI | abi & EF_PPC64_ABI)
    }

    /// Get the ARM EABI field.
    ///
    /// One of the `EF_ARM_EABI_*` values.
    pub fn arm_eabi(self) -> FileFlags {
        FileFlags(self.0 & EF_ARM_EABIMASK)
    }

    /// Set the ARM EABI field.
    ///
    /// One of the `EF_ARM_EABI_*` values.
    pub fn with_arm_eabi(self, eabi: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_ARM_EABIMASK | eabi.0 & EF_ARM_EABIMASK)
    }

    /// Get the AVR architecture field.
    ///
    /// One of the `EF_AVR_ARCH_*` values.
    pub fn avr_arch(self) -> FileFlags {
        FileFlags(self.0 & EF_AVR_ARCH)
    }

    /// Set the AVR architecture field.
    ///
    /// One of the `EF_AVR_ARCH_*` values.
    pub fn with_avr_arch(self, arch: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_AVR_ARCH | arch.0 & EF_AVR_ARCH)
    }

    /// Get the SH machine field.
    ///
    /// One of the `EF_SH*` values.
    pub fn sh_mach(self) -> FileFlags {
        FileFlags(self.0 & EF_SH_MACH_MASK)
    }

    /// Set the SH machine field.
    ///
    /// One of the `EF_SH*` values.
    pub fn with_sh_mach(self, mach: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_SH_MACH_MASK | mach.0 & EF_SH_MACH_MASK)
    }

    /// Get the RISC-V float ABI field.
    ///
    /// One of the `EF_RISCV_FLOAT_ABI_*` values.
    pub fn riscv_float_abi(self) -> FileFlags {
        FileFlags(self.0 & EF_RISCV_FLOAT_ABI)
    }

    /// Set the RISC-V float ABI field.
    ///
    /// One of the `EF_RISCV_FLOAT_ABI_*` values.
    pub fn with_riscv_float_abi(self, float_abi: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_RISCV_FLOAT_ABI | float_abi.0 & EF_RISCV_FLOAT_ABI)
    }

    /// Get the LoongArch ABI modifier field.
    ///
    /// One of the `EF_LARCH_ABI_* ` values.
    pub fn larch_abi_modifier(self) -> FileFlags {
        FileFlags(self.0 & EF_LARCH_ABI_MODIFIER_MASK)
    }

    /// Set the LoongArch ABI modifier field.
    ///
    /// One of the `EF_LARCH_ABI_* ` values.
    pub fn with_larch_abi_modifier(self, modifier: FileFlags) -> FileFlags {
        FileFlags(self.0 & !EF_LARCH_ABI_MODIFIER_MASK | modifier.0 & EF_LARCH_ABI_MODIFIER_MASK)
    }
}

/// Section header.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct SectionHeader32<E: Endian> {
    /// Section name.
    ///
    /// This is an offset into the section header string table.
    pub sh_name: U32<E>,
    /// Section type. One of the `SHT_*` constants.
    pub sh_type: U32<E, SectionType>,
    /// Section flags. A combination of the `SHF_*` constants.
    pub sh_flags: U32<E, SectionFlags>,
    /// Section virtual address at execution.
    pub sh_addr: U32<E>,
    /// Section file offset.
    pub sh_offset: U32<E>,
    /// Section size in bytes.
    pub sh_size: U32<E>,
    /// Link to another section.
    ///
    /// The section relationship depends on the `sh_type` value.
    pub sh_link: U32<E>,
    /// Additional section information.
    ///
    /// The meaning of this field depends on the `sh_type` value.
    pub sh_info: U32<E>,
    /// Section alignment.
    pub sh_addralign: U32<E>,
    /// Entry size if the section holds a table.
    pub sh_entsize: U32<E>,
}

/// Section header.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct SectionHeader64<E: Endian> {
    /// Section name.
    ///
    /// This is an offset into the section header string table.
    pub sh_name: U32<E>,
    /// Section type. One of the `SHT_*` constants.
    pub sh_type: U32<E, SectionType>,
    /// Section flags. A combination of the `SHF_*` constants.
    pub sh_flags: U64<E, SectionFlags>,
    /// Section virtual address at execution.
    pub sh_addr: U64<E>,
    /// Section file offset.
    pub sh_offset: U64<E>,
    /// Section size in bytes.
    pub sh_size: U64<E>,
    /// Link to another section.
    ///
    /// The section relationship depends on the `sh_type` value.
    pub sh_link: U32<E>,
    /// Additional section information.
    ///
    /// The meaning of this field depends on the `sh_type` value.
    pub sh_info: U32<E>,
    /// Section alignment.
    pub sh_addralign: U64<E>,
    /// Entry size if the section holds a table.
    pub sh_entsize: U64<E>,
}

newtype!(
    /// Section header index.
    ///
    /// May be a reserved value with special meaning.
    ///
    /// This is primarily used for `Sym*::st_shndx`.
    /// However, `FileHeader*::e_shstrndx` may be set to `SHN_UNDEF`, `SHN_XINDEX`, or an index.
    struct SymbolSection(u16);
);

impl SymbolSection {
    /// Construct a `SymbolSection` from a `u32` section index.
    ///
    /// Returns `SHN_XINDEX` if the index is >= `SHN_LORESERVE`. The caller must write the
    /// extended index separately.
    pub fn new(index: u32) -> Self {
        if index >= u32::from(SHN_LORESERVE) {
            SHN_XINDEX
        } else {
            SymbolSection(index as u16)
        }
    }

    /// Return the section index, or `None` if this is `SHN_UNDEF` or in the reserved range.
    pub fn index(self) -> Option<u16> {
        if self.is_special() {
            None
        } else {
            Some(self.0)
        }
    }

    /// Return true if the number is `SHN_UNDEF` or in the reserved range.
    pub fn is_special(self) -> bool {
        self == SHN_UNDEF || self.is_reserved()
    }

    /// Return true if the number is in the reserved range.
    pub fn is_reserved(self) -> bool {
        debug_assert_eq!(SHN_HIRESERVE, !0);
        self.0 >= SHN_LORESERVE
    }
    /// Return true if the number is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= SHN_LOOS && self.0 <= SHN_HIOS
    }
    /// Return true if the number is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= SHN_LOPROC && self.0 <= SHN_HIPROC
    }
}

newtype_constant_names!(NAMES_SHN: SymbolSection(u16) = {
    /// Undefined section.
    SHN_UNDEF = 0,
    /// Associated symbol is absolute.
    SHN_ABS = 0xfff1,
    /// Associated symbol is common.
    SHN_COMMON = 0xfff2,
    /// Section index is in the `SHT_SYMTAB_SHNDX` section.
    SHN_XINDEX = 0xffff,
});

/// Start of reserved section indices.
pub const SHN_LORESERVE: u16 = 0xff00;
/// Start of processor-specific section indices.
pub const SHN_LOPROC: u16 = 0xff00;
/// End of processor-specific section indices.
pub const SHN_HIPROC: u16 = 0xff1f;
/// Start of OS-specific section indices.
pub const SHN_LOOS: u16 = 0xff20;
/// End of OS-specific section indices.
pub const SHN_HIOS: u16 = 0xff3f;
/// End of reserved section indices.
pub const SHN_HIRESERVE: u16 = 0xffff;

newtype!(
    /// Values for `SectionHeader*::sh_type`.
    struct SectionType(u32);
);

impl SectionType {
    /// Return true if the type is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= SHT_LOOS && self.0 <= SHT_HIOS
    }
    /// Return true if the type is in the Sun-specific range.
    pub fn is_sun(self) -> bool {
        self.0 >= SHT_LOSUNW && self.0 <= SHT_HISUNW
    }
    /// Return true if the type is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= SHT_LOPROC && self.0 <= SHT_HIPROC
    }
    /// Return true if the type is in the application-specific range.
    pub fn is_user(self) -> bool {
        self.0 >= SHT_LOUSER && self.0 <= SHT_HIUSER
    }
}

newtype_constant_names!(NAMES_SHT: SectionType(u32) = {
    /// Section header table entry is unused.
    SHT_NULL = 0,
    /// Program data.
    SHT_PROGBITS = 1,
    /// Symbol table.
    SHT_SYMTAB = 2,
    /// String table.
    SHT_STRTAB = 3,
    /// Relocation entries with explicit addends.
    SHT_RELA = 4,
    /// Symbol hash table.
    SHT_HASH = 5,
    /// Dynamic linking information.
    SHT_DYNAMIC = 6,
    /// Notes.
    SHT_NOTE = 7,
    /// Program space with no data (bss).
    SHT_NOBITS = 8,
    /// Relocation entries without explicit addends.
    SHT_REL = 9,
    /// Reserved section type.
    SHT_SHLIB = 10,
    /// Dynamic linker symbol table.
    SHT_DYNSYM = 11,
    /// Array of constructors.
    SHT_INIT_ARRAY = 14,
    /// Array of destructors.
    SHT_FINI_ARRAY = 15,
    /// Array of pre-constructors.
    SHT_PREINIT_ARRAY = 16,
    /// Section group.
    SHT_GROUP = 17,
    /// Extended section indices for a symbol table.
    SHT_SYMTAB_SHNDX = 18,
    /// Relocation entries; only offsets.
    SHT_RELR = 19,
    /// Experimental CREL relocations. LLVM will change the value and
    /// break compatibility in the future.
    SHT_CREL = 0x40000014,
    /// Android-specific compressed version of `SHT_REL`.
    SHT_ANDROID_REL = 0x60000001,
    /// Android-specific compressed version of `SHT_RELA`.
    SHT_ANDROID_RELA = 0x60000002,
    /// LLVM-style dependent libraries.
    SHT_LLVM_DEPENDENT_LIBRARIES = 0x6fff4c04,
    /// Android-specific precursor of `SHT_RELR`; differs only by constants and required API level.
    SHT_ANDROID_RELR = 0x6fff_ff00,
    /// GNU SFrame stack trace format.
    SHT_GNU_SFRAME = 0x6fff_fff4,
    /// Object attributes.
    SHT_GNU_ATTRIBUTES = 0x6fff_fff5,
    /// GNU-style hash table.
    SHT_GNU_HASH = 0x6fff_fff6,
    /// Prelink library list
    SHT_GNU_LIBLIST = 0x6fff_fff7,
    /// Checksum for DSO content.
    SHT_CHECKSUM = 0x6fff_fff8,
    #[allow(non_upper_case_globals)]
    SHT_SUNW_move = 0x6fff_fffa,
    SHT_SUNW_COMDAT = 0x6fff_fffb,
    #[allow(non_upper_case_globals)]
    SHT_SUNW_syminfo = 0x6fff_fffc,
    /// Version definition section.
    SHT_GNU_VERDEF = 0x6fff_fffd,
    /// Version needs section.
    SHT_GNU_VERNEED = 0x6fff_fffe,
    /// Version symbol table.
    SHT_GNU_VERSYM = 0x6fff_ffff,
});

/// Start of OS-specific section types.
pub const SHT_LOOS: u32 = 0x6000_0000;
/// Sun-specific low bound.
pub const SHT_LOSUNW: u32 = 0x6fff_fffa;
/// Sun-specific high bound.
pub const SHT_HISUNW: u32 = 0x6fff_ffff;
/// End of OS-specific section types.
pub const SHT_HIOS: u32 = 0x6fff_ffff;
/// Start of processor-specific section types.
pub const SHT_LOPROC: u32 = 0x7000_0000;
/// End of processor-specific section types.
pub const SHT_HIPROC: u32 = 0x7fff_ffff;
/// Start of application-specific section types.
pub const SHT_LOUSER: u32 = 0x8000_0000;
/// End of application-specific section types.
pub const SHT_HIUSER: u32 = 0x8fff_ffff;

newtype!(
    /// Values for `SectionHeader*::sh_flags`.
    struct SectionFlags(u64);
);

impl SectionFlags {
    /// Returns OS-specific flags.
    pub fn os_bits(self) -> Self {
        SectionFlags(self.0 & SHF_MASKOS)
    }

    /// Returns processor-specific flags.
    pub fn proc_bits(self) -> Self {
        SectionFlags(self.0 & SHF_MASKPROC)
    }
}

newtype_flag_names!(NAMES_SHF: SectionFlags(u64) = {
    /// Section is writable.
    SHF_WRITE = 1 << 0,
    /// Section occupies memory during execution.
    SHF_ALLOC = 1 << 1,
    /// Section is executable.
    SHF_EXECINSTR = 1 << 2,
    /// Section may be be merged to eliminate duplication.
    SHF_MERGE = 1 << 4,
    /// Section contains nul-terminated strings.
    SHF_STRINGS = 1 << 5,
    /// The `sh_info` field contains a section header table index.
    SHF_INFO_LINK = 1 << 6,
    /// Section has special ordering requirements when combining sections.
    SHF_LINK_ORDER = 1 << 7,
    /// Section requires special OS-specific handling.
    SHF_OS_NONCONFORMING = 1 << 8,
    /// Section is a member of a group.
    SHF_GROUP = 1 << 9,
    /// Section holds thread-local storage.
    SHF_TLS = 1 << 10,
    /// Section is compressed.
    ///
    /// Compressed sections begin with one of the `CompressionHeader*` headers.
    SHF_COMPRESSED = 1 << 11,
    /// Section should not be garbage collected by the linker.
    SHF_GNU_RETAIN = 1 << 21,
    /// Mbind section.
    SHF_GNU_MBIND = 1 << 24,
    /// This section is excluded from the final executable or shared library.
    SHF_EXCLUDE = 0x8000_0000,
});

/// OS-specific section flags.
pub const SHF_MASKOS: u64 = 0x0ff0_0000;
/// Processor-specific section flags.
pub const SHF_MASKPROC: u64 = 0xf000_0000;

/// Section compression header.
///
/// Used when `SHF_COMPRESSED` is set.
///
/// Note: this type currently allows for misaligned headers, but that may be
/// changed in a future version.
#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct CompressionHeader32<E: Endian> {
    /// Compression format. One of the `ELFCOMPRESS_*` values.
    pub ch_type: U32<E, CompressionType>,
    /// Uncompressed data size.
    pub ch_size: U32<E>,
    /// Uncompressed data alignment.
    pub ch_addralign: U32<E>,
}

/// Section compression header.
///
/// Used when `SHF_COMPRESSED` is set.
///
/// Note: this type currently allows for misaligned headers, but that may be
/// changed in a future version.
#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct CompressionHeader64<E: Endian> {
    /// Compression format. One of the `ELFCOMPRESS_*` values.
    pub ch_type: U32<E, CompressionType>,
    /// Reserved.
    pub ch_reserved: U32<E>,
    /// Uncompressed data size.
    pub ch_size: U64<E>,
    /// Uncompressed data alignment.
    pub ch_addralign: U64<E>,
}

newtype!(
    /// Values for `CompressionHeader*::ch_type`.
    struct CompressionType(u32);
);

impl CompressionType {
    /// Return true if the type is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= ELFCOMPRESS_LOOS && self.0 <= ELFCOMPRESS_HIOS
    }
    /// Return true if the type is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= ELFCOMPRESS_LOPROC && self.0 <= ELFCOMPRESS_HIPROC
    }
}

newtype_constant_names!(NAMES_COMPRESS: CompressionType(u32) = {
    /// ZLIB/DEFLATE algorithm.
    ELFCOMPRESS_ZLIB = 1,
    /// Zstandard algorithm.
    ELFCOMPRESS_ZSTD = 2,
});

/// Start of OS-specific compression types.
pub const ELFCOMPRESS_LOOS: u32 = 0x6000_0000;
/// End of OS-specific compression types.
pub const ELFCOMPRESS_HIOS: u32 = 0x6fff_ffff;
/// Start of processor-specific compression types.
pub const ELFCOMPRESS_LOPROC: u32 = 0x7000_0000;
/// End of processor-specific compression types.
pub const ELFCOMPRESS_HIPROC: u32 = 0x7fff_ffff;

newtype!(
    /// Values for the flag entry for section groups.
    struct GroupFlags(u32);
);

newtype_flag_names!(NAMES_GRP: GroupFlags(u32) = {
    /// Mark group as COMDAT.
    GRP_COMDAT = 1,
});

/// Symbol table entry.
#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct Sym32<E: Endian> {
    /// Symbol name.
    ///
    /// This is an offset into the symbol string table.
    pub st_name: U32<E>,
    /// Symbol value.
    pub st_value: U32<E>,
    /// Symbol size.
    pub st_size: U32<E>,
    /// Symbol type and binding.
    ///
    /// Use the `st_type` and `st_bind` methods to access this value.
    pub st_info: SymbolInfo,
    /// Symbol visibility.
    ///
    /// Use the `st_visibility` method to access this value.
    pub st_other: SymbolOther,
    /// Section index or one of the `SHN_*` values.
    pub st_shndx: U16<E, SymbolSection>,
}

impl<E: Endian> Sym32<E> {
    /// Get the `st_bind` subfield of the `st_info` field.
    #[inline]
    pub fn st_bind(&self) -> SymbolBind {
        self.st_info.st_bind()
    }

    /// Get the `st_type` subfield of the `st_info` field.
    #[inline]
    pub fn st_type(&self) -> SymbolType {
        self.st_info.st_type()
    }

    /// Set the `st_info` field given the `st_bind` and `st_type` subfields.
    #[inline]
    pub fn set_st_info(&mut self, st_bind: SymbolBind, st_type: SymbolType) {
        self.st_info = SymbolInfo::new(st_bind, st_type);
    }

    /// Get the `st_visibility` subfield of the `st_other` field.
    #[inline]
    pub fn st_visibility(&self) -> SymbolVisibility {
        self.st_other.visibility()
    }
}

/// Symbol table entry.
#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct Sym64<E: Endian> {
    /// Symbol name.
    ///
    /// This is an offset into the symbol string table.
    pub st_name: U32<E>,
    /// Symbol type and binding.
    ///
    /// Use the `st_bind` and `st_type` methods to access this value.
    pub st_info: SymbolInfo,
    /// Symbol visibility.
    ///
    /// Use the `st_visibility` method to access this value.
    pub st_other: SymbolOther,
    /// Section index or one of the `SHN_*` values.
    pub st_shndx: U16<E, SymbolSection>,
    /// Symbol value.
    pub st_value: U64<E>,
    /// Symbol size.
    pub st_size: U64<E>,
}

impl<E: Endian> Sym64<E> {
    /// Get the `st_bind` subfield of the `st_info` field.
    #[inline]
    pub fn st_bind(&self) -> SymbolBind {
        self.st_info.st_bind()
    }

    /// Get the `st_type` subfield of the `st_info` field.
    #[inline]
    pub fn st_type(&self) -> SymbolType {
        self.st_info.st_type()
    }

    /// Set the `st_info` field given the `st_bind` and `st_type` subfields.
    #[inline]
    pub fn set_st_info(&mut self, st_bind: SymbolBind, st_type: SymbolType) {
        self.st_info = SymbolInfo::new(st_bind, st_type);
    }

    /// Get the `st_visibility` subfield of the `st_other` field.
    #[inline]
    pub fn st_visibility(&self) -> SymbolVisibility {
        self.st_other.visibility()
    }
}

/// Additional information about a `Sym32`.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Syminfo32<E: Endian> {
    /// Direct bindings, symbol bound to.
    pub si_boundto: U16<E, SyminfoBoundto>,
    /// Per symbol flags.
    pub si_flags: U16<E, SyminfoFlags>,
}

/// Additional information about a `Sym64`.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Syminfo64<E: Endian> {
    /// Direct bindings, symbol bound to.
    pub si_boundto: U16<E, SyminfoBoundto>,
    /// Per symbol flags.
    pub si_flags: U16<E, SyminfoFlags>,
}

newtype!(
    /// Values for `Syminfo*::si_boundto`.
    struct SyminfoBoundto(u16);
);

impl SyminfoBoundto {
    /// Return true if the value is in the reserved range.
    pub fn is_reserved(self) -> bool {
        self.0 >= SYMINFO_BT_LOWRESERVE
    }

    /// Return the symbol index, or `None` if it is a reserved value.
    pub fn index(self) -> Option<u16> {
        if self.is_reserved() {
            None
        } else {
            Some(self.0)
        }
    }

    /// Values for `Syminfo*::si_boundto` for the first entry.
    #[cfg(feature = "names")]
    pub fn version_names() -> &'static ConstantNames<SyminfoBoundto> {
        &NAMES_SYMINFO_VERSION
    }
}

newtype_constant_names!(NAMES_SYMINFO_BT: SyminfoBoundto(u16) = {
    /// Symbol bound to self
    SYMINFO_BT_SELF = 0xffff,
    /// Symbol bound to parent
    SYMINFO_BT_PARENT = 0xfffe,
});

/// Beginning of reserved entries
pub const SYMINFO_BT_LOWRESERVE: u16 = 0xff00;

newtype!(
    /// Values for `Syminfo*::si_flags`.
    struct SyminfoFlags(u16);
);

newtype_flag_names!(NAMES_SYMINFO_FLG: SyminfoFlags(u16) = {
    /// Direct bound symbol
    SYMINFO_FLG_DIRECT = 0x0001,
    /// Pass-thru symbol for translator
    SYMINFO_FLG_PASSTHRU = 0x0002,
    /// Symbol is a copy-reloc
    SYMINFO_FLG_COPY = 0x0004,
    /// Symbol bound to object to be lazy loaded
    SYMINFO_FLG_LAZYLOAD = 0x0008,
});

constant_names!(NAMES_SYMINFO_VERSION: SyminfoBoundto(u16) = {
    SYMINFO_NONE = 0,
    SYMINFO_CURRENT = 1,
    SYMINFO_NUM = 2,
});

newtype!(
    /// Values for `Sym*::st_info`.
    #[repr(transparent)]
    struct SymbolInfo(u8);
);

impl core::fmt::Debug for SymbolInfo {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{:?} | {:?}", self.st_bind(), self.st_type())
    }
}

impl SymbolInfo {
    /// Construct a value for the `st_info` field given the `st_bind` and `st_type` fields.
    pub fn new(st_bind: SymbolBind, st_type: SymbolType) -> Self {
        SymbolInfo((st_bind.0 << 4) | (st_type.0 & 0xf))
    }

    /// Get the `st_bind` field.
    pub fn st_bind(self) -> SymbolBind {
        SymbolBind(self.0 >> 4)
    }

    /// Get the `st_type` field.
    pub fn st_type(self) -> SymbolType {
        SymbolType(self.0 & 0xf)
    }
}

impl core::ops::BitOr<SymbolBind> for SymbolType {
    type Output = SymbolInfo;
    fn bitor(self, st_bind: SymbolBind) -> Self::Output {
        SymbolInfo::new(st_bind, self)
    }
}

impl core::ops::BitOr<SymbolType> for SymbolBind {
    type Output = SymbolInfo;
    fn bitor(self, st_type: SymbolType) -> Self::Output {
        SymbolInfo::new(self, st_type)
    }
}

newtype!(
    /// Values for `st_bind` field of `Sym*::st_info`.
    struct SymbolBind(u8);
);

impl SymbolBind {
    /// Return true if the binding is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= STB_LOOS && self.0 <= STB_HIOS
    }
    /// Return true if the binding is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= STB_LOPROC && self.0 <= STB_HIPROC
    }
}

newtype_constant_names!(NAMES_STB: SymbolBind(u8) = {
    /// Local symbol.
    STB_LOCAL = 0,
    /// Global symbol.
    STB_GLOBAL = 1,
    /// Weak symbol.
    STB_WEAK = 2,
    /// Unique symbol.
    STB_GNU_UNIQUE = 10,
});

/// Start of OS-specific symbol binding.
pub const STB_LOOS: u8 = 10;
/// End of OS-specific symbol binding.
pub const STB_HIOS: u8 = 12;
/// Start of processor-specific symbol binding.
pub const STB_LOPROC: u8 = 13;
/// End of processor-specific symbol binding.
pub const STB_HIPROC: u8 = 15;

newtype!(
    /// Values for `st_type` field of `Sym*::st_info`.
    struct SymbolType(u8);
);

impl SymbolType {
    /// Return true if the type is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= STT_LOOS && self.0 <= STT_HIOS
    }
    /// Return true if the type is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= STT_LOPROC && self.0 <= STT_HIPROC
    }
}

newtype_constant_names!(NAMES_STT: SymbolType(u8) = {
    /// Symbol type is unspecified.
    STT_NOTYPE = 0,
    /// Symbol is a data object.
    STT_OBJECT = 1,
    /// Symbol is a code object.
    STT_FUNC = 2,
    /// Symbol is associated with a section.
    STT_SECTION = 3,
    /// Symbol's name is a file name.
    STT_FILE = 4,
    /// Symbol is a common data object.
    STT_COMMON = 5,
    /// Symbol is a thread-local storage object.
    STT_TLS = 6,
    /// Symbol is an indirect code object.
    STT_GNU_IFUNC = 10,
});

/// Start of OS-specific symbol types.
pub const STT_LOOS: u8 = 10;
/// End of OS-specific symbol types.
pub const STT_HIOS: u8 = 12;
/// Start of processor-specific symbol types.
pub const STT_LOPROC: u8 = 13;
/// End of processor-specific symbol types.
pub const STT_HIPROC: u8 = 15;

newtype!(
    /// Values for `Sym*::st_other`.
    #[repr(transparent)]
    struct SymbolOther(u8);
);

impl SymbolOther {
    /// Get the `st_visibility` field.
    pub fn visibility(self) -> SymbolVisibility {
        SymbolVisibility(self.0 & STV_MASK)
    }

    /// Set the `st_visibility` field.
    pub fn with_visibility(self, vis: SymbolVisibility) -> Self {
        SymbolOther(self.0 & !STV_MASK | vis.0 & STV_MASK)
    }

    /// Get the PPC64 `local` field.
    pub fn ppc64_local(self) -> u8 {
        (self.0 & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT
    }

    /// Set the PPC64 `local` field.
    pub fn ppc64_with_local(self, local: u8) -> Self {
        SymbolOther(
            self.0 & !STO_PPC64_LOCAL_MASK | (local << STO_PPC64_LOCAL_BIT) & STO_PPC64_LOCAL_MASK,
        )
    }
}

newtype_flag_names!(NAMES_STO: SymbolOther(u8) = {
    STV_MASK = 3 => NAMES_STV,
});

newtype!(
    struct SymbolVisibility(u8);
);

impl From<SymbolVisibility> for SymbolOther {
    fn from(value: SymbolVisibility) -> Self {
        SymbolOther(value.0 & STV_MASK)
    }
}

impl From<SymbolOther> for SymbolVisibility {
    fn from(value: SymbolOther) -> Self {
        value.visibility()
    }
}

newtype_constant_names!(NAMES_STV: SymbolVisibility(u8) = {
    /// Default symbol visibility rules.
    STV_DEFAULT = 0,
    /// Processor specific hidden class.
    STV_INTERNAL = 1,
    /// Symbol is not visible to other components.
    STV_HIDDEN = 2,
    /// Symbol is visible to other components, but is not preemptible.
    STV_PROTECTED = 3,
});

/// Relocation table entry without explicit addend.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Rel32<E: Endian> {
    /// Relocation address.
    pub r_offset: U32<E>,
    /// Relocation type and symbol index.
    pub r_info: U32<E>,
}

impl<E: Endian> Rel32<E> {
    /// Get the `r_sym` subfield of the `r_info` field.
    #[inline]
    pub fn r_sym(&self, endian: E) -> u32 {
        self.r_info.get(endian) >> 8
    }

    /// Get the `r_type` subfield of the `r_info` field.
    #[inline]
    pub fn r_type(&self, endian: E) -> RelocationType {
        RelocationType(self.r_info.get(endian) & 0xff)
    }

    /// Calculate the `r_info` field given the `r_sym` and `r_type` subfields.
    ///
    /// No overflow check is performed when truncating `r_sym` and `r_type`.
    pub fn r_info(endian: E, r_sym: u32, r_type: RelocationType) -> U32<E> {
        U32::new(endian, (r_sym << 8) | (r_type.0 & 0xff))
    }

    /// Set the `r_info` field given the `r_sym` and `r_type` subfields.
    ///
    /// No overflow check is performed when truncating `r_sym` and `r_type`.
    pub fn set_r_info(&mut self, endian: E, r_sym: u32, r_type: RelocationType) {
        self.r_info = Self::r_info(endian, r_sym, r_type)
    }
}

/// Relocation table entry with explicit addend.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Rela32<E: Endian> {
    /// Relocation address.
    pub r_offset: U32<E>,
    /// Relocation type and symbol index.
    pub r_info: U32<E>,
    /// Explicit addend.
    pub r_addend: I32<E>,
}

impl<E: Endian> Rela32<E> {
    /// Get the `r_sym` subfield of the `r_info` field.
    #[inline]
    pub fn r_sym(&self, endian: E) -> u32 {
        self.r_info.get(endian) >> 8
    }

    /// Get the `r_type` subfield of the `r_info` field.
    #[inline]
    pub fn r_type(&self, endian: E) -> RelocationType {
        RelocationType(self.r_info.get(endian) & 0xff)
    }

    /// Calculate the `r_info` field given the `r_sym` and `r_type` subfields.
    ///
    /// No overflow check is performed when truncating `r_sym` and `r_type`.
    pub fn r_info(endian: E, r_sym: u32, r_type: RelocationType) -> U32<E> {
        U32::new(endian, (r_sym << 8) | u32::from(r_type.0 as u8))
    }

    /// Set the `r_info` field given the `r_sym` and `r_type` subfields.
    ///
    /// No overflow check is performed when truncating `r_sym` and `r_type`.
    pub fn set_r_info(&mut self, endian: E, r_sym: u32, r_type: RelocationType) {
        self.r_info = Self::r_info(endian, r_sym, r_type)
    }
}

impl<E: Endian> From<Rel32<E>> for Rela32<E> {
    fn from(rel: Rel32<E>) -> Self {
        Rela32 {
            r_offset: rel.r_offset,
            r_info: rel.r_info,
            r_addend: I32::default(),
        }
    }
}

/// Relocation table entry without explicit addend.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Rel64<E: Endian> {
    /// Relocation address.
    pub r_offset: U64<E>,
    /// Relocation type and symbol index.
    pub r_info: U64<E>,
}

impl<E: Endian> Rel64<E> {
    /// Get the `r_sym` subfield of the `r_info` field.
    #[inline]
    pub fn r_sym(&self, endian: E) -> u32 {
        (self.r_info.get(endian) >> 32) as u32
    }

    /// Get the `r_type` subfield of the `r_info` field.
    #[inline]
    pub fn r_type(&self, endian: E) -> RelocationType {
        RelocationType((self.r_info.get(endian) & 0xffff_ffff) as u32)
    }

    /// Calculate the `r_info` field given the `r_sym` and `r_type` subfields.
    pub fn r_info(endian: E, r_sym: u32, r_type: RelocationType) -> U64<E> {
        U64::new(endian, (u64::from(r_sym) << 32) | u64::from(r_type.0))
    }

    /// Set the `r_info` field given the `r_sym` and `r_type` subfields.
    pub fn set_r_info(&mut self, endian: E, r_sym: u32, r_type: RelocationType) {
        self.r_info = Self::r_info(endian, r_sym, r_type)
    }
}

impl<E: Endian> From<Rel64<E>> for Rela64<E> {
    fn from(rel: Rel64<E>) -> Self {
        Rela64 {
            r_offset: rel.r_offset,
            r_info: rel.r_info,
            r_addend: I64::default(),
        }
    }
}

/// Relocation table entry with explicit addend.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Rela64<E: Endian> {
    /// Relocation address.
    pub r_offset: U64<E>,
    /// Relocation type and symbol index.
    pub r_info: U64<E>,
    /// Explicit addend.
    pub r_addend: I64<E>,
}

impl<E: Endian> Rela64<E> {
    pub(crate) fn get_r_info(&self, endian: E, is_mips64el: bool) -> u64 {
        let mut t = self.r_info.get(endian);
        if is_mips64el {
            t = (t << 32)
                | ((t >> 8) & 0xff000000)
                | ((t >> 24) & 0x00ff0000)
                | ((t >> 40) & 0x0000ff00)
                | ((t >> 56) & 0x000000ff);
        }
        t
    }

    /// Get the `r_sym` subfield of the `r_info` field.
    #[inline]
    pub fn r_sym(&self, endian: E, is_mips64el: bool) -> u32 {
        (self.get_r_info(endian, is_mips64el) >> 32) as u32
    }

    /// Get the `r_type` subfield of the `r_info` field.
    #[inline]
    pub fn r_type(&self, endian: E, is_mips64el: bool) -> RelocationType {
        RelocationType((self.get_r_info(endian, is_mips64el) & 0xffff_ffff) as u32)
    }

    /// Calculate the `r_info` field given the `r_sym` and `r_type` subfields.
    pub fn r_info(endian: E, is_mips64el: bool, r_sym: u32, r_type: RelocationType) -> U64<E> {
        let mut t = (u64::from(r_sym) << 32) | u64::from(r_type.0);
        if is_mips64el {
            t = (t >> 32)
                | ((t & 0xff000000) << 8)
                | ((t & 0x00ff0000) << 24)
                | ((t & 0x0000ff00) << 40)
                | ((t & 0x000000ff) << 56);
        }
        U64::new(endian, t)
    }

    /// Set the `r_info` field given the `r_sym` and `r_type` subfields.
    pub fn set_r_info(&mut self, endian: E, is_mips64el: bool, r_sym: u32, r_type: RelocationType) {
        self.r_info = Self::r_info(endian, is_mips64el, r_sym, r_type);
    }
}

/// 32-bit relative relocation table entry.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Relr32<E: Endian>(pub U32<E>);

/// 64-bit relative relocation table entry.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Relr64<E: Endian>(pub U64<E>);

newtype!(
    /// Values for `Rel*::r_type`.
    struct RelocationType(u32);
);

newtype_constant_names!(RelocationType(u32) = {});

/// Program segment header.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct ProgramHeader32<E: Endian> {
    /// Segment type. One of the `PT_*` constants.
    pub p_type: U32<E, ProgramType>,
    /// Segment file offset.
    pub p_offset: U32<E>,
    /// Segment virtual address.
    pub p_vaddr: U32<E>,
    /// Segment physical address.
    pub p_paddr: U32<E>,
    /// Segment size in the file.
    pub p_filesz: U32<E>,
    /// Segment size in memory.
    pub p_memsz: U32<E>,
    /// Segment flags. A combination of the `PF_*` constants.
    pub p_flags: U32<E, ProgramFlags>,
    /// Segment alignment.
    pub p_align: U32<E>,
}

/// Program segment header.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct ProgramHeader64<E: Endian> {
    /// Segment type. One of the `PT_*` constants.
    pub p_type: U32<E, ProgramType>,
    /// Segment flags. A combination of the `PF_*` constants.
    pub p_flags: U32<E, ProgramFlags>,
    /// Segment file offset.
    pub p_offset: U64<E>,
    /// Segment virtual address.
    pub p_vaddr: U64<E>,
    /// Segment physical address.
    pub p_paddr: U64<E>,
    /// Segment size in the file.
    pub p_filesz: U64<E>,
    /// Segment size in memory.
    pub p_memsz: U64<E>,
    /// Segment alignment.
    pub p_align: U64<E>,
}

/// Special value for `FileHeader*::e_phnum`.
///
/// This indicates that the real number of program headers is too large to fit into e_phnum.
/// Instead the real value is in the field `sh_info` of section 0.
pub const PN_XNUM: u16 = 0xffff;

newtype!(
    /// Values for `ProgramHeader*::p_type`.
    struct ProgramType(u32);
);

impl ProgramType {
    /// Return true if the type is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= PT_LOOS && self.0 <= PT_HIOS
    }
    /// Return true if the type is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= PT_LOPROC && self.0 <= PT_HIPROC
    }
}

newtype_constant_names!(NAMES_PT: ProgramType(u32) = {
    /// Program header table entry is unused.
    PT_NULL = 0,
    /// Loadable program segment.
    PT_LOAD = 1,
    /// Dynamic linking information.
    PT_DYNAMIC = 2,
    /// Program interpreter.
    PT_INTERP = 3,
    /// Auxiliary information.
    PT_NOTE = 4,
    /// Reserved.
    PT_SHLIB = 5,
    /// Segment contains the program header table.
    PT_PHDR = 6,
    /// Thread-local storage segment.
    PT_TLS = 7,
    /// GCC `.eh_frame_hdr` segment.
    PT_GNU_EH_FRAME = 0x6474_e550,
    /// Indicates stack executability.
    PT_GNU_STACK = 0x6474_e551,
    /// Read-only after relocation.
    PT_GNU_RELRO = 0x6474_e552,
    /// Segment containing `.note.gnu.property` section.
    PT_GNU_PROPERTY = 0x6474_e553,
    /// GNU SFrame stack trace format.
    PT_GNU_SFRAME = 0x6474_e554,
});

/// Start of OS-specific segment types.
pub const PT_LOOS: u32 = 0x6000_0000;
/// End of OS-specific segment types.
pub const PT_HIOS: u32 = 0x6fff_ffff;
/// Start of processor-specific segment types.
pub const PT_LOPROC: u32 = 0x7000_0000;
/// End of processor-specific segment types.
pub const PT_HIPROC: u32 = 0x7fff_ffff;

newtype!(
    /// Values for `ProgramHeader*::p_flags`.
    struct ProgramFlags(u32);
);

newtype_flag_names!(NAMES_PF: ProgramFlags(u32) = {
    /// Segment is executable.
    PF_X = 1 << 0,
    /// Segment is writable.
    PF_W = 1 << 1,
    /// Segment is readable.
    PF_R = 1 << 2,
});

/// OS-specific segment flags.
pub const PF_MASKOS: u32 = 0x0ff0_0000;
/// Processor-specific segment flags.
pub const PF_MASKPROC: u32 = 0xf000_0000;

/// Note name for core files.
pub const ELF_NOTE_CORE: &[u8] = b"CORE";
/// Note name for linux core files.
///
/// Notes in linux core files may also use `ELF_NOTE_CORE`.
pub const ELF_NOTE_LINUX: &[u8] = b"LINUX";

// Values for `NoteHeader*::n_type` in core files.
constant_names!(NAMES_NT_CORE: NoteType(u32) = {
    /// Contains copy of prstatus struct.
    NT_PRSTATUS = 1,
    /// Contains copy of fpregset struct.
    NT_PRFPREG = 2,
    /// Contains copy of fpregset struct.
    NT_FPREGSET = 2,
    /// Contains copy of prpsinfo struct.
    NT_PRPSINFO = 3,
    /// Contains copy of prxregset struct.
    NT_PRXREG = 4,
    /// Contains copy of task structure.
    NT_TASKSTRUCT = 4,
    /// String from sysinfo(SI_PLATFORM).
    NT_PLATFORM = 5,
    /// Contains copy of auxv array.
    NT_AUXV = 6,
    /// Contains copy of gwindows struct.
    NT_GWINDOWS = 7,
    /// Contains copy of asrset struct.
    NT_ASRS = 8,
    /// Contains copy of pstatus struct.
    NT_PSTATUS = 10,
    /// Contains copy of psinfo struct.
    NT_PSINFO = 13,
    /// Contains copy of prcred struct.
    NT_PRCRED = 14,
    /// Contains copy of utsname struct.
    NT_UTSNAME = 15,
    /// Contains copy of lwpstatus struct.
    NT_LWPSTATUS = 16,
    /// Contains copy of lwpinfo struct.
    NT_LWPSINFO = 17,
    /// Contains copy of fprxregset struct.
    NT_PRFPXREG = 20,
    /// Contains copy of siginfo_t, size might increase.
    NT_SIGINFO = 0x5349_4749,
    /// Contains information about mapped files.
    NT_FILE = 0x4649_4c45,
    /// Contains copy of user_fxsr_struct.
    NT_PRXFPREG = 0x46e6_2b7f,
    /// PowerPC Altivec/VMX registers.
    NT_PPC_VMX = 0x100,
    /// PowerPC SPE/EVR registers.
    NT_PPC_SPE = 0x101,
    /// PowerPC VSX registers.
    NT_PPC_VSX = 0x102,
    /// Target Address Register.
    NT_PPC_TAR = 0x103,
    /// Program Priority Register.
    NT_PPC_PPR = 0x104,
    /// Data Stream Control Register.
    NT_PPC_DSCR = 0x105,
    /// Event Based Branch Registers.
    NT_PPC_EBB = 0x106,
    /// Performance Monitor Registers.
    NT_PPC_PMU = 0x107,
    /// TM checkpointed GPR Registers.
    NT_PPC_TM_CGPR = 0x108,
    /// TM checkpointed FPR Registers.
    NT_PPC_TM_CFPR = 0x109,
    /// TM checkpointed VMX Registers.
    NT_PPC_TM_CVMX = 0x10a,
    /// TM checkpointed VSX Registers.
    NT_PPC_TM_CVSX = 0x10b,
    /// TM Special Purpose Registers.
    NT_PPC_TM_SPR = 0x10c,
    /// TM checkpointed Target Address Register.
    NT_PPC_TM_CTAR = 0x10d,
    /// TM checkpointed Program Priority Register.
    NT_PPC_TM_CPPR = 0x10e,
    /// TM checkpointed Data Stream Control Register.
    NT_PPC_TM_CDSCR = 0x10f,
    /// Memory Protection Keys registers.
    NT_PPC_PKEY = 0x110,
    /// i386 TLS slots (struct user_desc).
    NT_386_TLS = 0x200,
    /// x86 io permission bitmap (1=deny).
    NT_386_IOPERM = 0x201,
    /// x86 extended state using xsave.
    NT_X86_XSTATE = 0x202,
    /// s390 upper register halves.
    NT_S390_HIGH_GPRS = 0x300,
    /// s390 timer register.
    NT_S390_TIMER = 0x301,
    /// s390 TOD clock comparator register.
    NT_S390_TODCMP = 0x302,
    /// s390 TOD programmable register.
    NT_S390_TODPREG = 0x303,
    /// s390 control registers.
    NT_S390_CTRS = 0x304,
    /// s390 prefix register.
    NT_S390_PREFIX = 0x305,
    /// s390 breaking event address.
    NT_S390_LAST_BREAK = 0x306,
    /// s390 system call restart data.
    NT_S390_SYSTEM_CALL = 0x307,
    /// s390 transaction diagnostic block.
    NT_S390_TDB = 0x308,
    /// s390 vector registers 0-15 upper half.
    NT_S390_VXRS_LOW = 0x309,
    /// s390 vector registers 16-31.
    NT_S390_VXRS_HIGH = 0x30a,
    /// s390 guarded storage registers.
    NT_S390_GS_CB = 0x30b,
    /// s390 guarded storage broadcast control block.
    NT_S390_GS_BC = 0x30c,
    /// s390 runtime instrumentation.
    NT_S390_RI_CB = 0x30d,
    /// ARM VFP/NEON registers.
    NT_ARM_VFP = 0x400,
    /// ARM TLS register.
    NT_ARM_TLS = 0x401,
    /// ARM hardware breakpoint registers.
    NT_ARM_HW_BREAK = 0x402,
    /// ARM hardware watchpoint registers.
    NT_ARM_HW_WATCH = 0x403,
    /// ARM system call number.
    NT_ARM_SYSTEM_CALL = 0x404,
    /// ARM Scalable Vector Extension registers.
    NT_ARM_SVE = 0x405,
    /// Vmcore Device Dump Note.
    NT_VMCOREDD = 0x700,
    /// MIPS DSP ASE registers.
    NT_MIPS_DSP = 0x800,
    /// MIPS floating-point mode.
    NT_MIPS_FP_MODE = 0x801,
});

/// Note type for version string.
///
/// This note may appear in object files.
///
/// It must be handled as a special case because it has no descriptor, and instead
/// uses the note name as the version string.
pub const NT_VERSION: u32 = 1;

/// Dynamic section entry.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Dyn32<E: Endian> {
    /// Dynamic entry type.
    pub d_tag: I32<E, DynamicTag>,
    /// Value (integer or address).
    pub d_val: U32<E>,
}

/// Dynamic section entry.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Dyn64<E: Endian> {
    /// Dynamic entry type.
    pub d_tag: I64<E, DynamicTag>,
    /// Value (integer or address).
    pub d_val: U64<E>,
}

newtype!(
    /// Values for `Dyn*::d_tag`.
    struct DynamicTag(i64);
);

impl DynamicTag {
    /// Return true if the tag is in the range for values.
    ///
    /// Note that some tags outside of this range are also used for values.
    pub fn is_value(self) -> bool {
        self.0 >= DT_VALRNGLO && self.0 <= DT_VALRNGHI
    }
    /// Return true if the tag is in the range for addresses.
    ///
    /// Note that some tags outside of this range are also used for addresses.
    pub fn is_address(self) -> bool {
        self.0 >= DT_ADDRRNGLO && self.0 <= DT_ADDRRNGHI
    }
    /// Return true if the tag is in the OS-specific range.
    pub fn is_os(self) -> bool {
        self.0 >= DT_LOOS && self.0 <= DT_HIOS
    }
    /// Return true if the tag is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= DT_LOPROC && self.0 <= DT_HIPROC
    }
}

newtype_constant_names!(NAMES_DT: DynamicTag(i64) = {
    /// Marks end of dynamic section
    DT_NULL = 0,
    /// Name of needed library
    DT_NEEDED = 1,
    /// Size in bytes of PLT relocs
    DT_PLTRELSZ = 2,
    /// Processor defined value
    DT_PLTGOT = 3,
    /// Address of symbol hash table
    DT_HASH = 4,
    /// Address of string table
    DT_STRTAB = 5,
    /// Address of symbol table
    DT_SYMTAB = 6,
    /// Address of Rela relocs
    DT_RELA = 7,
    /// Total size of Rela relocs
    DT_RELASZ = 8,
    /// Size of one Rela reloc
    DT_RELAENT = 9,
    /// Size of string table
    DT_STRSZ = 10,
    /// Size of one symbol table entry
    DT_SYMENT = 11,
    /// Address of init function
    DT_INIT = 12,
    /// Address of termination function
    DT_FINI = 13,
    /// Name of shared object
    DT_SONAME = 14,
    /// Library search path (deprecated)
    DT_RPATH = 15,
    /// Start symbol search here
    DT_SYMBOLIC = 16,
    /// Address of Rel relocs
    DT_REL = 17,
    /// Total size of Rel relocs
    DT_RELSZ = 18,
    /// Size of one Rel reloc
    DT_RELENT = 19,
    /// Type of reloc in PLT
    DT_PLTREL = 20,
    /// For debugging; unspecified
    DT_DEBUG = 21,
    /// Reloc might modify .text
    DT_TEXTREL = 22,
    /// Address of PLT relocs
    DT_JMPREL = 23,
    /// Process relocations of object
    DT_BIND_NOW = 24,
    /// Array with addresses of init fct
    DT_INIT_ARRAY = 25,
    /// Array with addresses of fini fct
    DT_FINI_ARRAY = 26,
    /// Size in bytes of DT_INIT_ARRAY
    DT_INIT_ARRAYSZ = 27,
    /// Size in bytes of DT_FINI_ARRAY
    DT_FINI_ARRAYSZ = 28,
    /// Library search path
    DT_RUNPATH = 29,
    /// Flags for the object being loaded
    DT_FLAGS = 30,
    /// Start of encoded range
    DT_ENCODING = 32,
    /// Array with addresses of preinit fct
    DT_PREINIT_ARRAY = 32,
    /// size in bytes of DT_PREINIT_ARRAY
    DT_PREINIT_ARRAYSZ = 33,
    /// Address of SYMTAB_SHNDX section
    DT_SYMTAB_SHNDX = 34,
    /// Address of Relr relocs
    DT_RELR = 36,
    /// Total size of Relr relocs
    DT_RELRSZ = 35,
    /// Size of one Relr reloc
    DT_RELRENT = 37,

    /// Address of Android-specific compressed Rel relocs
    DT_ANDROID_REL = 0x6000000f,
    /// Total size of Android-specific compressed Rel relocs
    DT_ANDROID_RELSZ = 0x60000010,
    /// Address of Android-specific compressed Rela relocs
    DT_ANDROID_RELA = 0x60000011,
    /// Total size of Android-specific compressed Rela relocs
    DT_ANDROID_RELASZ = 0x60000012,
    /// Address of Android-specific Relr relocs
    DT_ANDROID_RELR = 0x6fff_e000,
    /// Total size of Android-specific Relr relocs
    DT_ANDROID_RELRSZ = 0x6fff_e001,
    /// Size of one Android-specific Relr reloc
    DT_ANDROID_RELRENT = 0x6fff_e003,

    /// Prelinking timestamp
    DT_GNU_PRELINKED = 0x6fff_fdf5,
    /// Size of conflict section
    DT_GNU_CONFLICTSZ = 0x6fff_fdf6,
    /// Size of library list
    DT_GNU_LIBLISTSZ = 0x6fff_fdf7,
    DT_CHECKSUM = 0x6fff_fdf8,
    DT_PLTPADSZ = 0x6fff_fdf9,
    DT_MOVEENT = 0x6fff_fdfa,
    DT_MOVESZ = 0x6fff_fdfb,
    /// Feature selection (DTF_*).
    DT_FEATURE_1 = 0x6fff_fdfc,
    /// Flags for DT_* entries, affecting the following DT_* entry.
    DT_POSFLAG_1 = 0x6fff_fdfd,
    /// Size of syminfo table (in bytes)
    DT_SYMINSZ = 0x6fff_fdfe,
    /// Entry size of syminfo
    DT_SYMINENT = 0x6fff_fdff,

    /// GNU-style hash table.
    DT_GNU_HASH = 0x6fff_fef5,
    DT_TLSDESC_PLT = 0x6fff_fef6,
    DT_TLSDESC_GOT = 0x6fff_fef7,
    /// Start of conflict section
    DT_GNU_CONFLICT = 0x6fff_fef8,
    /// Library list
    DT_GNU_LIBLIST = 0x6fff_fef9,
    /// Configuration information.
    DT_CONFIG = 0x6fff_fefa,
    /// Dependency auditing.
    DT_DEPAUDIT = 0x6fff_fefb,
    /// Object auditing.
    DT_AUDIT = 0x6fff_fefc,
    /// PLT padding.
    DT_PLTPAD = 0x6fff_fefd,
    /// Move table.
    DT_MOVETAB = 0x6fff_fefe,
    /// Syminfo table.
    DT_SYMINFO = 0x6fff_feff,

    // The versioning entry types.  The next are defined as part of the
    // GNU extension.
    DT_VERSYM = 0x6fff_fff0,
    DT_RELACOUNT = 0x6fff_fff9,
    DT_RELCOUNT = 0x6fff_fffa,
    /// State flags, see DF_1_* below.
    DT_FLAGS_1 = 0x6fff_fffb,
    /// Address of version definition table
    DT_VERDEF = 0x6fff_fffc,
    /// Number of version definitions
    DT_VERDEFNUM = 0x6fff_fffd,
    /// Address of table with needed versions
    DT_VERNEED = 0x6fff_fffe,
    /// Number of needed versions
    DT_VERNEEDNUM = 0x6fff_ffff,

    // Machine-independent extensions in the "processor-specific" range.
    /// Shared object to load before self
    DT_AUXILIARY = 0x7fff_fffd,
    /// Shared object to get values from
    DT_FILTER = 0x7fff_ffff,
});

/// Start of OS-specific
pub const DT_LOOS: i64 = 0x6000_000d;
/// End of OS-specific
pub const DT_HIOS: i64 = 0x6fff_f000;
/// Start of processor-specific
pub const DT_LOPROC: i64 = 0x7000_0000;
/// End of processor-specific
pub const DT_HIPROC: i64 = 0x7fff_ffff;

// `DT_*` entries between `DT_VALRNGHI` & `DT_VALRNGLO` use `d_val` as a value.
pub const DT_VALRNGLO: i64 = 0x6fff_fd00;
pub const DT_VALRNGHI: i64 = 0x6fff_fdff;

// `DT_*` entries between `DT_ADDRRNGHI` & `DT_ADDRRNGLO` use `d_val` as an address.
//
// If any adjustment is made to the ELF object after it has been
// built these entries will need to be adjusted.
pub const DT_ADDRRNGLO: i64 = 0x6fff_fe00;
pub const DT_ADDRRNGHI: i64 = 0x6fff_feff;

newtype!(
    /// Values of `Dyn*::d_val` in the `DT_FLAGS` entry.
    struct DynamicFlags(u64);
);

newtype_flag_names!(NAMES_DF: DynamicFlags(u64) = {
    /// Object may use DF_ORIGIN
    DF_ORIGIN = 0x0000_0001,
    /// Symbol resolutions starts here
    DF_SYMBOLIC = 0x0000_0002,
    /// Object contains text relocations
    DF_TEXTREL = 0x0000_0004,
    /// No lazy binding for this object
    DF_BIND_NOW = 0x0000_0008,
    /// Module uses the static TLS model
    DF_STATIC_TLS = 0x0000_0010,
});

newtype!(
    /// Values of `Dyn*::d_val` in the `DT_FLAGS_1` entry.
    struct DynamicFlags1(u64);
);

newtype_flag_names!(NAMES_DF_1: DynamicFlags1(u64) = {
    /// Set RTLD_NOW for this object.
    DF_1_NOW = 0x0000_0001,
    /// Set RTLD_GLOBAL for this object.
    DF_1_GLOBAL = 0x0000_0002,
    /// Set RTLD_GROUP for this object.
    DF_1_GROUP = 0x0000_0004,
    /// Set RTLD_NODELETE for this object.
    DF_1_NODELETE = 0x0000_0008,
    /// Trigger filtee loading at runtime.
    DF_1_LOADFLTR = 0x0000_0010,
    /// Set RTLD_INITFIRST for this object.
    DF_1_INITFIRST = 0x0000_0020,
    /// Set RTLD_NOOPEN for this object.
    DF_1_NOOPEN = 0x0000_0040,
    /// $ORIGIN must be handled.
    DF_1_ORIGIN = 0x0000_0080,
    /// Direct binding enabled.
    DF_1_DIRECT = 0x0000_0100,
    DF_1_TRANS = 0x0000_0200,
    /// Object is used to interpose.
    DF_1_INTERPOSE = 0x0000_0400,
    /// Ignore default lib search path.
    DF_1_NODEFLIB = 0x0000_0800,
    /// Object can't be dldump'ed.
    DF_1_NODUMP = 0x0000_1000,
    /// Configuration alternative created.
    DF_1_CONFALT = 0x0000_2000,
    /// Filtee terminates filters search.
    DF_1_ENDFILTEE = 0x0000_4000,
    /// Disp reloc applied at build time.
    DF_1_DISPRELDNE = 0x0000_8000,
    /// Disp reloc applied at run-time.
    DF_1_DISPRELPND = 0x0001_0000,
    /// Object has no-direct binding.
    DF_1_NODIRECT = 0x0002_0000,
    DF_1_IGNMULDEF = 0x0004_0000,
    DF_1_NOKSYMS = 0x0008_0000,
    DF_1_NOHDR = 0x0010_0000,
    /// Object is modified after built.
    DF_1_EDITED = 0x0020_0000,
    DF_1_NORELOC = 0x0040_0000,
    /// Object has individual interposers.
    DF_1_SYMINTPOSE = 0x0080_0000,
    /// Global auditing required.
    DF_1_GLOBAUDIT = 0x0100_0000,
    /// Singleton symbols are used.
    DF_1_SINGLETON = 0x0200_0000,
    DF_1_STUB = 0x0400_0000,
    DF_1_PIE = 0x0800_0000,
});

/// Version symbol information
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Versym<E: Endian>(pub U16<E, VersymIndex>);

newtype!(
    /// Version index for a symbol.
    ///
    /// This is a `VersionIndex` plus the `VERSYM_HIDDEN` flag.
    struct VersymIndex(u16);
);

impl VersymIndex {
    /// Return the version index.
    pub fn index(&self) -> VersionIndex {
        VersionIndex(self.0 & VERSYM_VERSION)
    }

    /// Return true if it is the local index.
    pub fn is_local(&self) -> bool {
        self.index() == VER_NDX_LOCAL
    }

    /// Return true if it is the global index.
    pub fn is_global(&self) -> bool {
        self.index() == VER_NDX_GLOBAL
    }

    /// Return the hidden flag.
    pub fn is_hidden(&self) -> bool {
        self.contains(VERSYM_HIDDEN)
    }
}

impl From<VersionIndex> for VersymIndex {
    fn from(value: VersionIndex) -> Self {
        VersymIndex(value.0)
    }
}

impl From<VersymIndex> for VersionIndex {
    fn from(value: VersymIndex) -> Self {
        value.index()
    }
}

newtype_flag_names!(NAMES_VERSYM: VersymIndex(u16) = {
    /// Symbol is hidden.
    VERSYM_HIDDEN = 0x8000,
    /// Symbol version index.
    VERSYM_VERSION = 0x7fff => NAMES_VER_NDX,
});

/// Version definition sections
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Verdef<E: Endian> {
    /// Version revision
    pub vd_version: U16<E>,
    /// Version information
    pub vd_flags: U16<E, VersionFlags>,
    /// Version Index
    pub vd_ndx: U16<E, VersionIndex>,
    /// Number of associated aux entries
    pub vd_cnt: U16<E>,
    /// Version name hash value
    pub vd_hash: U32<E>,
    /// Offset in bytes to verdaux array
    pub vd_aux: U32<E>,
    /// Offset in bytes to next verdef entry
    pub vd_next: U32<E>,
}

// Legal values for vd_version (version revision).
/// No version
pub const VER_DEF_NONE: u16 = 0;
/// Current version
pub const VER_DEF_CURRENT: u16 = 1;

newtype!(
    /// Legal values for vd_flags and vna_flags (version information flags).
    struct VersionFlags(u16);
);

newtype_flag_names!(NAMES_VER_FLG: VersionFlags(u16) = {
    // Legal values for vd_flags (version information flags).
    /// Version definition of file itself
    VER_FLG_BASE = 0x1,
    // Legal values for vd_flags and vna_flags (version information flags).
    /// Weak version identifier
    VER_FLG_WEAK = 0x2,
});

newtype!(
    /// Version index.
    ///
    /// This is the index value stored in [`VersymIndex`], [`Verdef::vd_ndx`] or
    /// [`field@Vernaux::vna_other`].
    struct VersionIndex(u16);
);

impl VersionIndex {
    /// Construct a `VersymIndex` from an index and a hidden flag.
    pub fn versym(self, hidden: bool) -> VersymIndex {
        if hidden {
            VersymIndex(self.0).with(VERSYM_HIDDEN)
        } else {
            VersymIndex(self.0)
        }
    }

    /// Add an offset to the index.
    ///
    /// This is useful when constructing a `VersionIndex` from a base index
    /// such as `VER_NDX_GLOBAL`.
    ///
    /// Panics in debug builds if the resulting index >= `VERSYM_HIDDEN`.
    /// In release builds, the result wraps and the bounds check is skipped.
    pub fn offset(self, offset: u16) -> Self {
        let index = self.0 + offset;
        debug_assert!(index < VERSYM_HIDDEN.0);
        VersionIndex(index)
    }

    /// Add an offset to the index, checking for overflow.
    ///
    /// This is useful when constructing a `VersionIndex` from a base index
    /// such as `VER_NDX_GLOBAL`.
    ///
    /// Returns `None` if the resulting index >= `VERSYM_HIDDEN`.
    pub fn checked_offset(self, offset: u16) -> Option<Self> {
        let index = self.0.checked_add(offset)?;
        if index >= VERSYM_HIDDEN.0 {
            return None;
        }
        Some(VersionIndex(index))
    }

    /// Compute the offset relative to another index.
    ///
    /// This is useful for obtaining an array index relative to a base index
    /// such as `VER_NDX_GLOBAL`.
    ///
    /// Panics in debug builds if `self.0 < base.0`.
    /// In release builds, the result wraps.
    pub fn offset_from(self, base: VersionIndex) -> u16 {
        self.0 - base.0
    }

    /// Compute the offset relative to another index, checking for underflow.
    ///
    /// This is useful for obtaining an array index relative to a base index
    /// such as `VER_NDX_GLOBAL`.
    ///
    /// Returns `None` if `self.0 < base.0`.
    pub fn checked_offset_from(self, base: VersionIndex) -> Option<u16> {
        self.0.checked_sub(base.0)
    }

    /// Return true if it is the local index.
    pub fn is_local(&self) -> bool {
        *self == VER_NDX_LOCAL
    }

    /// Return true if it is the global index.
    pub fn is_global(&self) -> bool {
        *self == VER_NDX_GLOBAL
    }

    /// Return true if it is the local or global index.
    pub fn is_special(&self) -> bool {
        self.0 <= VER_NDX_GLOBAL.0
    }
}

impl core::ops::Add<u16> for VersionIndex {
    type Output = Self;

    fn add(self, rhs: u16) -> Self::Output {
        self.offset(rhs)
    }
}

impl core::ops::AddAssign<u16> for VersionIndex {
    fn add_assign(&mut self, rhs: u16) {
        *self = self.offset(rhs);
    }
}

impl core::ops::Sub for VersionIndex {
    type Output = u16;

    fn sub(self, rhs: VersionIndex) -> Self::Output {
        self.offset_from(rhs)
    }
}

impl From<VersionIndex> for usize {
    fn from(value: VersionIndex) -> Self {
        usize::from(value.0)
    }
}

newtype_constant_names!(NAMES_VER_NDX: VersionIndex(u16) = {
    /// Symbol is local.
    VER_NDX_LOCAL = 0,
    /// Symbol is global.
    VER_NDX_GLOBAL = 1,
});

/// Auxiliary version information.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Verdaux<E: Endian> {
    /// Version or dependency names
    pub vda_name: U32<E>,
    /// Offset in bytes to next verdaux
    pub vda_next: U32<E>,
}

/// Version dependency.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Verneed<E: Endian> {
    /// Version of structure
    pub vn_version: U16<E>,
    /// Number of associated aux entries
    pub vn_cnt: U16<E>,
    /// Offset of filename for this dependency
    pub vn_file: U32<E>,
    /// Offset in bytes to vernaux array
    pub vn_aux: U32<E>,
    /// Offset in bytes to next verneed entry
    pub vn_next: U32<E>,
}

// Legal values for vn_version (version revision).
/// No version
pub const VER_NEED_NONE: u16 = 0;
/// Current version
pub const VER_NEED_CURRENT: u16 = 1;

/// Auxiliary needed version information.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Vernaux<E: Endian> {
    /// Hash value of dependency name
    pub vna_hash: U32<E>,
    /// Dependency specific information
    pub vna_flags: U16<E, VersionFlags>,
    /// Version Index
    ///
    /// LSB documents that this supports `VERSYM_HIDDEN`, but no linker sets it, so we
    /// keep this as a `VersionIndex`. Use [`method@Self::vna_other`] if you wish to handle
    /// the hidden bit when parsing.
    pub vna_other: U16<E, VersionIndex>,
    /// Dependency name string offset
    pub vna_name: U32<E>,
    /// Offset in bytes to next vernaux entry
    pub vna_next: U32<E>,
}

impl<E: Endian> Vernaux<E> {
    /// Return the `vna_other` field as a `VersymIndex`.
    pub fn vna_other(self, endian: E) -> VersymIndex {
        VersymIndex(self.vna_other.get(endian).0)
    }
}

// TODO: Elf*_auxv_t, AT_*

/// Note section entry header.
///
/// A note consists of a header followed by a variable length name and descriptor.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct NoteHeader32<E: Endian> {
    /// Length of the note's name.
    ///
    /// Some known names are defined by the `ELF_NOTE_*` constants.
    pub n_namesz: U32<E>,
    /// Length of the note's descriptor.
    ///
    /// The content of the descriptor depends on the note name and type.
    pub n_descsz: U32<E>,
    /// Type of the note.
    ///
    /// One of the `NT_*` constants. The note name determines which
    /// `NT_*` constants are valid.
    pub n_type: U32<E, NoteType>,
}

/// Note section entry header.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct NoteHeader64<E: Endian> {
    /// Length of the note's name.
    ///
    /// Some known names are defined by the `ELF_NOTE_*` constants.
    pub n_namesz: U32<E>,
    /// Length of the note's descriptor.
    ///
    /// The content of the descriptor depends on the note name and type.
    pub n_descsz: U32<E>,
    /// Type of the note.
    ///
    /// One of the `NT_*` constants. The note name determines which
    /// `NT_*` constants are valid.
    pub n_type: U32<E, NoteType>,
}

newtype!(
    /// Values for `NoteHeader*::n_type`.
    struct NoteType(u32);
);

// Types depend on n_name.
newtype_constant_names!(NoteType(u32) = {});

#[cfg(feature = "names")]
impl NoteType {
    /// Get `NT_*` constants for `NoteHeader*::n_type`.
    ///
    /// `name` is the note name (as indicated by `NoteHeader*::n_namesz`).
    pub fn names(name: &[u8]) -> &'static ConstantNames<NoteType> {
        match name {
            ELF_NOTE_CORE | ELF_NOTE_LINUX => &NAMES_NT_CORE,
            ELF_NOTE_GNU => &NAMES_NT_GNU,
            ELF_NOTE_SOLARIS => &NAMES_NT_SOLARIS,
            ELF_NOTE_GO => &NAMES_NT_GO,
            _ => {
                constant_names!(EMPTY: NoteType = {});
                &EMPTY
            }
        }
    }
}

/// Solaris entries in the note section have this name.
pub const ELF_NOTE_SOLARIS: &[u8] = b"SUNW Solaris";

// Values for `n_type` when the name is `ELF_NOTE_SOLARIS`.
constant_names!(NAMES_NT_SOLARIS: NoteType(u32) = {
    /// Desired pagesize for the binary.
    NT_SOLARIS_PAGESIZE_HINT = 1,
});

/// GNU entries in the note section have this name.
pub const ELF_NOTE_GNU: &[u8] = b"GNU";

/// Go entries in the note section have this name.
// See https://go-review.googlesource.com/9520 and https://go-review.googlesource.com/10704.
pub const ELF_NOTE_GO: &[u8] = b"Go";

// Note types for `ELF_NOTE_GNU`.
constant_names!(NAMES_NT_GNU: NoteType(u32) = {
    /// ABI information.
    ///
    /// The descriptor consists of words:
    /// - word 0: OS descriptor
    /// - word 1: major version of the ABI
    /// - word 2: minor version of the ABI
    /// - word 3: subminor version of the ABI
    NT_GNU_ABI_TAG = 1,
    /// Synthetic hwcap information.
    ///
    /// The descriptor begins with two words:
    /// - word 0: number of entries
    /// - word 1: bitmask of enabled entries
    ///
    /// Then follow variable-length entries, one byte followed by a
    /// '\0'-terminated hwcap name string.  The byte gives the bit
    /// number to test if enabled, (1U << bit) & bitmask.
    NT_GNU_HWCAP = 2,
    /// Build ID bits as generated by `ld --build-id`.
    ///
    /// The descriptor consists of any nonzero number of bytes.
    NT_GNU_BUILD_ID = 3,
    /// Version note generated by GNU gold containing a version string.
    NT_GNU_GOLD_VERSION = 4,
    /// Program property.
    NT_GNU_PROPERTY_TYPE_0 = 5,
});

/// OS descriptor for `NT_GNU_ABI_TAG`.
pub const ELF_NOTE_OS_LINUX: u32 = 0;
/// OS descriptor for `NT_GNU_ABI_TAG`.
pub const ELF_NOTE_OS_GNU: u32 = 1;
/// OS descriptor for `NT_GNU_ABI_TAG`.
pub const ELF_NOTE_OS_SOLARIS2: u32 = 2;
/// OS descriptor for `NT_GNU_ABI_TAG`.
pub const ELF_NOTE_OS_FREEBSD: u32 = 3;

newtype!(
    /// Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0).
    struct GnuPropertyType(u32);
);

impl GnuPropertyType {
    /// A 4-byte unsigned integer property: A bit is set if it is set in all
    /// relocatable inputs.
    pub fn is_uint32_and(self) -> bool {
        self.0 >= GNU_PROPERTY_UINT32_AND_LO && self.0 <= GNU_PROPERTY_UINT32_AND_HI
    }
    /// A 4-byte unsigned integer property: A bit is set if it is set in any
    /// relocatable inputs.
    pub fn is_uint32_or(self) -> bool {
        self.0 >= GNU_PROPERTY_UINT32_OR_LO && self.0 <= GNU_PROPERTY_UINT32_OR_HI
    }
    /// Return true if the property is in the processor-specific range.
    pub fn is_proc(self) -> bool {
        self.0 >= GNU_PROPERTY_LOPROC && self.0 <= GNU_PROPERTY_HIPROC
    }
    /// Return true if the property is in the application-specific range.
    pub fn is_user(self) -> bool {
        debug_assert_eq!(GNU_PROPERTY_HIUSER, !0);
        self.0 >= GNU_PROPERTY_LOUSER
    }
    /// A 4-byte unsigned integer property: A bit is set if it is set in all
    /// relocatable inputs.
    pub fn is_x86_uint32_and(self) -> bool {
        self.0 >= GNU_PROPERTY_X86_UINT32_AND_LO && self.0 <= GNU_PROPERTY_X86_UINT32_AND_HI
    }
    /// A 4-byte unsigned integer property: A bit is set if it is set in any
    /// relocatable inputs.
    pub fn is_x86_uint32_or(self) -> bool {
        self.0 >= GNU_PROPERTY_X86_UINT32_OR_LO && self.0 <= GNU_PROPERTY_X86_UINT32_OR_HI
    }
    /// A 4-byte unsigned integer property: A bit is set if it is set in any
    /// relocatable inputs and the property is present in all relocatable
    /// inputs.
    pub fn is_x86_uint32_or_and(self) -> bool {
        self.0 >= GNU_PROPERTY_X86_UINT32_OR_AND_LO && self.0 <= GNU_PROPERTY_X86_UINT32_OR_AND_HI
    }

    /// Return the property type names for the given machine.
    #[cfg(feature = "names")]
    pub fn type_names(machine: Machine) -> &'static ConstantNames<Self> {
        match machine {
            EM_386 | EM_X86_64 => &NAMES_GNU_PROPERTY_X86,
            EM_AARCH64 => &NAMES_GNU_PROPERTY_AARCH64,
            _ => &NAMES_GNU_PROPERTY,
        }
    }

    /// Return the property values names for the given machine if the property
    /// data is a u32.
    #[cfg(feature = "names")]
    pub fn u32_value_names(self, machine: Machine) -> Option<&'static FlagNames<u32>> {
        match self {
            GNU_PROPERTY_1_NEEDED => {
                return Some(&NAMES_GNU_PROPERTY_1_NEEDED);
            }
            _ => {}
        }
        match machine {
            EM_386 | EM_X86_64 => match self {
                GNU_PROPERTY_X86_ISA_1_USED | GNU_PROPERTY_X86_ISA_1_NEEDED => {
                    return Some(&NAMES_GNU_PROPERTY_X86_ISA_1);
                }
                GNU_PROPERTY_X86_FEATURE_1_AND => {
                    return Some(&NAMES_GNU_PROPERTY_X86_FEATURE_1);
                }
                _ => {}
            },
            EM_AARCH64 => match self {
                GNU_PROPERTY_AARCH64_FEATURE_1_AND => {
                    return Some(&NAMES_GNU_PROPERTY_AARCH64_FEATURE_1);
                }
                _ => {}
            },
            _ => {}
        }
        None
    }
}

newtype_constant_names!(NAMES_GNU_PROPERTY: GnuPropertyType(u32) = {
    /// Stack size.
    GNU_PROPERTY_STACK_SIZE = 1,
    /// No copy relocation on protected data symbol.
    GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
    /// The needed properties by the object file.  */
    GNU_PROPERTY_1_NEEDED = GNU_PROPERTY_UINT32_OR_LO,
});

flag_names!(NAMES_GNU_PROPERTY_1_NEEDED: u32 = {
    /// Set if the object file requires canonical function pointers and
    /// cannot be used with copy relocation.
    GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS = 1 << 0,
});

// A 4-byte unsigned integer property: A bit is set if it is set in all
// relocatable inputs.
pub const GNU_PROPERTY_UINT32_AND_LO: u32 = 0xb0000000;
pub const GNU_PROPERTY_UINT32_AND_HI: u32 = 0xb0007fff;

// A 4-byte unsigned integer property: A bit is set if it is set in any
// relocatable inputs.
pub const GNU_PROPERTY_UINT32_OR_LO: u32 = 0xb0008000;
pub const GNU_PROPERTY_UINT32_OR_HI: u32 = 0xb000ffff;

/// Processor-specific semantics, lo
pub const GNU_PROPERTY_LOPROC: u32 = 0xc0000000;
/// Processor-specific semantics, hi
pub const GNU_PROPERTY_HIPROC: u32 = 0xdfffffff;
/// Application-specific semantics, lo
pub const GNU_PROPERTY_LOUSER: u32 = 0xe0000000;
/// Application-specific semantics, hi
pub const GNU_PROPERTY_HIUSER: u32 = 0xffffffff;

constant_names!(NAMES_GNU_PROPERTY_AARCH64: GnuPropertyType(u32) = NAMES_GNU_PROPERTY + {
    GNU_PROPERTY_AARCH64_FEATURE_1_AND = 0xc0000000,
    GNU_PROPERTY_AARCH64_FEATURE_PAUTH = 0xc0000001,
});

flag_names!(NAMES_GNU_PROPERTY_AARCH64_FEATURE_1: u32 = {
    GNU_PROPERTY_AARCH64_FEATURE_1_BTI = 1 << 0,
    GNU_PROPERTY_AARCH64_FEATURE_1_PAC = 1 << 1,
});

// A 4-byte unsigned integer property: A bit is set if it is set in all
// relocatable inputs.
pub const GNU_PROPERTY_X86_UINT32_AND_LO: u32 = 0xc0000002;
pub const GNU_PROPERTY_X86_UINT32_AND_HI: u32 = 0xc0007fff;

// A 4-byte unsigned integer property: A bit is set if it is set in any
// relocatable inputs.
pub const GNU_PROPERTY_X86_UINT32_OR_LO: u32 = 0xc0008000;
pub const GNU_PROPERTY_X86_UINT32_OR_HI: u32 = 0xc000ffff;

// A 4-byte unsigned integer property: A bit is set if it is set in any
// relocatable inputs and the property is present in all relocatable
// inputs.
pub const GNU_PROPERTY_X86_UINT32_OR_AND_LO: u32 = 0xc0010000;
pub const GNU_PROPERTY_X86_UINT32_OR_AND_HI: u32 = 0xc0017fff;

constant_names!(NAMES_GNU_PROPERTY_X86: GnuPropertyType(u32) = NAMES_GNU_PROPERTY + {
    /// The x86 instruction sets indicated by the corresponding bits are
    /// used in program.  Their support in the hardware is optional.
    GNU_PROPERTY_X86_ISA_1_USED = 0xc0010002,
    /// The x86 instruction sets indicated by the corresponding bits are
    /// used in program and they must be supported by the hardware.
    GNU_PROPERTY_X86_ISA_1_NEEDED = 0xc0008002,
    /// X86 processor-specific features used in program.
    GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002,
});

flag_names!(NAMES_GNU_PROPERTY_X86_ISA_1: u32 = {
    /// GNU_PROPERTY_X86_ISA_1_BASELINE: CMOV, CX8 (cmpxchg8b), FPU (fld),
    /// MMX, OSFXSR (fxsave), SCE (syscall), SSE and SSE2.
    GNU_PROPERTY_X86_ISA_1_BASELINE = 1 << 0,
    /// GNU_PROPERTY_X86_ISA_1_V2: GNU_PROPERTY_X86_ISA_1_BASELINE,
    /// CMPXCHG16B (cmpxchg16b), LAHF-SAHF (lahf), POPCNT (popcnt), SSE3,
    /// SSSE3, SSE4.1 and SSE4.2.
    GNU_PROPERTY_X86_ISA_1_V2 = 1 << 1,
    /// GNU_PROPERTY_X86_ISA_1_V3: GNU_PROPERTY_X86_ISA_1_V2, AVX, AVX2, BMI1,
    /// BMI2, F16C, FMA, LZCNT, MOVBE, XSAVE.
    GNU_PROPERTY_X86_ISA_1_V3 = 1 << 2,
    /// GNU_PROPERTY_X86_ISA_1_V4: GNU_PROPERTY_X86_ISA_1_V3, AVX512F,
    /// AVX512BW, AVX512CD, AVX512DQ and AVX512VL.
    GNU_PROPERTY_X86_ISA_1_V4 = 1 << 3,
});

flag_names!(NAMES_GNU_PROPERTY_X86_FEATURE_1: u32 = {
    /// This indicates that all executable sections are compatible with IBT.
    GNU_PROPERTY_X86_FEATURE_1_IBT = 1 << 0,
    /// This indicates that all executable sections are compatible with SHSTK.
    GNU_PROPERTY_X86_FEATURE_1_SHSTK = 1 << 1,
});

// Note types for `ELF_NOTE_GO`.
constant_names!(NAMES_NT_GO: NoteType(u32) = {
    /// Build ID bits as generated by Go's gc compiler.
    ///
    /// The descriptor consists of any nonzero number of bytes.
    // See https://go-review.googlesource.com/10707.
    NT_GO_BUILD_ID = 4,
});

// TODO: Elf*_Move

/// Header of `SHT_HASH` section.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct HashHeader<E: Endian> {
    /// The number of hash buckets.
    pub bucket_count: U32<E>,
    /// The number of chain values.
    pub chain_count: U32<E>,
    // Array of hash bucket start indices.
    // buckets: U32<E>[bucket_count]
    // Array of hash chain links. An index of 0 terminates the chain.
    // chains: U32<E>[chain_count]
}

/// Calculate the SysV hash for a symbol name.
///
/// Used for `SHT_HASH`.
pub fn hash(name: &[u8]) -> u32 {
    let mut hash = 0u32;
    for byte in name {
        hash = hash.wrapping_mul(16).wrapping_add(u32::from(*byte));
        hash ^= (hash >> 24) & 0xf0;
    }
    hash & 0xfff_ffff
}

/// Header of `SHT_GNU_HASH` section.
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct GnuHashHeader<E: Endian> {
    /// The number of hash buckets.
    pub bucket_count: U32<E>,
    /// The symbol table index of the first symbol in the hash.
    pub symbol_base: U32<E>,
    /// The number of words in the bloom filter.
    ///
    /// Must be a non-zero power of 2.
    pub bloom_count: U32<E>,
    /// The bit shift count for the bloom filter.
    pub bloom_shift: U32<E>,
    // Array of bloom filter words.
    // bloom_filters: U32<E>[bloom_count] or U64<E>[bloom_count]
    // Array of hash bucket start indices.
    // buckets: U32<E>[bucket_count]
    // Array of hash values, one for each symbol starting at symbol_base.
    // values: U32<E>[symbol_count]
}

/// Calculate the GNU hash for a symbol name.
///
/// Used for `SHT_GNU_HASH`.
pub fn gnu_hash(name: &[u8]) -> u32 {
    let mut hash = 5381u32;
    for byte in name {
        hash = hash.wrapping_mul(33).wrapping_add(u32::from(*byte));
    }
    hash
}

// Motorola 68k specific definitions.

names! {
    struct M68k(Base);
    /// `Rel*::r_type` values for `EM_68K`.
    consts r = pub NAMES_R_68K: RelocationType(u32) = {
        /// No reloc
        R_68K_NONE = 0,
        /// Direct 32 bit
        R_68K_32 = 1,
        /// Direct 16 bit
        R_68K_16 = 2,
        /// Direct 8 bit
        R_68K_8 = 3,
        /// PC relative 32 bit
        R_68K_PC32 = 4,
        /// PC relative 16 bit
        R_68K_PC16 = 5,
        /// PC relative 8 bit
        R_68K_PC8 = 6,
        /// 32 bit PC relative GOT entry
        R_68K_GOT32 = 7,
        /// 16 bit PC relative GOT entry
        R_68K_GOT16 = 8,
        /// 8 bit PC relative GOT entry
        R_68K_GOT8 = 9,
        /// 32 bit GOT offset
        R_68K_GOT32O = 10,
        /// 16 bit GOT offset
        R_68K_GOT16O = 11,
        /// 8 bit GOT offset
        R_68K_GOT8O = 12,
        /// 32 bit PC relative PLT address
        R_68K_PLT32 = 13,
        /// 16 bit PC relative PLT address
        R_68K_PLT16 = 14,
        /// 8 bit PC relative PLT address
        R_68K_PLT8 = 15,
        /// 32 bit PLT offset
        R_68K_PLT32O = 16,
        /// 16 bit PLT offset
        R_68K_PLT16O = 17,
        /// 8 bit PLT offset
        R_68K_PLT8O = 18,
        /// Copy symbol at runtime
        R_68K_COPY = 19,
        /// Create GOT entry
        R_68K_GLOB_DAT = 20,
        /// Create PLT entry
        R_68K_JMP_SLOT = 21,
        /// Adjust by program base
        R_68K_RELATIVE = 22,
        /// 32 bit GOT offset for GD
        R_68K_TLS_GD32 = 25,
        /// 16 bit GOT offset for GD
        R_68K_TLS_GD16 = 26,
        /// 8 bit GOT offset for GD
        R_68K_TLS_GD8 = 27,
        /// 32 bit GOT offset for LDM
        R_68K_TLS_LDM32 = 28,
        /// 16 bit GOT offset for LDM
        R_68K_TLS_LDM16 = 29,
        /// 8 bit GOT offset for LDM
        R_68K_TLS_LDM8 = 30,
        /// 32 bit module-relative offset
        R_68K_TLS_LDO32 = 31,
        /// 16 bit module-relative offset
        R_68K_TLS_LDO16 = 32,
        /// 8 bit module-relative offset
        R_68K_TLS_LDO8 = 33,
        /// 32 bit GOT offset for IE
        R_68K_TLS_IE32 = 34,
        /// 16 bit GOT offset for IE
        R_68K_TLS_IE16 = 35,
        /// 8 bit GOT offset for IE
        R_68K_TLS_IE8 = 36,
        /// 32 bit offset relative to static TLS block
        R_68K_TLS_LE32 = 37,
        /// 16 bit offset relative to static TLS block
        R_68K_TLS_LE16 = 38,
        /// 8 bit offset relative to static TLS block
        R_68K_TLS_LE8 = 39,
        /// 32 bit module number
        R_68K_TLS_DTPMOD32 = 40,
        /// 32 bit module-relative offset
        R_68K_TLS_DTPREL32 = 41,
        /// 32 bit TP-relative offset
        R_68K_TLS_TPREL32 = 42,
    };
}

// Intel 80386 specific definitions.

names! {
    struct I386(Base);
    /// `Rel*::r_type` values for `EM_386`.
    consts r = pub NAMES_R_386: RelocationType(u32) = {
        /// No reloc
        R_386_NONE = 0,
        /// Direct 32 bit
        R_386_32 = 1,
        /// PC relative 32 bit
        R_386_PC32 = 2,
        /// 32 bit GOT entry
        R_386_GOT32 = 3,
        /// 32 bit PLT address
        R_386_PLT32 = 4,
        /// Copy symbol at runtime
        R_386_COPY = 5,
        /// Create GOT entry
        R_386_GLOB_DAT = 6,
        /// Create PLT entry
        R_386_JMP_SLOT = 7,
        /// Adjust by program base
        R_386_RELATIVE = 8,
        /// 32 bit offset to GOT
        R_386_GOTOFF = 9,
        /// 32 bit PC relative offset to GOT
        R_386_GOTPC = 10,
        /// Direct 32 bit PLT address
        R_386_32PLT = 11,
        /// Offset in static TLS block
        R_386_TLS_TPOFF = 14,
        /// Address of GOT entry for static TLS block offset
        R_386_TLS_IE = 15,
        /// GOT entry for static TLS block offset
        R_386_TLS_GOTIE = 16,
        /// Offset relative to static TLS block
        R_386_TLS_LE = 17,
        /// Direct 32 bit for GNU version of general dynamic thread local data
        R_386_TLS_GD = 18,
        /// Direct 32 bit for GNU version of local dynamic thread local data in LE code
        R_386_TLS_LDM = 19,
        /// Direct 16 bit
        R_386_16 = 20,
        /// PC relative 16 bit
        R_386_PC16 = 21,
        /// Direct 8 bit
        R_386_8 = 22,
        /// PC relative 8 bit
        R_386_PC8 = 23,
        /// Direct 32 bit for general dynamic thread local data
        R_386_TLS_GD_32 = 24,
        /// Tag for pushl in GD TLS code
        R_386_TLS_GD_PUSH = 25,
        /// Relocation for call to __tls_get_addr()
        R_386_TLS_GD_CALL = 26,
        /// Tag for popl in GD TLS code
        R_386_TLS_GD_POP = 27,
        /// Direct 32 bit for local dynamic thread local data in LE code
        R_386_TLS_LDM_32 = 28,
        /// Tag for pushl in LDM TLS code
        R_386_TLS_LDM_PUSH = 29,
        /// Relocation for call to __tls_get_addr() in LDM code
        R_386_TLS_LDM_CALL = 30,
        /// Tag for popl in LDM TLS code
        R_386_TLS_LDM_POP = 31,
        /// Offset relative to TLS block
        R_386_TLS_LDO_32 = 32,
        /// GOT entry for negated static TLS block offset
        R_386_TLS_IE_32 = 33,
        /// Negated offset relative to static TLS block
        R_386_TLS_LE_32 = 34,
        /// ID of module containing symbol
        R_386_TLS_DTPMOD32 = 35,
        /// Offset in TLS block
        R_386_TLS_DTPOFF32 = 36,
        /// Negated offset in static TLS block
        R_386_TLS_TPOFF32 = 37,
        /// 32-bit symbol size
        R_386_SIZE32 = 38,
        /// GOT offset for TLS descriptor.
        R_386_TLS_GOTDESC = 39,
        /// Marker of call through TLS descriptor for relaxation.
        R_386_TLS_DESC_CALL = 40,
        /// TLS descriptor containing pointer to code and to argument, returning the TLS offset for the symbol.
        R_386_TLS_DESC = 41,
        /// Adjust indirectly by program base
        R_386_IRELATIVE = 42,
        /// Load from 32 bit GOT entry, relaxable.
        R_386_GOT32X = 43,
    };
}

// ADI SHARC specific definitions

names! {
    struct Sharc(Base);
    /// `Rel*::r_type` values for `EM_SHARC`.
    consts r = pub NAMES_R_SHARC: RelocationType(u32) = {
        /// 24-bit absolute address in bits 23:0 of a 48-bit instr
        ///
        /// Targets:
        ///
        /// * Type 25a (PC_DIRECT)
        R_SHARC_ADDR24_V3 = 0x0b,

        /// 32-bit absolute address in bits 31:0 of a 48-bit instr
        ///
        /// Targets:
        ///
        /// * Type 14a
        /// * Type 14d
        /// * Type 15a
        /// * Type 16a
        /// * Type 17a
        /// * Type 18a
        /// * Type 19a
        R_SHARC_ADDR32_V3 = 0x0c,

        /// 32-bit absolute address in bits 31:0 of a 32-bit data location
        ///
        /// Represented with `RelocationEncoding::Generic`
        R_SHARC_ADDR_VAR_V3 = 0x0d,

        /// 6-bit PC-relative address in bits 32:27 of a 48-bit instr
        ///
        /// Targets:
        ///
        /// * Type 9a
        /// * Type 10a
        R_SHARC_PCRSHORT_V3 = 0x0e,

        /// 24-bit PC-relative address in bits 23:0 of a 48-bit instr
        ///
        /// Targets:
        ///
        /// * Type 8a
        /// * Type 12a (truncated to 23 bits after relocation)
        /// * Type 13a (truncated to 23 bits after relocation)
        /// * Type 25a (PC Relative)
        R_SHARC_PCRLONG_V3 = 0x0f,

        /// 6-bit absolute address in bits 32:27 of a 48-bit instr
        ///
        /// Targets:
        ///
        /// * Type 4a
        /// * Type 4b
        /// * Type 4d
        R_SHARC_DATA6_V3 = 0x10,

        /// 16-bit absolute address in bits 39:24 of a 48-bit instr
        ///
        /// Targets:
        ///
        /// * Type 12a
        R_SHARC_DATA16_V3 = 0x11,

        /// 6-bit absolute address into bits 16:11 of a 32-bit instr
        ///
        /// Targets:
        ///
        /// * Type 4b
        R_SHARC_DATA6_VISA_V3 = 0x12,

        /// 7-bit absolute address into bits 6:0 of a 32-bit instr
        R_SHARC_DATA7_VISA_V3 = 0x13,

        /// 16-bit absolute address into bits 15:0 of a 32-bit instr
        R_SHARC_DATA16_VISA_V3 = 0x14,

        /// 6-bit PC-relative address into bits 16:11 of a Type B
        ///
        /// Targets:
        ///
        /// * Type 9b
        R_SHARC_PCR6_VISA_V3 = 0x17,

        /// 16-bit absolute address into bits 15:0 of a 16-bit location.
        ///
        /// Represented with `RelocationEncoding::Generic`
        R_SHARC_ADDR_VAR16_V3 = 0x19,

        R_SHARC_CALC_PUSH_ADDR = 0xe0,
        R_SHARC_CALC_PUSH_ADDEND = 0xe1,
        R_SHARC_CALC_ADD = 0xe2,
        R_SHARC_CALC_SUB = 0xe3,
        R_SHARC_CALC_MUL = 0xe4,
        R_SHARC_CALC_DIV = 0xe5,
        R_SHARC_CALC_MOD = 0xe6,
        R_SHARC_CALC_LSHIFT = 0xe7,
        R_SHARC_CALC_RSHIFT = 0xe8,
        R_SHARC_CALC_AND = 0xe9,
        R_SHARC_CALC_OR = 0xea,
        R_SHARC_CALC_XOR = 0xeb,
        R_SHARC_CALC_PUSH_LEN = 0xec,
        R_SHARC_CALC_NOT = 0xf6,
    };
    consts sht: SectionType(u32) = {
        /// .adi.attributes
        SHT_SHARC_ADI_ATTRIBUTES = SHT_LOPROC + 0x2,
    };
}

// SUN SPARC specific definitions.

names! {
    struct Sparc(Base);
    consts stt: SymbolType(u8) = {
        /// Global register reserved to app.
        STT_SPARC_REGISTER = 13,
    };
    flags ef: FileFlags(u32) = {
        /// little endian data
        EF_SPARC_LEDATA = 0x80_0000,
        /// generic V8+ features
        EF_SPARC_32PLUS = 0x00_0100,
        /// Sun UltraSPARC1 extensions
        EF_SPARC_SUN_US1 = 0x00_0200,
        /// HAL R1 extensions
        EF_SPARC_HAL_R1 = 0x00_0400,
        /// Sun UltraSPARCIII extensions
        EF_SPARC_SUN_US3 = 0x00_0800,
    };
    /// `Rel*::r_type` values for `EM_SPARC` and `EM_SPARC32PLUS`.
    consts r = pub NAMES_R_SPARC: RelocationType(u32) = {
        /// No reloc
        R_SPARC_NONE = 0,
        /// Direct 8 bit
        R_SPARC_8 = 1,
        /// Direct 16 bit
        R_SPARC_16 = 2,
        /// Direct 32 bit
        R_SPARC_32 = 3,
        /// PC relative 8 bit
        R_SPARC_DISP8 = 4,
        /// PC relative 16 bit
        R_SPARC_DISP16 = 5,
        /// PC relative 32 bit
        R_SPARC_DISP32 = 6,
        /// PC relative 30 bit shifted
        R_SPARC_WDISP30 = 7,
        /// PC relative 22 bit shifted
        R_SPARC_WDISP22 = 8,
        /// High 22 bit
        R_SPARC_HI22 = 9,
        /// Direct 22 bit
        R_SPARC_22 = 10,
        /// Direct 13 bit
        R_SPARC_13 = 11,
        /// Truncated 10 bit
        R_SPARC_LO10 = 12,
        /// Truncated 10 bit GOT entry
        R_SPARC_GOT10 = 13,
        /// 13 bit GOT entry
        R_SPARC_GOT13 = 14,
        /// 22 bit GOT entry shifted
        R_SPARC_GOT22 = 15,
        /// PC relative 10 bit truncated
        R_SPARC_PC10 = 16,
        /// PC relative 22 bit shifted
        R_SPARC_PC22 = 17,
        /// 30 bit PC relative PLT address
        R_SPARC_WPLT30 = 18,
        /// Copy symbol at runtime
        R_SPARC_COPY = 19,
        /// Create GOT entry
        R_SPARC_GLOB_DAT = 20,
        /// Create PLT entry
        R_SPARC_JMP_SLOT = 21,
        /// Adjust by program base
        R_SPARC_RELATIVE = 22,
        /// Direct 32 bit unaligned
        R_SPARC_UA32 = 23,

        /// Direct 32 bit ref to PLT entry
        R_SPARC_PLT32 = 24,
        /// High 22 bit PLT entry
        R_SPARC_HIPLT22 = 25,
        /// Truncated 10 bit PLT entry
        R_SPARC_LOPLT10 = 26,
        /// PC rel 32 bit ref to PLT entry
        R_SPARC_PCPLT32 = 27,
        /// PC rel high 22 bit PLT entry
        R_SPARC_PCPLT22 = 28,
        /// PC rel trunc 10 bit PLT entry
        R_SPARC_PCPLT10 = 29,
        /// Direct 10 bit
        R_SPARC_10 = 30,
        /// Direct 11 bit
        R_SPARC_11 = 31,
        /// Direct 64 bit
        R_SPARC_64 = 32,
        /// 10bit with secondary 13bit addend
        R_SPARC_OLO10 = 33,
        /// Top 22 bits of direct 64 bit
        R_SPARC_HH22 = 34,
        /// High middle 10 bits of ...
        R_SPARC_HM10 = 35,
        /// Low middle 22 bits of ...
        R_SPARC_LM22 = 36,
        /// Top 22 bits of pc rel 64 bit
        R_SPARC_PC_HH22 = 37,
        /// High middle 10 bit of ...
        R_SPARC_PC_HM10 = 38,
        /// Low miggle 22 bits of ...
        R_SPARC_PC_LM22 = 39,
        /// PC relative 16 bit shifted
        R_SPARC_WDISP16 = 40,
        /// PC relative 19 bit shifted
        R_SPARC_WDISP19 = 41,
        /// was part of v9 ABI but was removed
        R_SPARC_GLOB_JMP = 42,
        /// Direct 7 bit
        R_SPARC_7 = 43,
        /// Direct 5 bit
        R_SPARC_5 = 44,
        /// Direct 6 bit
        R_SPARC_6 = 45,
        /// PC relative 64 bit
        R_SPARC_DISP64 = 46,
        /// Direct 64 bit ref to PLT entry
        R_SPARC_PLT64 = 47,
        /// High 22 bit complemented
        R_SPARC_HIX22 = 48,
        /// Truncated 11 bit complemented
        R_SPARC_LOX10 = 49,
        /// Direct high 12 of 44 bit
        R_SPARC_H44 = 50,
        /// Direct mid 22 of 44 bit
        R_SPARC_M44 = 51,
        /// Direct low 10 of 44 bit
        R_SPARC_L44 = 52,
        /// Global register usage
        R_SPARC_REGISTER = 53,
        /// Direct 64 bit unaligned
        R_SPARC_UA64 = 54,
        /// Direct 16 bit unaligned
        R_SPARC_UA16 = 55,
        R_SPARC_TLS_GD_HI22 = 56,
        R_SPARC_TLS_GD_LO10 = 57,
        R_SPARC_TLS_GD_ADD = 58,
        R_SPARC_TLS_GD_CALL = 59,
        R_SPARC_TLS_LDM_HI22 = 60,
        R_SPARC_TLS_LDM_LO10 = 61,
        R_SPARC_TLS_LDM_ADD = 62,
        R_SPARC_TLS_LDM_CALL = 63,
        R_SPARC_TLS_LDO_HIX22 = 64,
        R_SPARC_TLS_LDO_LOX10 = 65,
        R_SPARC_TLS_LDO_ADD = 66,
        R_SPARC_TLS_IE_HI22 = 67,
        R_SPARC_TLS_IE_LO10 = 68,
        R_SPARC_TLS_IE_LD = 69,
        R_SPARC_TLS_IE_LDX = 70,
        R_SPARC_TLS_IE_ADD = 71,
        R_SPARC_TLS_LE_HIX22 = 72,
        R_SPARC_TLS_LE_LOX10 = 73,
        R_SPARC_TLS_DTPMOD32 = 74,
        R_SPARC_TLS_DTPMOD64 = 75,
        R_SPARC_TLS_DTPOFF32 = 76,
        R_SPARC_TLS_DTPOFF64 = 77,
        R_SPARC_TLS_TPOFF32 = 78,
        R_SPARC_TLS_TPOFF64 = 79,
        R_SPARC_GOTDATA_HIX22 = 80,
        R_SPARC_GOTDATA_LOX10 = 81,
        R_SPARC_GOTDATA_OP_HIX22 = 82,
        R_SPARC_GOTDATA_OP_LOX10 = 83,
        R_SPARC_GOTDATA_OP = 84,
        R_SPARC_H34 = 85,
        R_SPARC_SIZE32 = 86,
        R_SPARC_SIZE64 = 87,
        R_SPARC_WDISP10 = 88,
        R_SPARC_JMP_IREL = 248,
        R_SPARC_IRELATIVE = 249,
        R_SPARC_GNU_VTINHERIT = 250,
        R_SPARC_GNU_VTENTRY = 251,
        R_SPARC_REV32 = 252,
    };
    consts dt: DynamicTag(i64) = {
        DT_SPARC_REGISTER = 0x7000_0001,
    };
}

pub const EF_SPARC_EXT_MASK: u32 = 0xFF_FF00;

names! {
    struct SparcV9(Sparc);
    flags ef: FileFlags(u32) = {
        EF_SPARCV9_MM = 3 => NAMES_EF_SPARC_MM,
    };
}

constant_names!(NAMES_EF_SPARC_MM: FileFlags(u32) = {
    EF_SPARCV9_TSO = 0,
    EF_SPARCV9_PSO = 1,
    EF_SPARCV9_RMO = 2,
});

// MIPS R3000 specific definitions.

names! {
    struct Mips(Base);
    flags ef: FileFlags(u32) = {
        /// A .noreorder directive was used.
        EF_MIPS_NOREORDER = 1,
        /// Contains PIC code.
        EF_MIPS_PIC = 2,
        /// Uses PIC calling sequence.
        EF_MIPS_CPIC = 4,
        EF_MIPS_XGOT = 8,
        EF_MIPS_64BIT_WHIRL = 16,
        EF_MIPS_ABI2 = 32,
        EF_MIPS_ABI_ON32 = 64,
        /// Uses FP64 (12 callee-saved).
        EF_MIPS_FP64 = 512,
        /// Uses IEEE 754-2008 NaN encoding.
        EF_MIPS_NAN2008 = 1024,
        /// Mask for selecting EF_MIPS_ABI_ variant
        EF_MIPS_ABI = 0x0000_f000 => NAMES_EF_MIPS_ABI,
        /// MIPS architecture level.
        EF_MIPS_ARCH = 0xf000_0000 => NAMES_EF_MIPS_ARCH,
    };
    consts shn: SymbolSection(u16) = {
        /// Allocated common symbols.
        SHN_MIPS_ACOMMON = 0xff00,
        /// Allocated test symbols.
        SHN_MIPS_TEXT = 0xff01,
        /// Allocated data symbols.
        SHN_MIPS_DATA = 0xff02,
        /// Small common symbols.
        SHN_MIPS_SCOMMON = 0xff03,
        /// Small undefined symbols.
        SHN_MIPS_SUNDEFINED = 0xff04,
    };
    consts sht: SectionType(u32) = {
        /// Shared objects used in link.
        SHT_MIPS_LIBLIST = 0x7000_0000,
        SHT_MIPS_MSYM = 0x7000_0001,
        /// Conflicting symbols.
        SHT_MIPS_CONFLICT = 0x7000_0002,
        /// Global data area sizes.
        SHT_MIPS_GPTAB = 0x7000_0003,
        /// Reserved for SGI/MIPS compilers
        SHT_MIPS_UCODE = 0x7000_0004,
        /// MIPS ECOFF debugging info.
        SHT_MIPS_DEBUG = 0x7000_0005,
        /// Register usage information.
        SHT_MIPS_REGINFO = 0x7000_0006,
        SHT_MIPS_PACKAGE = 0x7000_0007,
        SHT_MIPS_PACKSYM = 0x7000_0008,
        SHT_MIPS_RELD = 0x7000_0009,
        SHT_MIPS_IFACE = 0x7000_000b,
        SHT_MIPS_CONTENT = 0x7000_000c,
        /// Miscellaneous options.
        SHT_MIPS_OPTIONS = 0x7000_000d,
        SHT_MIPS_SHDR = 0x7000_0010,
        SHT_MIPS_FDESC = 0x7000_0011,
        SHT_MIPS_EXTSYM = 0x7000_0012,
        SHT_MIPS_DENSE = 0x7000_0013,
        SHT_MIPS_PDESC = 0x7000_0014,
        SHT_MIPS_LOCSYM = 0x7000_0015,
        SHT_MIPS_AUXSYM = 0x7000_0016,
        SHT_MIPS_OPTSYM = 0x7000_0017,
        SHT_MIPS_LOCSTR = 0x7000_0018,
        SHT_MIPS_LINE = 0x7000_0019,
        SHT_MIPS_RFDESC = 0x7000_001a,
        SHT_MIPS_DELTASYM = 0x7000_001b,
        SHT_MIPS_DELTAINST = 0x7000_001c,
        SHT_MIPS_DELTACLASS = 0x7000_001d,
        /// DWARF debugging information.
        SHT_MIPS_DWARF = 0x7000_001e,
        SHT_MIPS_DELTADECL = 0x7000_001f,
        SHT_MIPS_SYMBOL_LIB = 0x7000_0020,
        /// Event section.
        SHT_MIPS_EVENTS = 0x7000_0021,
        SHT_MIPS_TRANSLATE = 0x7000_0022,
        SHT_MIPS_PIXIE = 0x7000_0023,
        SHT_MIPS_XLATE = 0x7000_0024,
        SHT_MIPS_XLATE_DEBUG = 0x7000_0025,
        SHT_MIPS_WHIRL = 0x7000_0026,
        SHT_MIPS_EH_REGION = 0x7000_0027,
        SHT_MIPS_XLATE_OLD = 0x7000_0028,
        SHT_MIPS_PDR_EXCEPTION = 0x7000_0029,
    };
    flags shf: SectionFlags(u64) = {
        /// Must be in global data area.
        SHF_MIPS_GPREL = 0x1000_0000,
        SHF_MIPS_MERGE = 0x2000_0000,
        SHF_MIPS_ADDR = 0x4000_0000,
        SHF_MIPS_STRINGS = 0x8000_0000,
        SHF_MIPS_NOSTRIP = 0x0800_0000,
        SHF_MIPS_LOCAL = 0x0400_0000,
        SHF_MIPS_NAMES = 0x0200_0000,
        SHF_MIPS_NODUPE = 0x0100_0000,
    };
    flags sto: SymbolOther(u8) = {
        STO_MIPS_PLT = 0x8,
    };
    consts stb: SymbolBind(u8) = {
        STB_MIPS_SPLIT_COMMON = 13,
    };
    /// `Rel*::r_type` values for `EM_MIPS`.
    consts r = pub NAMES_R_MIPS: RelocationType(u32) = {
        /// No reloc
        R_MIPS_NONE = 0,
        /// Direct 16 bit
        R_MIPS_16 = 1,
        /// Direct 32 bit
        R_MIPS_32 = 2,
        /// PC relative 32 bit
        R_MIPS_REL32 = 3,
        /// Direct 26 bit shifted
        R_MIPS_26 = 4,
        /// High 16 bit
        R_MIPS_HI16 = 5,
        /// Low 16 bit
        R_MIPS_LO16 = 6,
        /// GP relative 16 bit
        R_MIPS_GPREL16 = 7,
        /// 16 bit literal entry
        R_MIPS_LITERAL = 8,
        /// 16 bit GOT entry
        R_MIPS_GOT16 = 9,
        /// PC relative 16 bit
        R_MIPS_PC16 = 10,
        /// 16 bit GOT entry for function
        R_MIPS_CALL16 = 11,
        /// GP relative 32 bit
        R_MIPS_GPREL32 = 12,

        R_MIPS_SHIFT5 = 16,
        R_MIPS_SHIFT6 = 17,
        R_MIPS_64 = 18,
        R_MIPS_GOT_DISP = 19,
        R_MIPS_GOT_PAGE = 20,
        R_MIPS_GOT_OFST = 21,
        R_MIPS_GOT_HI16 = 22,
        R_MIPS_GOT_LO16 = 23,
        R_MIPS_SUB = 24,
        R_MIPS_INSERT_A = 25,
        R_MIPS_INSERT_B = 26,
        R_MIPS_DELETE = 27,
        R_MIPS_HIGHER = 28,
        R_MIPS_HIGHEST = 29,
        R_MIPS_CALL_HI16 = 30,
        R_MIPS_CALL_LO16 = 31,
        R_MIPS_SCN_DISP = 32,
        R_MIPS_REL16 = 33,
        R_MIPS_ADD_IMMEDIATE = 34,
        R_MIPS_PJUMP = 35,
        R_MIPS_RELGOT = 36,
        R_MIPS_JALR = 37,
        /// Module number 32 bit
        R_MIPS_TLS_DTPMOD32 = 38,
        /// Module-relative offset 32 bit
        R_MIPS_TLS_DTPREL32 = 39,
        /// Module number 64 bit
        R_MIPS_TLS_DTPMOD64 = 40,
        /// Module-relative offset 64 bit
        R_MIPS_TLS_DTPREL64 = 41,
        /// 16 bit GOT offset for GD
        R_MIPS_TLS_GD = 42,
        /// 16 bit GOT offset for LDM
        R_MIPS_TLS_LDM = 43,
        /// Module-relative offset, high 16 bits
        R_MIPS_TLS_DTPREL_HI16 = 44,
        /// Module-relative offset, low 16 bits
        R_MIPS_TLS_DTPREL_LO16 = 45,
        /// 16 bit GOT offset for IE
        R_MIPS_TLS_GOTTPREL = 46,
        /// TP-relative offset, 32 bit
        R_MIPS_TLS_TPREL32 = 47,
        /// TP-relative offset, 64 bit
        R_MIPS_TLS_TPREL64 = 48,
        /// TP-relative offset, high 16 bits
        R_MIPS_TLS_TPREL_HI16 = 49,
        /// TP-relative offset, low 16 bits
        R_MIPS_TLS_TPREL_LO16 = 50,
        R_MIPS_GLOB_DAT = 51,
        R_MIPS_COPY = 126,
        R_MIPS_JUMP_SLOT = 127,
    };
    consts pt: ProgramType(u32) = {
        /// Register usage information.
        PT_MIPS_REGINFO = 0x7000_0000,
        /// Runtime procedure table.
        PT_MIPS_RTPROC = 0x7000_0001,
        PT_MIPS_OPTIONS = 0x7000_0002,
        /// FP mode requirement.
        PT_MIPS_ABIFLAGS = 0x7000_0003,
    };
    flags pf: ProgramFlags(u32) = {
        PF_MIPS_LOCAL = 0x1000_0000,
    };
    consts dt: DynamicTag(i64) = {
        /// Runtime linker interface version
        DT_MIPS_RLD_VERSION = 0x7000_0001,
        /// Timestamp
        DT_MIPS_TIME_STAMP = 0x7000_0002,
        /// Checksum
        DT_MIPS_ICHECKSUM = 0x7000_0003,
        /// Version string (string tbl index)
        DT_MIPS_IVERSION = 0x7000_0004,
        /// Flags
        DT_MIPS_FLAGS = 0x7000_0005,
        /// Base address
        DT_MIPS_BASE_ADDRESS = 0x7000_0006,
        DT_MIPS_MSYM = 0x7000_0007,
        /// Address of CONFLICT section
        DT_MIPS_CONFLICT = 0x7000_0008,
        /// Address of LIBLIST section
        DT_MIPS_LIBLIST = 0x7000_0009,
        /// Number of local GOT entries
        DT_MIPS_LOCAL_GOTNO = 0x7000_000a,
        /// Number of CONFLICT entries
        DT_MIPS_CONFLICTNO = 0x7000_000b,
        /// Number of LIBLIST entries
        DT_MIPS_LIBLISTNO = 0x7000_0010,
        /// Number of DYNSYM entries
        DT_MIPS_SYMTABNO = 0x7000_0011,
        /// First external DYNSYM
        DT_MIPS_UNREFEXTNO = 0x7000_0012,
        /// First GOT entry in DYNSYM
        DT_MIPS_GOTSYM = 0x7000_0013,
        /// Number of GOT page table entries
        DT_MIPS_HIPAGENO = 0x7000_0014,
        /// Address of run time loader map.
        DT_MIPS_RLD_MAP = 0x7000_0016,
        /// Delta C++ class definition.
        DT_MIPS_DELTA_CLASS = 0x7000_0017,
        /// Number of entries in DT_MIPS_DELTA_CLASS.
        DT_MIPS_DELTA_CLASS_NO = 0x7000_0018,
        /// Delta C++ class instances.
        DT_MIPS_DELTA_INSTANCE = 0x7000_0019,
        /// Number of entries in DT_MIPS_DELTA_INSTANCE.
        DT_MIPS_DELTA_INSTANCE_NO = 0x7000_001a,
        /// Delta relocations.
        DT_MIPS_DELTA_RELOC = 0x7000_001b,
        /// Number of entries in DT_MIPS_DELTA_RELOC.
        DT_MIPS_DELTA_RELOC_NO = 0x7000_001c,
        /// Delta symbols that Delta relocations refer to.
        DT_MIPS_DELTA_SYM = 0x7000_001d,
        /// Number of entries in DT_MIPS_DELTA_SYM.
        DT_MIPS_DELTA_SYM_NO = 0x7000_001e,
        /// Delta symbols that hold the class declaration.
        DT_MIPS_DELTA_CLASSSYM = 0x7000_0020,
        /// Number of entries in DT_MIPS_DELTA_CLASSSYM.
        DT_MIPS_DELTA_CLASSSYM_NO = 0x7000_0021,
        /// Flags indicating for C++ flavor.
        DT_MIPS_CXX_FLAGS = 0x7000_0022,
        DT_MIPS_PIXIE_INIT = 0x7000_0023,
        DT_MIPS_SYMBOL_LIB = 0x7000_0024,
        DT_MIPS_LOCALPAGE_GOTIDX = 0x7000_0025,
        DT_MIPS_LOCAL_GOTIDX = 0x7000_0026,
        DT_MIPS_HIDDEN_GOTIDX = 0x7000_0027,
        DT_MIPS_PROTECTED_GOTIDX = 0x7000_0028,
        /// Address of .options.
        DT_MIPS_OPTIONS = 0x7000_0029,
        /// Address of .interface.
        DT_MIPS_INTERFACE = 0x7000_002a,
        DT_MIPS_DYNSTR_ALIGN = 0x7000_002b,
        /// Size of the .interface section.
        DT_MIPS_INTERFACE_SIZE = 0x7000_002c,
        /// Address of rld_text_rsolve function stored in GOT.
        DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000_002d,
        /// Default suffix of dso to be added by rld on dlopen() calls.
        DT_MIPS_PERF_SUFFIX = 0x7000_002e,
        /// (O32)Size of compact rel section.
        DT_MIPS_COMPACT_SIZE = 0x7000_002f,
        /// GP value for aux GOTs.
        DT_MIPS_GP_VALUE = 0x7000_0030,
        /// Address of aux .dynamic.
        DT_MIPS_AUX_DYNAMIC = 0x7000_0031,
        /// The address of .got.plt in an executable using the new non-PIC ABI.
        DT_MIPS_PLTGOT = 0x7000_0032,
        /// The base of the PLT in an executable using the new non-PIC ABI if that PLT is writable.  For a non-writable PLT, this is omitted or has a zero value.
        DT_MIPS_RWPLT = 0x7000_0034,
        /// An alternative description of the classic MIPS RLD_MAP that is usable in a PIE as it stores a relative offset from the address of the tag rather than an absolute address.
        DT_MIPS_RLD_MAP_REL = 0x7000_0035,
    };
}

constant_names!(NAMES_EF_MIPS_ABI: FileFlags(u32) = {
    /// The first MIPS 32 bit ABI
    EF_MIPS_ABI_O32 = 0x0000_1000,
    /// O32 ABI extended for 64-bit architectures
    EF_MIPS_ABI_O64 = 0x0000_2000,
    /// EABI in 32-bit mode
    EF_MIPS_ABI_EABI32 = 0x0000_3000,
    /// EABI in 64-bit mode
    EF_MIPS_ABI_EABI64 = 0x0000_4000,
});

constant_names!(NAMES_EF_MIPS_ARCH: FileFlags(u32) = {
    /// -mips1 code.
    EF_MIPS_ARCH_1 = 0x0000_0000,
    /// -mips2 code.
    EF_MIPS_ARCH_2 = 0x1000_0000,
    /// -mips3 code.
    EF_MIPS_ARCH_3 = 0x2000_0000,
    /// -mips4 code.
    EF_MIPS_ARCH_4 = 0x3000_0000,
    /// -mips5 code.
    EF_MIPS_ARCH_5 = 0x4000_0000,
    /// MIPS32 code.
    EF_MIPS_ARCH_32 = 0x5000_0000,
    /// MIPS64 code.
    EF_MIPS_ARCH_64 = 0x6000_0000,
    /// MIPS32r2 code.
    EF_MIPS_ARCH_32R2 = 0x7000_0000,
    /// MIPS64r2 code.
    EF_MIPS_ARCH_64R2 = 0x8000_0000,
    /// MIPS32r6 code
    EF_MIPS_ARCH_32R6 = 0x9000_0000,
    /// MIPS64r6 code
    EF_MIPS_ARCH_64R6 = 0xa000_0000,
});

// MIPS values for `Sym32::st_other`.

/// Only valid for `STB_MIPS_SPLIT_COMMON`.
pub const STO_MIPS_SC_ALIGN_UNUSED: u8 = 0xff;

// Entries found in sections of type `SHT_MIPS_GPTAB`.

// TODO: Elf32_gptab, Elf32_RegInfo, Elf_Options

// Values for `Elf_Options::kind`.

/// Undefined.
pub const ODK_NULL: u32 = 0;
/// Register usage information.
pub const ODK_REGINFO: u32 = 1;
/// Exception processing options.
pub const ODK_EXCEPTIONS: u32 = 2;
/// Section padding options.
pub const ODK_PAD: u32 = 3;
/// Hardware workarounds performed
pub const ODK_HWPATCH: u32 = 4;
/// record the fill value used by the linker.
pub const ODK_FILL: u32 = 5;
/// reserve space for desktop tools to write.
pub const ODK_TAGS: u32 = 6;
/// HW workarounds.  'AND' bits when merging.
pub const ODK_HWAND: u32 = 7;
/// HW workarounds.  'OR' bits when merging.
pub const ODK_HWOR: u32 = 8;

// Values for `Elf_Options::info` for `ODK_EXCEPTIONS` entries.

/// FPE's which MUST be enabled.
pub const OEX_FPU_MIN: u32 = 0x1f;
/// FPE's which MAY be enabled.
pub const OEX_FPU_MAX: u32 = 0x1f00;
/// page zero must be mapped.
pub const OEX_PAGE0: u32 = 0x10000;
/// Force sequential memory mode?
pub const OEX_SMM: u32 = 0x20000;
/// Force floating point debug mode?
pub const OEX_FPDBUG: u32 = 0x40000;
pub const OEX_PRECISEFP: u32 = OEX_FPDBUG;
/// Dismiss invalid address faults?
pub const OEX_DISMISS: u32 = 0x80000;

pub const OEX_FPU_INVAL: u32 = 0x10;
pub const OEX_FPU_DIV0: u32 = 0x08;
pub const OEX_FPU_OFLO: u32 = 0x04;
pub const OEX_FPU_UFLO: u32 = 0x02;
pub const OEX_FPU_INEX: u32 = 0x01;

// Masks for `Elf_Options::info` for an `ODK_HWPATCH` entry.  */
/// R4000 end-of-page patch.
pub const OHW_R4KEOP: u32 = 0x1;
/// may need R8000 prefetch patch.
pub const OHW_R8KPFETCH: u32 = 0x2;
/// R5000 end-of-page patch.
pub const OHW_R5KEOP: u32 = 0x4;
/// R5000 cvt.\[ds\].l bug.  clean=1.
pub const OHW_R5KCVTL: u32 = 0x8;

pub const OPAD_PREFIX: u32 = 0x1;
pub const OPAD_POSTFIX: u32 = 0x2;
pub const OPAD_SYMBOL: u32 = 0x4;

// Entries found in sections of type `SHT_MIPS_OPTIONS`.

// TODO: Elf_Options_Hw

// Masks for `ElfOptions::info` for `ODK_HWAND` and `ODK_HWOR` entries.

pub const OHWA0_R4KEOP_CHECKED: u32 = 0x0000_0001;
pub const OHWA1_R4KEOP_CLEAN: u32 = 0x0000_0002;

// Values for `DT_MIPS_FLAGS` `Dyn32` entry.

/// No flags
pub const RHF_NONE: u32 = 0;
/// Use quickstart
pub const RHF_QUICKSTART: u32 = 1 << 0;
/// Hash size not power of 2
pub const RHF_NOTPOT: u32 = 1 << 1;
/// Ignore LD_LIBRARY_PATH
pub const RHF_NO_LIBRARY_REPLACEMENT: u32 = 1 << 2;
pub const RHF_NO_MOVE: u32 = 1 << 3;
pub const RHF_SGI_ONLY: u32 = 1 << 4;
pub const RHF_GUARANTEE_INIT: u32 = 1 << 5;
pub const RHF_DELTA_C_PLUS_PLUS: u32 = 1 << 6;
pub const RHF_GUARANTEE_START_INIT: u32 = 1 << 7;
pub const RHF_PIXIE: u32 = 1 << 8;
pub const RHF_DEFAULT_DELAY_LOAD: u32 = 1 << 9;
pub const RHF_REQUICKSTART: u32 = 1 << 10;
pub const RHF_REQUICKSTARTED: u32 = 1 << 11;
pub const RHF_CORD: u32 = 1 << 12;
pub const RHF_NO_UNRES_UNDEF: u32 = 1 << 13;
pub const RHF_RLD_ORDER_SAFE: u32 = 1 << 14;

// Entries found in sections of type `SHT_MIPS_LIBLIST`.

// TODO: Elf32_Lib, Elf64_Lib

// Values for `Lib*::l_flags`.

pub const LL_NONE: u32 = 0;
/// Require exact match
pub const LL_EXACT_MATCH: u32 = 1 << 0;
/// Ignore interface version
pub const LL_IGNORE_INT_VER: u32 = 1 << 1;
pub const LL_REQUIRE_MINOR: u32 = 1 << 2;
pub const LL_EXPORTS: u32 = 1 << 3;
pub const LL_DELAY_LOAD: u32 = 1 << 4;
pub const LL_DELTA: u32 = 1 << 5;

// TODO: MIPS ABI flags

// PA-RISC specific definitions.

names! {
    struct Parisc(Base);
    flags ef: FileFlags(u32) = {
        /// Trap nil pointer dereference.
        EF_PARISC_TRAPNIL = 0x0001_0000,
        /// Program uses arch. extensions.
        EF_PARISC_EXT = 0x0002_0000,
        /// Program expects little endian.
        EF_PARISC_LSB = 0x0004_0000,
        /// Program expects wide mode.
        EF_PARISC_WIDE = 0x0008_0000,
        /// No kernel assisted branch prediction.
        EF_PARISC_NO_KABP = 0x0010_0000,
        /// Allow lazy swapping.
        EF_PARISC_LAZYSWAP = 0x0040_0000,
        /// Architecture version.
        EF_PARISC_ARCH = 0x0000_ffff => NAMES_EFA_PARISC,
    };
    consts shn: SymbolSection(u16) = {
        /// Section for tentatively declared symbols in ANSI C.
        SHN_PARISC_ANSI_COMMON = 0xff00,
        /// Common blocks in huge model.
        SHN_PARISC_HUGE_COMMON = 0xff01,
    };
    consts sht: SectionType(u32) = {
        /// Contains product specific ext.
        SHT_PARISC_EXT = 0x7000_0000,
        /// Unwind information.
        SHT_PARISC_UNWIND = 0x7000_0001,
        /// Debug info for optimized code.
        SHT_PARISC_DOC = 0x7000_0002,
    };
    flags shf: SectionFlags(u64) = {
        /// Section with short addressing.
        SHF_PARISC_SHORT = 0x2000_0000,
        /// Section far from gp.
        SHF_PARISC_HUGE = 0x4000_0000,
        /// Static branch prediction code.
        SHF_PARISC_SBP = 0x8000_0000,
    };
    consts stt: SymbolType(u8) = {
        /// Millicode function entry point.
        STT_PARISC_MILLICODE = 13,
        STT_HP_OPAQUE = STT_LOOS + 0x1,
        STT_HP_STUB = STT_LOOS + 0x2,
    };
    /// `Rel*::r_type` values for `EM_PARISC`.
    consts r = pub NAMES_R_PARISC: RelocationType(u32) = {
        /// No reloc.
        R_PARISC_NONE = 0,
        /// Direct 32-bit reference.
        R_PARISC_DIR32 = 1,
        /// Left 21 bits of eff. address.
        R_PARISC_DIR21L = 2,
        /// Right 17 bits of eff. address.
        R_PARISC_DIR17R = 3,
        /// 17 bits of eff. address.
        R_PARISC_DIR17F = 4,
        /// Right 14 bits of eff. address.
        R_PARISC_DIR14R = 6,
        /// 32-bit rel. address.
        R_PARISC_PCREL32 = 9,
        /// Left 21 bits of rel. address.
        R_PARISC_PCREL21L = 10,
        /// Right 17 bits of rel. address.
        R_PARISC_PCREL17R = 11,
        /// 17 bits of rel. address.
        R_PARISC_PCREL17F = 12,
        /// Right 14 bits of rel. address.
        R_PARISC_PCREL14R = 14,
        /// Left 21 bits of rel. address.
        R_PARISC_DPREL21L = 18,
        /// Right 14 bits of rel. address.
        R_PARISC_DPREL14R = 22,
        /// GP-relative, left 21 bits.
        R_PARISC_GPREL21L = 26,
        /// GP-relative, right 14 bits.
        R_PARISC_GPREL14R = 30,
        /// LT-relative, left 21 bits.
        R_PARISC_LTOFF21L = 34,
        /// LT-relative, right 14 bits.
        R_PARISC_LTOFF14R = 38,
        /// 32 bits section rel. address.
        R_PARISC_SECREL32 = 41,
        /// No relocation, set segment base.
        R_PARISC_SEGBASE = 48,
        /// 32 bits segment rel. address.
        R_PARISC_SEGREL32 = 49,
        /// PLT rel. address, left 21 bits.
        R_PARISC_PLTOFF21L = 50,
        /// PLT rel. address, right 14 bits.
        R_PARISC_PLTOFF14R = 54,
        /// 32 bits LT-rel. function pointer.
        R_PARISC_LTOFF_FPTR32 = 57,
        /// LT-rel. fct ptr, left 21 bits.
        R_PARISC_LTOFF_FPTR21L = 58,
        /// LT-rel. fct ptr, right 14 bits.
        R_PARISC_LTOFF_FPTR14R = 62,
        /// 64 bits function address.
        R_PARISC_FPTR64 = 64,
        /// 32 bits function address.
        R_PARISC_PLABEL32 = 65,
        /// Left 21 bits of fdesc address.
        R_PARISC_PLABEL21L = 66,
        /// Right 14 bits of fdesc address.
        R_PARISC_PLABEL14R = 70,
        /// 64 bits PC-rel. address.
        R_PARISC_PCREL64 = 72,
        /// 22 bits PC-rel. address.
        R_PARISC_PCREL22F = 74,
        /// PC-rel. address, right 14 bits.
        R_PARISC_PCREL14WR = 75,
        /// PC rel. address, right 14 bits.
        R_PARISC_PCREL14DR = 76,
        /// 16 bits PC-rel. address.
        R_PARISC_PCREL16F = 77,
        /// 16 bits PC-rel. address.
        R_PARISC_PCREL16WF = 78,
        /// 16 bits PC-rel. address.
        R_PARISC_PCREL16DF = 79,
        /// 64 bits of eff. address.
        R_PARISC_DIR64 = 80,
        /// 14 bits of eff. address.
        R_PARISC_DIR14WR = 83,
        /// 14 bits of eff. address.
        R_PARISC_DIR14DR = 84,
        /// 16 bits of eff. address.
        R_PARISC_DIR16F = 85,
        /// 16 bits of eff. address.
        R_PARISC_DIR16WF = 86,
        /// 16 bits of eff. address.
        R_PARISC_DIR16DF = 87,
        /// 64 bits of GP-rel. address.
        R_PARISC_GPREL64 = 88,
        /// GP-rel. address, right 14 bits.
        R_PARISC_GPREL14WR = 91,
        /// GP-rel. address, right 14 bits.
        R_PARISC_GPREL14DR = 92,
        /// 16 bits GP-rel. address.
        R_PARISC_GPREL16F = 93,
        /// 16 bits GP-rel. address.
        R_PARISC_GPREL16WF = 94,
        /// 16 bits GP-rel. address.
        R_PARISC_GPREL16DF = 95,
        /// 64 bits LT-rel. address.
        R_PARISC_LTOFF64 = 96,
        /// LT-rel. address, right 14 bits.
        R_PARISC_LTOFF14WR = 99,
        /// LT-rel. address, right 14 bits.
        R_PARISC_LTOFF14DR = 100,
        /// 16 bits LT-rel. address.
        R_PARISC_LTOFF16F = 101,
        /// 16 bits LT-rel. address.
        R_PARISC_LTOFF16WF = 102,
        /// 16 bits LT-rel. address.
        R_PARISC_LTOFF16DF = 103,
        /// 64 bits section rel. address.
        R_PARISC_SECREL64 = 104,
        /// 64 bits segment rel. address.
        R_PARISC_SEGREL64 = 112,
        /// PLT-rel. address, right 14 bits.
        R_PARISC_PLTOFF14WR = 115,
        /// PLT-rel. address, right 14 bits.
        R_PARISC_PLTOFF14DR = 116,
        /// 16 bits LT-rel. address.
        R_PARISC_PLTOFF16F = 117,
        /// 16 bits PLT-rel. address.
        R_PARISC_PLTOFF16WF = 118,
        /// 16 bits PLT-rel. address.
        R_PARISC_PLTOFF16DF = 119,
        /// 64 bits LT-rel. function ptr.
        R_PARISC_LTOFF_FPTR64 = 120,
        /// LT-rel. fct. ptr., right 14 bits.
        R_PARISC_LTOFF_FPTR14WR = 123,
        /// LT-rel. fct. ptr., right 14 bits.
        R_PARISC_LTOFF_FPTR14DR = 124,
        /// 16 bits LT-rel. function ptr.
        R_PARISC_LTOFF_FPTR16F = 125,
        /// 16 bits LT-rel. function ptr.
        R_PARISC_LTOFF_FPTR16WF = 126,
        /// 16 bits LT-rel. function ptr.
        R_PARISC_LTOFF_FPTR16DF = 127,
        R_PARISC_LORESERVE = 128,
        /// Copy relocation.
        R_PARISC_COPY = 128,
        /// Dynamic reloc, imported PLT
        R_PARISC_IPLT = 129,
        /// Dynamic reloc, exported PLT
        R_PARISC_EPLT = 130,
        /// 32 bits TP-rel. address.
        R_PARISC_TPREL32 = 153,
        /// TP-rel. address, left 21 bits.
        R_PARISC_TPREL21L = 154,
        /// TP-rel. address, right 14 bits.
        R_PARISC_TPREL14R = 158,
        /// LT-TP-rel. address, left 21 bits.
        R_PARISC_LTOFF_TP21L = 162,
        /// LT-TP-rel. address, right 14 bits.
        R_PARISC_LTOFF_TP14R = 166,
        /// 14 bits LT-TP-rel. address.
        R_PARISC_LTOFF_TP14F = 167,
        /// 64 bits TP-rel. address.
        R_PARISC_TPREL64 = 216,
        /// TP-rel. address, right 14 bits.
        R_PARISC_TPREL14WR = 219,
        /// TP-rel. address, right 14 bits.
        R_PARISC_TPREL14DR = 220,
        /// 16 bits TP-rel. address.
        R_PARISC_TPREL16F = 221,
        /// 16 bits TP-rel. address.
        R_PARISC_TPREL16WF = 222,
        /// 16 bits TP-rel. address.
        R_PARISC_TPREL16DF = 223,
        /// 64 bits LT-TP-rel. address.
        R_PARISC_LTOFF_TP64 = 224,
        /// LT-TP-rel. address, right 14 bits.
        R_PARISC_LTOFF_TP14WR = 227,
        /// LT-TP-rel. address, right 14 bits.
        R_PARISC_LTOFF_TP14DR = 228,
        /// 16 bits LT-TP-rel. address.
        R_PARISC_LTOFF_TP16F = 229,
        /// 16 bits LT-TP-rel. address.
        R_PARISC_LTOFF_TP16WF = 230,
        /// 16 bits LT-TP-rel. address.
        R_PARISC_LTOFF_TP16DF = 231,
        R_PARISC_GNU_VTENTRY = 232,
        R_PARISC_GNU_VTINHERIT = 233,
        /// GD 21-bit left.
        R_PARISC_TLS_GD21L = 234,
        /// GD 14-bit right.
        R_PARISC_TLS_GD14R = 235,
        /// GD call to __t_g_a.
        R_PARISC_TLS_GDCALL = 236,
        /// LD module 21-bit left.
        R_PARISC_TLS_LDM21L = 237,
        /// LD module 14-bit right.
        R_PARISC_TLS_LDM14R = 238,
        /// LD module call to __t_g_a.
        R_PARISC_TLS_LDMCALL = 239,
        /// LD offset 21-bit left.
        R_PARISC_TLS_LDO21L = 240,
        /// LD offset 14-bit right.
        R_PARISC_TLS_LDO14R = 241,
        /// DTP module 32-bit.
        R_PARISC_TLS_DTPMOD32 = 242,
        /// DTP module 64-bit.
        R_PARISC_TLS_DTPMOD64 = 243,
        /// DTP offset 32-bit.
        R_PARISC_TLS_DTPOFF32 = 244,
        /// DTP offset 32-bit.
        R_PARISC_TLS_DTPOFF64 = 245,
        R_PARISC_TLS_LE21L = R_PARISC_TPREL21L.0,
        R_PARISC_TLS_LE14R = R_PARISC_TPREL14R.0,
        R_PARISC_TLS_IE21L = R_PARISC_LTOFF_TP21L.0,
        R_PARISC_TLS_IE14R = R_PARISC_LTOFF_TP14R.0,
        R_PARISC_TLS_TPREL32 = R_PARISC_TPREL32.0,
        R_PARISC_TLS_TPREL64 = R_PARISC_TPREL64.0,
        R_PARISC_HIRESERVE = 255,
    };
    consts pt: ProgramType(u32) = {
        PT_HP_TLS = PT_LOOS + 0x0,
        PT_HP_CORE_NONE = PT_LOOS + 0x1,
        PT_HP_CORE_VERSION = PT_LOOS + 0x2,
        PT_HP_CORE_KERNEL = PT_LOOS + 0x3,
        PT_HP_CORE_COMM = PT_LOOS + 0x4,
        PT_HP_CORE_PROC = PT_LOOS + 0x5,
        PT_HP_CORE_LOADABLE = PT_LOOS + 0x6,
        PT_HP_CORE_STACK = PT_LOOS + 0x7,
        PT_HP_CORE_SHM = PT_LOOS + 0x8,
        PT_HP_CORE_MMF = PT_LOOS + 0x9,
        PT_HP_PARALLEL = PT_LOOS + 0x10,
        PT_HP_FASTBIND = PT_LOOS + 0x11,
        PT_HP_OPT_ANNOT = PT_LOOS + 0x12,
        PT_HP_HSL_ANNOT = PT_LOOS + 0x13,
        PT_HP_STACK = PT_LOOS + 0x14,

        PT_PARISC_ARCHEXT = 0x7000_0000,
        PT_PARISC_UNWIND = 0x7000_0001,
    };
    flags pf: ProgramFlags(u32) = {
        PF_PARISC_SBP = 0x0800_0000,

        PF_HP_PAGE_SIZE = 0x0010_0000,
        PF_HP_FAR_SHARED = 0x0020_0000,
        PF_HP_NEAR_SHARED = 0x0040_0000,
        PF_HP_CODE = 0x0100_0000,
        PF_HP_MODIFY = 0x0200_0000,
        PF_HP_LAZYSWAP = 0x0400_0000,
        PF_HP_SBP = 0x0800_0000,
    };
}

constant_names!(NAMES_EFA_PARISC: FileFlags(u32) = {
    /// PA-RISC 1.0 big-endian.
    EFA_PARISC_1_0 = 0x020b,
    /// PA-RISC 1.1 big-endian.
    EFA_PARISC_1_1 = 0x0210,
    /// PA-RISC 2.0 big-endian.
    EFA_PARISC_2_0 = 0x0214,
});

// Alpha specific definitions.

names! {
    struct Alpha(Base);
    flags ef: FileFlags(u32) = {
        /// All addresses must be < 2GB.
        EF_ALPHA_32BIT = 1,
        /// Relocations for relaxing exist.
        EF_ALPHA_CANRELAX = 2,
    };
    consts sht: SectionType(u32) = {
        // These two are primarily concerned with ECOFF debugging info.
        SHT_ALPHA_DEBUG = 0x7000_0001,
        SHT_ALPHA_REGINFO = 0x7000_0002,
    };
    flags shf: SectionFlags(u64) = {
        SHF_ALPHA_GPREL = 0x1000_0000,
    };
    flags sto: SymbolOther(u8) = {
        /// No PV required.
        STO_ALPHA_NOPV = 0x80,
        /// PV only used for initial ldgp.
        STO_ALPHA_STD_GPLOAD = 0x88,
    };
    /// `Rel*::r_type` values for `EM_ALPHA`.
    consts r = pub NAMES_R_ALPHA: RelocationType(u32) = {
        /// No reloc
        R_ALPHA_NONE = 0,
        /// Direct 32 bit
        R_ALPHA_REFLONG = 1,
        /// Direct 64 bit
        R_ALPHA_REFQUAD = 2,
        /// GP relative 32 bit
        R_ALPHA_GPREL32 = 3,
        /// GP relative 16 bit w/optimization
        R_ALPHA_LITERAL = 4,
        /// Optimization hint for LITERAL
        R_ALPHA_LITUSE = 5,
        /// Add displacement to GP
        R_ALPHA_GPDISP = 6,
        /// PC+4 relative 23 bit shifted
        R_ALPHA_BRADDR = 7,
        /// PC+4 relative 16 bit shifted
        R_ALPHA_HINT = 8,
        /// PC relative 16 bit
        R_ALPHA_SREL16 = 9,
        /// PC relative 32 bit
        R_ALPHA_SREL32 = 10,
        /// PC relative 64 bit
        R_ALPHA_SREL64 = 11,
        /// GP relative 32 bit, high 16 bits
        R_ALPHA_GPRELHIGH = 17,
        /// GP relative 32 bit, low 16 bits
        R_ALPHA_GPRELLOW = 18,
        /// GP relative 16 bit
        R_ALPHA_GPREL16 = 19,
        /// Copy symbol at runtime
        R_ALPHA_COPY = 24,
        /// Create GOT entry
        R_ALPHA_GLOB_DAT = 25,
        /// Create PLT entry
        R_ALPHA_JMP_SLOT = 26,
        /// Adjust by program base
        R_ALPHA_RELATIVE = 27,
        R_ALPHA_TLS_GD_HI = 28,
        R_ALPHA_TLSGD = 29,
        R_ALPHA_TLS_LDM = 30,
        R_ALPHA_DTPMOD64 = 31,
        R_ALPHA_GOTDTPREL = 32,
        R_ALPHA_DTPREL64 = 33,
        R_ALPHA_DTPRELHI = 34,
        R_ALPHA_DTPRELLO = 35,
        R_ALPHA_DTPREL16 = 36,
        R_ALPHA_GOTTPREL = 37,
        R_ALPHA_TPREL64 = 38,
        R_ALPHA_TPRELHI = 39,
        R_ALPHA_TPRELLO = 40,
        R_ALPHA_TPREL16 = 41,
    };
    consts dt: DynamicTag(i64) = {
        DT_ALPHA_PLTRO = DT_LOPROC + 0,
    };
}

// Magic values of the `R_ALPHA_LITUSE` relocation addend.
pub const LITUSE_ALPHA_ADDR: u32 = 0;
pub const LITUSE_ALPHA_BASE: u32 = 1;
pub const LITUSE_ALPHA_BYTOFF: u32 = 2;
pub const LITUSE_ALPHA_JSR: u32 = 3;
pub const LITUSE_ALPHA_TLS_GD: u32 = 4;
pub const LITUSE_ALPHA_TLS_LDM: u32 = 5;

// PowerPC specific declarations.

names! {
    struct Ppc(Base);
    flags ef: FileFlags(u32) = {
        /// PowerPC embedded flag
        EF_PPC_EMB = 0x8000_0000,

        // Cygnus local bits below .
        /// PowerPC -mrelocatable flag
        EF_PPC_RELOCATABLE = 0x0001_0000,
        /// PowerPC -mrelocatable-lib flag
        EF_PPC_RELOCATABLE_LIB = 0x0000_8000,
    };
    /// `Rel*::r_type` values for `EM_PPC`.
    consts r = pub NAMES_R_PPC: RelocationType(u32) = {
        // PowerPC values for `Rel*::r_type` defined by the ABIs.
        R_PPC_NONE = 0,
        /// 32bit absolute address
        R_PPC_ADDR32 = 1,
        /// 26bit address, 2 bits ignored.
        R_PPC_ADDR24 = 2,
        /// 16bit absolute address
        R_PPC_ADDR16 = 3,
        /// lower 16bit of absolute address
        R_PPC_ADDR16_LO = 4,
        /// high 16bit of absolute address
        R_PPC_ADDR16_HI = 5,
        /// adjusted high 16bit
        R_PPC_ADDR16_HA = 6,
        /// 16bit address, 2 bits ignored
        R_PPC_ADDR14 = 7,
        R_PPC_ADDR14_BRTAKEN = 8,
        R_PPC_ADDR14_BRNTAKEN = 9,
        /// PC relative 26 bit
        R_PPC_REL24 = 10,
        /// PC relative 16 bit
        R_PPC_REL14 = 11,
        R_PPC_REL14_BRTAKEN = 12,
        R_PPC_REL14_BRNTAKEN = 13,
        R_PPC_GOT16 = 14,
        R_PPC_GOT16_LO = 15,
        R_PPC_GOT16_HI = 16,
        R_PPC_GOT16_HA = 17,
        R_PPC_PLTREL24 = 18,
        R_PPC_COPY = 19,
        R_PPC_GLOB_DAT = 20,
        R_PPC_JMP_SLOT = 21,
        R_PPC_RELATIVE = 22,
        R_PPC_LOCAL24PC = 23,
        R_PPC_UADDR32 = 24,
        R_PPC_UADDR16 = 25,
        R_PPC_REL32 = 26,
        R_PPC_PLT32 = 27,
        R_PPC_PLTREL32 = 28,
        R_PPC_PLT16_LO = 29,
        R_PPC_PLT16_HI = 30,
        R_PPC_PLT16_HA = 31,
        R_PPC_SDAREL16 = 32,
        R_PPC_SECTOFF = 33,
        R_PPC_SECTOFF_LO = 34,
        R_PPC_SECTOFF_HI = 35,
        R_PPC_SECTOFF_HA = 36,

        // PowerPC values for `Rel*::r_type` defined for the TLS access ABI.
        /// none    (sym+add)@tls
        R_PPC_TLS = 67,
        /// word32  (sym+add)@dtpmod
        R_PPC_DTPMOD32 = 68,
        /// half16* (sym+add)@tprel
        R_PPC_TPREL16 = 69,
        /// half16  (sym+add)@tprel@l
        R_PPC_TPREL16_LO = 70,
        /// half16  (sym+add)@tprel@h
        R_PPC_TPREL16_HI = 71,
        /// half16  (sym+add)@tprel@ha
        R_PPC_TPREL16_HA = 72,
        /// word32  (sym+add)@tprel
        R_PPC_TPREL32 = 73,
        /// half16*(sym+add)@dtprel
        R_PPC_DTPREL16 = 74,
        /// half16  (sym+add)@dtprel@l
        R_PPC_DTPREL16_LO = 75,
        /// half16  (sym+add)@dtprel@h
        R_PPC_DTPREL16_HI = 76,
        /// half16  (sym+add)@dtprel@ha
        R_PPC_DTPREL16_HA = 77,
        /// word32  (sym+add)@dtprel
        R_PPC_DTPREL32 = 78,
        /// half16* (sym+add)@got@tlsgd
        R_PPC_GOT_TLSGD16 = 79,
        /// half16  (sym+add)@got@tlsgd@l
        R_PPC_GOT_TLSGD16_LO = 80,
        /// half16  (sym+add)@got@tlsgd@h
        R_PPC_GOT_TLSGD16_HI = 81,
        /// half16  (sym+add)@got@tlsgd@ha
        R_PPC_GOT_TLSGD16_HA = 82,
        /// half16* (sym+add)@got@tlsld
        R_PPC_GOT_TLSLD16 = 83,
        /// half16  (sym+add)@got@tlsld@l
        R_PPC_GOT_TLSLD16_LO = 84,
        /// half16  (sym+add)@got@tlsld@h
        R_PPC_GOT_TLSLD16_HI = 85,
        /// half16  (sym+add)@got@tlsld@ha
        R_PPC_GOT_TLSLD16_HA = 86,
        /// half16* (sym+add)@got@tprel
        R_PPC_GOT_TPREL16 = 87,
        /// half16  (sym+add)@got@tprel@l
        R_PPC_GOT_TPREL16_LO = 88,
        /// half16  (sym+add)@got@tprel@h
        R_PPC_GOT_TPREL16_HI = 89,
        /// half16  (sym+add)@got@tprel@ha
        R_PPC_GOT_TPREL16_HA = 90,
        /// half16* (sym+add)@got@dtprel
        R_PPC_GOT_DTPREL16 = 91,
        /// half16* (sym+add)@got@dtprel@l
        R_PPC_GOT_DTPREL16_LO = 92,
        /// half16* (sym+add)@got@dtprel@h
        R_PPC_GOT_DTPREL16_HI = 93,
        /// half16* (sym+add)@got@dtprel@ha
        R_PPC_GOT_DTPREL16_HA = 94,
        /// none    (sym+add)@tlsgd
        R_PPC_TLSGD = 95,
        /// none    (sym+add)@tlsld
        R_PPC_TLSLD = 96,

        // PowerPC values for `Rel*::r_type` from the Embedded ELF ABI.
        R_PPC_EMB_NADDR32 = 101,
        R_PPC_EMB_NADDR16 = 102,
        R_PPC_EMB_NADDR16_LO = 103,
        R_PPC_EMB_NADDR16_HI = 104,
        R_PPC_EMB_NADDR16_HA = 105,
        R_PPC_EMB_SDAI16 = 106,
        R_PPC_EMB_SDA2I16 = 107,
        R_PPC_EMB_SDA2REL = 108,
        /// 16 bit offset in SDA
        R_PPC_EMB_SDA21 = 109,
        R_PPC_EMB_MRKREF = 110,
        R_PPC_EMB_RELSEC16 = 111,
        R_PPC_EMB_RELST_LO = 112,
        R_PPC_EMB_RELST_HI = 113,
        R_PPC_EMB_RELST_HA = 114,
        R_PPC_EMB_BIT_FLD = 115,
        /// 16 bit relative offset in SDA
        R_PPC_EMB_RELSDA = 116,

        // Diab tool values for `Rel*::r_type`.
        /// like EMB_SDA21, but lower 16 bit
        R_PPC_DIAB_SDA21_LO = 180,
        /// like EMB_SDA21, but high 16 bit
        R_PPC_DIAB_SDA21_HI = 181,
        /// like EMB_SDA21, adjusted high 16
        R_PPC_DIAB_SDA21_HA = 182,
        /// like EMB_RELSDA, but lower 16 bit
        R_PPC_DIAB_RELSDA_LO = 183,
        /// like EMB_RELSDA, but high 16 bit
        R_PPC_DIAB_RELSDA_HI = 184,
        /// like EMB_RELSDA, adjusted high 16
        R_PPC_DIAB_RELSDA_HA = 185,

        /// GNU extension to support local ifunc.
        R_PPC_IRELATIVE = 248,

        // GNU relocs used in PIC code sequences.
        /// half16   (sym+add-.)
        R_PPC_REL16 = 249,
        /// half16   (sym+add-.)@l
        R_PPC_REL16_LO = 250,
        /// half16   (sym+add-.)@h
        R_PPC_REL16_HI = 251,
        /// half16   (sym+add-.)@ha
        R_PPC_REL16_HA = 252,

        /// This is a phony reloc to handle any old fashioned TOC16 references that may
        /// still be in object files.
        R_PPC_TOC16 = 255,
    };
    consts dt: DynamicTag(i64) = {
        DT_PPC_GOT = DT_LOPROC + 0,
        DT_PPC_OPT = DT_LOPROC + 1,
    };
}

// PowerPC specific values for the `DT_PPC_OPT` entry.
pub const PPC_OPT_TLS: u32 = 1;

names! {
    struct Ppc64(Base);
    /// `Rel*::r_type` values for `EM_PPC64`.
    consts r = pub NAMES_R_PPC64: RelocationType(u32) = {
        // PowerPC64 values for `Rel*::r_type` defined by the ABIs.
        R_PPC64_NONE = R_PPC_NONE.0,
        /// 32bit absolute address
        R_PPC64_ADDR32 = R_PPC_ADDR32.0,
        /// 26bit address, word aligned
        R_PPC64_ADDR24 = R_PPC_ADDR24.0,
        /// 16bit absolute address
        R_PPC64_ADDR16 = R_PPC_ADDR16.0,
        /// lower 16bits of address
        R_PPC64_ADDR16_LO = R_PPC_ADDR16_LO.0,
        /// high 16bits of address.
        R_PPC64_ADDR16_HI = R_PPC_ADDR16_HI.0,
        /// adjusted high 16bits.
        R_PPC64_ADDR16_HA = R_PPC_ADDR16_HA.0,
        /// 16bit address, word aligned
        R_PPC64_ADDR14 = R_PPC_ADDR14.0,
        R_PPC64_ADDR14_BRTAKEN = R_PPC_ADDR14_BRTAKEN.0,
        R_PPC64_ADDR14_BRNTAKEN = R_PPC_ADDR14_BRNTAKEN.0,
        /// PC-rel. 26 bit, word aligned
        R_PPC64_REL24 = R_PPC_REL24.0,
        /// PC relative 16 bit
        R_PPC64_REL14 = R_PPC_REL14.0,
        R_PPC64_REL14_BRTAKEN = R_PPC_REL14_BRTAKEN.0,
        R_PPC64_REL14_BRNTAKEN = R_PPC_REL14_BRNTAKEN.0,
        R_PPC64_GOT16 = R_PPC_GOT16.0,
        R_PPC64_GOT16_LO = R_PPC_GOT16_LO.0,
        R_PPC64_GOT16_HI = R_PPC_GOT16_HI.0,
        R_PPC64_GOT16_HA = R_PPC_GOT16_HA.0,

        R_PPC64_COPY = R_PPC_COPY.0,
        R_PPC64_GLOB_DAT = R_PPC_GLOB_DAT.0,
        R_PPC64_JMP_SLOT = R_PPC_JMP_SLOT.0,
        R_PPC64_RELATIVE = R_PPC_RELATIVE.0,

        R_PPC64_UADDR32 = R_PPC_UADDR32.0,
        R_PPC64_UADDR16 = R_PPC_UADDR16.0,
        R_PPC64_REL32 = R_PPC_REL32.0,
        R_PPC64_PLT32 = R_PPC_PLT32.0,
        R_PPC64_PLTREL32 = R_PPC_PLTREL32.0,
        R_PPC64_PLT16_LO = R_PPC_PLT16_LO.0,
        R_PPC64_PLT16_HI = R_PPC_PLT16_HI.0,
        R_PPC64_PLT16_HA = R_PPC_PLT16_HA.0,

        R_PPC64_SECTOFF = R_PPC_SECTOFF.0,
        R_PPC64_SECTOFF_LO = R_PPC_SECTOFF_LO.0,
        R_PPC64_SECTOFF_HI = R_PPC_SECTOFF_HI.0,
        R_PPC64_SECTOFF_HA = R_PPC_SECTOFF_HA.0,
        /// word30 (S + A - P) >> 2
        R_PPC64_ADDR30 = 37,
        /// doubleword64 S + A
        R_PPC64_ADDR64 = 38,
        /// half16 #higher(S + A)
        R_PPC64_ADDR16_HIGHER = 39,
        /// half16 #highera(S + A)
        R_PPC64_ADDR16_HIGHERA = 40,
        /// half16 #highest(S + A)
        R_PPC64_ADDR16_HIGHEST = 41,
        /// half16 #highesta(S + A)
        R_PPC64_ADDR16_HIGHESTA = 42,
        /// doubleword64 S + A
        R_PPC64_UADDR64 = 43,
        /// doubleword64 S + A - P
        R_PPC64_REL64 = 44,
        /// doubleword64 L + A
        R_PPC64_PLT64 = 45,
        /// doubleword64 L + A - P
        R_PPC64_PLTREL64 = 46,
        /// half16* S + A - .TOC
        R_PPC64_TOC16 = 47,
        /// half16 #lo(S + A - .TOC.)
        R_PPC64_TOC16_LO = 48,
        /// half16 #hi(S + A - .TOC.)
        R_PPC64_TOC16_HI = 49,
        /// half16 #ha(S + A - .TOC.)
        R_PPC64_TOC16_HA = 50,
        /// doubleword64 .TOC
        R_PPC64_TOC = 51,
        /// half16* M + A
        R_PPC64_PLTGOT16 = 52,
        /// half16 #lo(M + A)
        R_PPC64_PLTGOT16_LO = 53,
        /// half16 #hi(M + A)
        R_PPC64_PLTGOT16_HI = 54,
        /// half16 #ha(M + A)
        R_PPC64_PLTGOT16_HA = 55,

        /// half16ds* (S + A) >> 2
        R_PPC64_ADDR16_DS = 56,
        /// half16ds  #lo(S + A) >> 2
        R_PPC64_ADDR16_LO_DS = 57,
        /// half16ds* (G + A) >> 2
        R_PPC64_GOT16_DS = 58,
        /// half16ds  #lo(G + A) >> 2
        R_PPC64_GOT16_LO_DS = 59,
        /// half16ds  #lo(L + A) >> 2
        R_PPC64_PLT16_LO_DS = 60,
        /// half16ds* (R + A) >> 2
        R_PPC64_SECTOFF_DS = 61,
        /// half16ds  #lo(R + A) >> 2
        R_PPC64_SECTOFF_LO_DS = 62,
        /// half16ds* (S + A - .TOC.) >> 2
        R_PPC64_TOC16_DS = 63,
        /// half16ds  #lo(S + A - .TOC.) >> 2
        R_PPC64_TOC16_LO_DS = 64,
        /// half16ds* (M + A) >> 2
        R_PPC64_PLTGOT16_DS = 65,
        /// half16ds  #lo(M + A) >> 2
        R_PPC64_PLTGOT16_LO_DS = 66,

        // PowerPC64 values for `Rel*::r_type` defined for the TLS access ABI.
        /// none    (sym+add)@tls
        R_PPC64_TLS = 67,
        /// doubleword64 (sym+add)@dtpmod
        R_PPC64_DTPMOD64 = 68,
        /// half16* (sym+add)@tprel
        R_PPC64_TPREL16 = 69,
        /// half16  (sym+add)@tprel@l
        R_PPC64_TPREL16_LO = 70,
        /// half16  (sym+add)@tprel@h
        R_PPC64_TPREL16_HI = 71,
        /// half16  (sym+add)@tprel@ha
        R_PPC64_TPREL16_HA = 72,
        /// doubleword64 (sym+add)@tprel
        R_PPC64_TPREL64 = 73,
        /// half16* (sym+add)@dtprel
        R_PPC64_DTPREL16 = 74,
        /// half16  (sym+add)@dtprel@l
        R_PPC64_DTPREL16_LO = 75,
        /// half16  (sym+add)@dtprel@h
        R_PPC64_DTPREL16_HI = 76,
        /// half16  (sym+add)@dtprel@ha
        R_PPC64_DTPREL16_HA = 77,
        /// doubleword64 (sym+add)@dtprel
        R_PPC64_DTPREL64 = 78,
        /// half16* (sym+add)@got@tlsgd
        R_PPC64_GOT_TLSGD16 = 79,
        /// half16  (sym+add)@got@tlsgd@l
        R_PPC64_GOT_TLSGD16_LO = 80,
        /// half16  (sym+add)@got@tlsgd@h
        R_PPC64_GOT_TLSGD16_HI = 81,
        /// half16  (sym+add)@got@tlsgd@ha
        R_PPC64_GOT_TLSGD16_HA = 82,
        /// half16* (sym+add)@got@tlsld
        R_PPC64_GOT_TLSLD16 = 83,
        /// half16  (sym+add)@got@tlsld@l
        R_PPC64_GOT_TLSLD16_LO = 84,
        /// half16  (sym+add)@got@tlsld@h
        R_PPC64_GOT_TLSLD16_HI = 85,
        /// half16  (sym+add)@got@tlsld@ha
        R_PPC64_GOT_TLSLD16_HA = 86,
        /// half16ds* (sym+add)@got@tprel
        R_PPC64_GOT_TPREL16_DS = 87,
        /// half16ds (sym+add)@got@tprel@l
        R_PPC64_GOT_TPREL16_LO_DS = 88,
        /// half16  (sym+add)@got@tprel@h
        R_PPC64_GOT_TPREL16_HI = 89,
        /// half16  (sym+add)@got@tprel@ha
        R_PPC64_GOT_TPREL16_HA = 90,
        /// half16ds* (sym+add)@got@dtprel
        R_PPC64_GOT_DTPREL16_DS = 91,
        /// half16ds (sym+add)@got@dtprel@l
        R_PPC64_GOT_DTPREL16_LO_DS = 92,
        /// half16  (sym+add)@got@dtprel@h
        R_PPC64_GOT_DTPREL16_HI = 93,
        /// half16  (sym+add)@got@dtprel@ha
        R_PPC64_GOT_DTPREL16_HA = 94,
        /// half16ds* (sym+add)@tprel
        R_PPC64_TPREL16_DS = 95,
        /// half16ds (sym+add)@tprel@l
        R_PPC64_TPREL16_LO_DS = 96,
        /// half16  (sym+add)@tprel@higher
        R_PPC64_TPREL16_HIGHER = 97,
        /// half16  (sym+add)@tprel@highera
        R_PPC64_TPREL16_HIGHERA = 98,
        /// half16  (sym+add)@tprel@highest
        R_PPC64_TPREL16_HIGHEST = 99,
        /// half16  (sym+add)@tprel@highesta
        R_PPC64_TPREL16_HIGHESTA = 100,
        /// half16ds* (sym+add)@dtprel
        R_PPC64_DTPREL16_DS = 101,
        /// half16ds (sym+add)@dtprel@l
        R_PPC64_DTPREL16_LO_DS = 102,
        /// half16  (sym+add)@dtprel@higher
        R_PPC64_DTPREL16_HIGHER = 103,
        /// half16  (sym+add)@dtprel@highera
        R_PPC64_DTPREL16_HIGHERA = 104,
        /// half16  (sym+add)@dtprel@highest
        R_PPC64_DTPREL16_HIGHEST = 105,
        /// half16  (sym+add)@dtprel@highesta
        R_PPC64_DTPREL16_HIGHESTA = 106,
        /// none    (sym+add)@tlsgd
        R_PPC64_TLSGD = 107,
        /// none    (sym+add)@tlsld
        R_PPC64_TLSLD = 108,
        /// none
        R_PPC64_TOCSAVE = 109,

        // Added when HA and HI relocs were changed to report overflows.
        R_PPC64_ADDR16_HIGH = 110,
        R_PPC64_ADDR16_HIGHA = 111,
        R_PPC64_TPREL16_HIGH = 112,
        R_PPC64_TPREL16_HIGHA = 113,
        R_PPC64_DTPREL16_HIGH = 114,
        R_PPC64_DTPREL16_HIGHA = 115,

        /// GNU extension to support local ifunc.
        R_PPC64_JMP_IREL = 247,
        /// GNU extension to support local ifunc.
        R_PPC64_IRELATIVE = 248,
        /// half16   (sym+add-.)
        R_PPC64_REL16 = 249,
        /// half16   (sym+add-.)@l
        R_PPC64_REL16_LO = 250,
        /// half16   (sym+add-.)@h
        R_PPC64_REL16_HI = 251,
        /// half16   (sym+add-.)@ha
        R_PPC64_REL16_HA = 252,
    };
    consts dt: DynamicTag(i64) = {
        DT_PPC64_GLINK = DT_LOPROC + 0,
        DT_PPC64_OPD = DT_LOPROC + 1,
        DT_PPC64_OPDSZ = DT_LOPROC + 2,
        DT_PPC64_OPT = DT_LOPROC + 3,
    };
}

/// PowerPC64 bits specifying ABI.
///
/// 1 for original function descriptor using ABI,
/// 2 for revised ABI without function descriptors,
/// 0 for unspecified or not using any features affected by the differences.
pub const EF_PPC64_ABI: u32 = 3;

// PowerPC64 bits for `DT_PPC64_OPT` entry.
pub const PPC64_OPT_TLS: u32 = 1;
pub const PPC64_OPT_MULTI_TOC: u32 = 2;
pub const PPC64_OPT_LOCALENTRY: u32 = 4;

// PowerPC64 values for `Sym64::st_other.
pub const STO_PPC64_LOCAL_BIT: u8 = 5;
pub const STO_PPC64_LOCAL_MASK: u8 = 7 << STO_PPC64_LOCAL_BIT;

// ARM specific declarations.

names! {
    struct Arm(Base);
    flags ef: FileFlags(u32) = {
        EF_ARM_RELEXEC = 0x01,
        EF_ARM_HASENTRY = 0x02,
        EF_ARM_INTERWORK = 0x04,
        EF_ARM_APCS_26 = 0x08,
        EF_ARM_APCS_FLOAT = 0x10,
        EF_ARM_PIC = 0x20,
        /// 8-bit structure alignment is in use
        EF_ARM_ALIGN8 = 0x40,
        EF_ARM_NEW_ABI = 0x80,
        EF_ARM_OLD_ABI = 0x100,
        EF_ARM_SOFT_FLOAT = 0x200,
        EF_ARM_VFP_FLOAT = 0x400,
        EF_ARM_MAVERICK_FLOAT = 0x800,

        // Constants defined in AAELF.
        EF_ARM_BE8 = 0x0080_0000,
        EF_ARM_LE8 = 0x0040_0000,

        EF_ARM_EABIMASK = 0xff00_0000 => NAMES_EF_ARM_EABI,
    };
    consts stt: SymbolType(u8) = {
        /// A Thumb function.
        STT_ARM_TFUNC = STT_LOPROC,
        /// A Thumb label.
        STT_ARM_16BIT = STT_HIPROC,
    };
    flags shf: SectionFlags(u64) = {
        /// Section contains an entry point
        SHF_ARM_ENTRYSECT = 0x1000_0000,
        /// Section may be multiply defined in the input to a link step.
        SHF_ARM_COMDEF = 0x8000_0000,
    };
    flags pf: ProgramFlags(u32) = {
        /// Segment contains the location addressed by the static base.
        PF_ARM_SB = 0x1000_0000,
        /// Position-independent segment.
        PF_ARM_PI = 0x2000_0000,
        /// Absolute segment.
        PF_ARM_ABS = 0x4000_0000,
    };
    consts pt: ProgramType(u32) = {
        /// ARM unwind segment.
        PT_ARM_EXIDX = PT_LOPROC + 1,
    };
    consts sht: SectionType(u32) = {
        /// ARM unwind section.
        SHT_ARM_EXIDX = SHT_LOPROC + 1,
        /// Preemption details.
        SHT_ARM_PREEMPTMAP = SHT_LOPROC + 2,
        /// ARM attributes section.
        SHT_ARM_ATTRIBUTES = SHT_LOPROC + 3,
    };
    /// `Rel*::r_type` values for `EM_ARM`.
    consts r = pub NAMES_R_ARM: RelocationType(u32) = {
        /// No reloc
        R_ARM_NONE = 0,
        /// Deprecated PC relative 26 bit branch.
        R_ARM_PC24 = 1,
        /// Direct 32 bit
        R_ARM_ABS32 = 2,
        /// PC relative 32 bit
        R_ARM_REL32 = 3,
        R_ARM_PC13 = 4,
        /// Direct 16 bit
        R_ARM_ABS16 = 5,
        /// Direct 12 bit
        R_ARM_ABS12 = 6,
        /// Direct & 0x7C (`LDR`, `STR`).
        R_ARM_THM_ABS5 = 7,
        /// Direct 8 bit
        R_ARM_ABS8 = 8,
        R_ARM_SBREL32 = 9,
        /// PC relative 24 bit (Thumb32 `BL`).
        R_ARM_THM_PC22 = 10,
        /// PC relative & 0x3FC (Thumb16 `LDR`, `ADD`, `ADR`).
        R_ARM_THM_PC8 = 11,
        R_ARM_AMP_VCALL9 = 12,
        /// Obsolete static relocation.
        R_ARM_SWI24 = 13,
        /// Dynamic relocation.
        R_ARM_TLS_DESC = 13,
        /// Reserved.
        R_ARM_THM_SWI8 = 14,
        /// Reserved.
        R_ARM_XPC25 = 15,
        /// Reserved.
        R_ARM_THM_XPC22 = 16,
        /// ID of module containing symbol
        R_ARM_TLS_DTPMOD32 = 17,
        /// Offset in TLS block
        R_ARM_TLS_DTPOFF32 = 18,
        /// Offset in static TLS block
        R_ARM_TLS_TPOFF32 = 19,
        /// Copy symbol at runtime
        R_ARM_COPY = 20,
        /// Create GOT entry
        R_ARM_GLOB_DAT = 21,
        /// Create PLT entry
        R_ARM_JUMP_SLOT = 22,
        /// Adjust by program base
        R_ARM_RELATIVE = 23,
        /// 32 bit offset to GOT
        R_ARM_GOTOFF = 24,
        /// 32 bit PC relative offset to GOT
        R_ARM_GOTPC = 25,
        /// 32 bit GOT entry
        R_ARM_GOT32 = 26,
        /// Deprecated, 32 bit PLT address.
        R_ARM_PLT32 = 27,
        /// PC relative 24 bit (`BL`, `BLX`).
        R_ARM_CALL = 28,
        /// PC relative 24 bit (`B`, `BL<cond>`).
        R_ARM_JUMP24 = 29,
        /// PC relative 24 bit (Thumb32 `B.W`).
        R_ARM_THM_JUMP24 = 30,
        /// Adjust by program base.
        R_ARM_BASE_ABS = 31,
        /// Obsolete.
        R_ARM_ALU_PCREL_7_0 = 32,
        /// Obsolete.
        R_ARM_ALU_PCREL_15_8 = 33,
        /// Obsolete.
        R_ARM_ALU_PCREL_23_15 = 34,
        /// Deprecated, prog. base relative.
        R_ARM_LDR_SBREL_11_0 = 35,
        /// Deprecated, prog. base relative.
        R_ARM_ALU_SBREL_19_12 = 36,
        /// Deprecated, prog. base relative.
        R_ARM_ALU_SBREL_27_20 = 37,
        R_ARM_TARGET1 = 38,
        /// Program base relative.
        R_ARM_SBREL31 = 39,
        R_ARM_V4BX = 40,
        R_ARM_TARGET2 = 41,
        /// 32 bit PC relative.
        R_ARM_PREL31 = 42,
        /// Direct 16-bit (`MOVW`).
        R_ARM_MOVW_ABS_NC = 43,
        /// Direct high 16-bit (`MOVT`).
        R_ARM_MOVT_ABS = 44,
        /// PC relative 16-bit (`MOVW`).
        R_ARM_MOVW_PREL_NC = 45,
        /// PC relative (MOVT).
        R_ARM_MOVT_PREL = 46,
        /// Direct 16 bit (Thumb32 `MOVW`).
        R_ARM_THM_MOVW_ABS_NC = 47,
        /// Direct high 16 bit (Thumb32 `MOVT`).
        R_ARM_THM_MOVT_ABS = 48,
        /// PC relative 16 bit (Thumb32 `MOVW`).
        R_ARM_THM_MOVW_PREL_NC = 49,
        /// PC relative high 16 bit (Thumb32 `MOVT`).
        R_ARM_THM_MOVT_PREL = 50,
        /// PC relative 20 bit (Thumb32 `B<cond>.W`).
        R_ARM_THM_JUMP19 = 51,
        /// PC relative X & 0x7E (Thumb16 `CBZ`, `CBNZ`).
        R_ARM_THM_JUMP6 = 52,
        /// PC relative 12 bit (Thumb32 `ADR.W`).
        R_ARM_THM_ALU_PREL_11_0 = 53,
        /// PC relative 12 bit (Thumb32 `LDR{D,SB,H,SH}`).
        R_ARM_THM_PC12 = 54,
        /// Direct 32-bit.
        R_ARM_ABS32_NOI = 55,
        /// PC relative 32-bit.
        R_ARM_REL32_NOI = 56,
        /// PC relative (`ADD`, `SUB`).
        R_ARM_ALU_PC_G0_NC = 57,
        /// PC relative (`ADD`, `SUB`).
        R_ARM_ALU_PC_G0 = 58,
        /// PC relative (`ADD`, `SUB`).
        R_ARM_ALU_PC_G1_NC = 59,
        /// PC relative (`ADD`, `SUB`).
        R_ARM_ALU_PC_G1 = 60,
        /// PC relative (`ADD`, `SUB`).
        R_ARM_ALU_PC_G2 = 61,
        /// PC relative (`LDR`,`STR`,`LDRB`,`STRB`).
        R_ARM_LDR_PC_G1 = 62,
        /// PC relative (`LDR`,`STR`,`LDRB`,`STRB`).
        R_ARM_LDR_PC_G2 = 63,
        /// PC relative (`STR{D,H}`, `LDR{D,SB,H,SH}`).
        R_ARM_LDRS_PC_G0 = 64,
        /// PC relative (`STR{D,H}`, `LDR{D,SB,H,SH}`).
        R_ARM_LDRS_PC_G1 = 65,
        /// PC relative (`STR{D,H}`, `LDR{D,SB,H,SH}`).
        R_ARM_LDRS_PC_G2 = 66,
        /// PC relative (`LDC`, `STC`).
        R_ARM_LDC_PC_G0 = 67,
        /// PC relative (`LDC`, `STC`).
        R_ARM_LDC_PC_G1 = 68,
        /// PC relative (`LDC`, `STC`).
        R_ARM_LDC_PC_G2 = 69,
        /// Program base relative (`ADD`,`SUB`).
        R_ARM_ALU_SB_G0_NC = 70,
        /// Program base relative (`ADD`,`SUB`).
        R_ARM_ALU_SB_G0 = 71,
        /// Program base relative (`ADD`,`SUB`).
        R_ARM_ALU_SB_G1_NC = 72,
        /// Program base relative (`ADD`,`SUB`).
        R_ARM_ALU_SB_G1 = 73,
        /// Program base relative (`ADD`,`SUB`).
        R_ARM_ALU_SB_G2 = 74,
        /// Program base relative (`LDR`, `STR`, `LDRB`, `STRB`).
        R_ARM_LDR_SB_G0 = 75,
        /// Program base relative (`LDR`, `STR`, `LDRB`, `STRB`).
        R_ARM_LDR_SB_G1 = 76,
        /// Program base relative (`LDR`, `STR`, `LDRB`, `STRB`).
        R_ARM_LDR_SB_G2 = 77,
        /// Program base relative (`LDR`, `STR`, `LDRB`, `STRB`).
        R_ARM_LDRS_SB_G0 = 78,
        /// Program base relative (`LDR`, `STR`, `LDRB`, `STRB`).
        R_ARM_LDRS_SB_G1 = 79,
        /// Program base relative (`LDR`, `STR`, `LDRB`, `STRB`).
        R_ARM_LDRS_SB_G2 = 80,
        /// Program base relative (`LDC`,`STC`).
        R_ARM_LDC_SB_G0 = 81,
        /// Program base relative (`LDC`,`STC`).
        R_ARM_LDC_SB_G1 = 82,
        /// Program base relative (`LDC`,`STC`).
        R_ARM_LDC_SB_G2 = 83,
        /// Program base relative 16 bit (`MOVW`).
        R_ARM_MOVW_BREL_NC = 84,
        /// Program base relative high 16 bit (`MOVT`).
        R_ARM_MOVT_BREL = 85,
        /// Program base relative 16 bit (`MOVW`).
        R_ARM_MOVW_BREL = 86,
        /// Program base relative 16 bit (Thumb32 `MOVW`).
        R_ARM_THM_MOVW_BREL_NC = 87,
        /// Program base relative high 16 bit (Thumb32 `MOVT`).
        R_ARM_THM_MOVT_BREL = 88,
        /// Program base relative 16 bit (Thumb32 `MOVW`).
        R_ARM_THM_MOVW_BREL = 89,
        R_ARM_TLS_GOTDESC = 90,
        R_ARM_TLS_CALL = 91,
        /// TLS relaxation.
        R_ARM_TLS_DESCSEQ = 92,
        R_ARM_THM_TLS_CALL = 93,
        R_ARM_PLT32_ABS = 94,
        /// GOT entry.
        R_ARM_GOT_ABS = 95,
        /// PC relative GOT entry.
        R_ARM_GOT_PREL = 96,
        /// GOT entry relative to GOT origin (`LDR`).
        R_ARM_GOT_BREL12 = 97,
        /// 12 bit, GOT entry relative to GOT origin (`LDR`, `STR`).
        R_ARM_GOTOFF12 = 98,
        R_ARM_GOTRELAX = 99,
        R_ARM_GNU_VTENTRY = 100,
        R_ARM_GNU_VTINHERIT = 101,
        /// PC relative & 0xFFE (Thumb16 `B`).
        R_ARM_THM_PC11 = 102,
        /// PC relative & 0x1FE (Thumb16 `B`/`B<cond>`).
        R_ARM_THM_PC9 = 103,
        /// PC-rel 32 bit for global dynamic thread local data
        R_ARM_TLS_GD32 = 104,
        /// PC-rel 32 bit for local dynamic thread local data
        R_ARM_TLS_LDM32 = 105,
        /// 32 bit offset relative to TLS block
        R_ARM_TLS_LDO32 = 106,
        /// PC-rel 32 bit for GOT entry of static TLS block offset
        R_ARM_TLS_IE32 = 107,
        /// 32 bit offset relative to static TLS block
        R_ARM_TLS_LE32 = 108,
        /// 12 bit relative to TLS block (`LDR`, `STR`).
        R_ARM_TLS_LDO12 = 109,
        /// 12 bit relative to static TLS block (`LDR`, `STR`).
        R_ARM_TLS_LE12 = 110,
        /// 12 bit GOT entry relative to GOT origin (`LDR`).
        R_ARM_TLS_IE12GP = 111,
        /// Obsolete.
        R_ARM_ME_TOO = 128,
        R_ARM_THM_TLS_DESCSEQ = 129,
        R_ARM_THM_TLS_DESCSEQ16 = 129,
        R_ARM_THM_TLS_DESCSEQ32 = 130,
        /// GOT entry relative to GOT origin, 12 bit (Thumb32 `LDR`).
        R_ARM_THM_GOT_BREL12 = 131,
        R_ARM_IRELATIVE = 160,
        R_ARM_RXPC25 = 249,
        R_ARM_RSBREL32 = 250,
        R_ARM_THM_RPC22 = 251,
        R_ARM_RREL32 = 252,
        R_ARM_RABS22 = 253,
        R_ARM_RPC24 = 254,
        R_ARM_RBASE = 255,
    };
}

constant_names!(NAMES_EF_ARM_EABI: FileFlags(u32) = {
    EF_ARM_EABI_UNKNOWN = 0x0000_0000,
    EF_ARM_EABI_VER1 = 0x0100_0000,
    EF_ARM_EABI_VER2 = 0x0200_0000,
    EF_ARM_EABI_VER3 = 0x0300_0000,
    EF_ARM_EABI_VER4 = 0x0400_0000,
    EF_ARM_EABI_VER5 = 0x0500_0000,
});

/// NB conflicts with EF_ARM_SOFT_FLOAT
pub const EF_ARM_ABI_FLOAT_SOFT: u32 = 0x200;
/// NB conflicts with EF_ARM_VFP_FLOAT
pub const EF_ARM_ABI_FLOAT_HARD: u32 = 0x400;

// Other constants defined in the ARM ELF spec. version B-01.
// NB. These conflict with values defined above.
pub const EF_ARM_SYMSARESORTED: u32 = 0x04;
pub const EF_ARM_DYNSYMSUSESEGIDX: u32 = 0x08;
pub const EF_ARM_MAPSYMSFIRST: u32 = 0x10;

names! {
    struct Aarch64(Base);
    consts sht: SectionType(u32) = {
        /// AArch64 attributes section.
        SHT_AARCH64_ATTRIBUTES = SHT_LOPROC + 3,
    };
    flags sto: SymbolOther(u8) = {
        // AArch64 values for `Sym64::st_other`.
        STO_AARCH64_VARIANT_PCS = 0x80,
    };
    consts dt: DynamicTag(i64) = {
        DT_AARCH64_BTI_PLT = DT_LOPROC + 1,
        DT_AARCH64_PAC_PLT = DT_LOPROC + 3,
        DT_AARCH64_VARIANT_PCS = DT_LOPROC + 5,
    };
    /// `Rel*::r_type` values for `EM_AARCH64`.
    consts r = pub NAMES_R_AARCH64: RelocationType(u32) = {
        /// No relocation.
        R_AARCH64_NONE = 0,

        // ILP32 AArch64 relocs.
        /// Direct 32 bit.
        R_AARCH64_P32_ABS32 = 1,
        /// Copy symbol at runtime.
        R_AARCH64_P32_COPY = 180,
        /// Create GOT entry.
        R_AARCH64_P32_GLOB_DAT = 181,
        /// Create PLT entry.
        R_AARCH64_P32_JUMP_SLOT = 182,
        /// Adjust by program base.
        R_AARCH64_P32_RELATIVE = 183,
        /// Module number, 32 bit.
        R_AARCH64_P32_TLS_DTPMOD = 184,
        /// Module-relative offset, 32 bit.
        R_AARCH64_P32_TLS_DTPREL = 185,
        /// TP-relative offset, 32 bit.
        R_AARCH64_P32_TLS_TPREL = 186,
        /// TLS Descriptor.
        R_AARCH64_P32_TLSDESC = 187,
        /// STT_GNU_IFUNC relocation.
        R_AARCH64_P32_IRELATIVE = 188,

        // LP64 AArch64 relocs.
        /// Direct 64 bit.
        R_AARCH64_ABS64 = 257,
        /// Direct 32 bit.
        R_AARCH64_ABS32 = 258,
        /// Direct 16-bit.
        R_AARCH64_ABS16 = 259,
        /// PC-relative 64-bit.
        R_AARCH64_PREL64 = 260,
        /// PC-relative 32-bit.
        R_AARCH64_PREL32 = 261,
        /// PC-relative 16-bit.
        R_AARCH64_PREL16 = 262,
        /// Dir. MOVZ imm. from bits 15:0.
        R_AARCH64_MOVW_UABS_G0 = 263,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_UABS_G0_NC = 264,
        /// Dir. MOVZ imm. from bits 31:16.
        R_AARCH64_MOVW_UABS_G1 = 265,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_UABS_G1_NC = 266,
        /// Dir. MOVZ imm. from bits 47:32.
        R_AARCH64_MOVW_UABS_G2 = 267,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_UABS_G2_NC = 268,
        /// Dir. MOV{K,Z} imm. from 63:48.
        R_AARCH64_MOVW_UABS_G3 = 269,
        /// Dir. MOV{N,Z} imm. from 15:0.
        R_AARCH64_MOVW_SABS_G0 = 270,
        /// Dir. MOV{N,Z} imm. from 31:16.
        R_AARCH64_MOVW_SABS_G1 = 271,
        /// Dir. MOV{N,Z} imm. from 47:32.
        R_AARCH64_MOVW_SABS_G2 = 272,
        /// PC-rel. LD imm. from bits 20:2.
        R_AARCH64_LD_PREL_LO19 = 273,
        /// PC-rel. ADR imm. from bits 20:0.
        R_AARCH64_ADR_PREL_LO21 = 274,
        /// Page-rel. ADRP imm. from 32:12.
        R_AARCH64_ADR_PREL_PG_HI21 = 275,
        /// Likewise; no overflow check.
        R_AARCH64_ADR_PREL_PG_HI21_NC = 276,
        /// Dir. ADD imm. from bits 11:0.
        R_AARCH64_ADD_ABS_LO12_NC = 277,
        /// Likewise for LD/ST; no check.
        R_AARCH64_LDST8_ABS_LO12_NC = 278,
        /// PC-rel. TBZ/TBNZ imm. from 15:2.
        R_AARCH64_TSTBR14 = 279,
        /// PC-rel. cond. br. imm. from 20:2.
        R_AARCH64_CONDBR19 = 280,
        /// PC-rel. B imm. from bits 27:2.
        R_AARCH64_JUMP26 = 282,
        /// Likewise for CALL.
        R_AARCH64_CALL26 = 283,
        /// Dir. ADD imm. from bits 11:1.
        R_AARCH64_LDST16_ABS_LO12_NC = 284,
        /// Likewise for bits 11:2.
        R_AARCH64_LDST32_ABS_LO12_NC = 285,
        /// Likewise for bits 11:3.
        R_AARCH64_LDST64_ABS_LO12_NC = 286,
        /// PC-rel. MOV{N,Z} imm. from 15:0.
        R_AARCH64_MOVW_PREL_G0 = 287,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_PREL_G0_NC = 288,
        /// PC-rel. MOV{N,Z} imm. from 31:16.
        R_AARCH64_MOVW_PREL_G1 = 289,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_PREL_G1_NC = 290,
        /// PC-rel. MOV{N,Z} imm. from 47:32.
        R_AARCH64_MOVW_PREL_G2 = 291,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_PREL_G2_NC = 292,
        /// PC-rel. MOV{N,Z} imm. from 63:48.
        R_AARCH64_MOVW_PREL_G3 = 293,
        /// Dir. ADD imm. from bits 11:4.
        R_AARCH64_LDST128_ABS_LO12_NC = 299,
        /// GOT-rel. off. MOV{N,Z} imm. 15:0.
        R_AARCH64_MOVW_GOTOFF_G0 = 300,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_GOTOFF_G0_NC = 301,
        /// GOT-rel. o. MOV{N,Z} imm. 31:16.
        R_AARCH64_MOVW_GOTOFF_G1 = 302,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_GOTOFF_G1_NC = 303,
        /// GOT-rel. o. MOV{N,Z} imm. 47:32.
        R_AARCH64_MOVW_GOTOFF_G2 = 304,
        /// Likewise for MOVK; no check.
        R_AARCH64_MOVW_GOTOFF_G2_NC = 305,
        /// GOT-rel. o. MOV{N,Z} imm. 63:48.
        R_AARCH64_MOVW_GOTOFF_G3 = 306,
        /// GOT-relative 64-bit.
        R_AARCH64_GOTREL64 = 307,
        /// GOT-relative 32-bit.
        R_AARCH64_GOTREL32 = 308,
        /// PC-rel. GOT off. load imm. 20:2.
        R_AARCH64_GOT_LD_PREL19 = 309,
        /// GOT-rel. off. LD/ST imm. 14:3.
        R_AARCH64_LD64_GOTOFF_LO15 = 310,
        /// P-page-rel. GOT off. ADRP 32:12.
        R_AARCH64_ADR_GOT_PAGE = 311,
        /// Dir. GOT off. LD/ST imm. 11:3.
        R_AARCH64_LD64_GOT_LO12_NC = 312,
        /// GOT-page-rel. GOT off. LD/ST 14:3
        R_AARCH64_LD64_GOTPAGE_LO15 = 313,
        /// PC-relative 32-bit.
        R_AARCH64_PLT32 = 314,
        /// GOT-relative PC-relative.
        R_AARCH64_GOTPCREL32 = 315,
        /// PC-relative ADR imm. 20:0.
        R_AARCH64_TLSGD_ADR_PREL21 = 512,
        /// page-rel. ADRP imm. 32:12.
        R_AARCH64_TLSGD_ADR_PAGE21 = 513,
        /// direct ADD imm. from 11:0.
        R_AARCH64_TLSGD_ADD_LO12_NC = 514,
        /// GOT-rel. MOV{N,Z} 31:16.
        R_AARCH64_TLSGD_MOVW_G1 = 515,
        /// GOT-rel. MOVK imm. 15:0.
        R_AARCH64_TLSGD_MOVW_G0_NC = 516,
        /// Like 512; local dynamic model.
        R_AARCH64_TLSLD_ADR_PREL21 = 517,
        /// Like 513; local dynamic model.
        R_AARCH64_TLSLD_ADR_PAGE21 = 518,
        /// Like 514; local dynamic model.
        R_AARCH64_TLSLD_ADD_LO12_NC = 519,
        /// Like 515; local dynamic model.
        R_AARCH64_TLSLD_MOVW_G1 = 520,
        /// Like 516; local dynamic model.
        R_AARCH64_TLSLD_MOVW_G0_NC = 521,
        /// TLS PC-rel. load imm. 20:2.
        R_AARCH64_TLSLD_LD_PREL19 = 522,
        /// TLS DTP-rel. MOV{N,Z} 47:32.
        R_AARCH64_TLSLD_MOVW_DTPREL_G2 = 523,
        /// TLS DTP-rel. MOV{N,Z} 31:16.
        R_AARCH64_TLSLD_MOVW_DTPREL_G1 = 524,
        /// Likewise; MOVK; no check.
        R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC = 525,
        /// TLS DTP-rel. MOV{N,Z} 15:0.
        R_AARCH64_TLSLD_MOVW_DTPREL_G0 = 526,
        /// Likewise; MOVK; no check.
        R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC = 527,
        /// DTP-rel. ADD imm. from 23:12.
        R_AARCH64_TLSLD_ADD_DTPREL_HI12 = 528,
        /// DTP-rel. ADD imm. from 11:0.
        R_AARCH64_TLSLD_ADD_DTPREL_LO12 = 529,
        /// Likewise; no ovfl. check.
        R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC = 530,
        /// DTP-rel. LD/ST imm. 11:0.
        R_AARCH64_TLSLD_LDST8_DTPREL_LO12 = 531,
        /// Likewise; no check.
        R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC = 532,
        /// DTP-rel. LD/ST imm. 11:1.
        R_AARCH64_TLSLD_LDST16_DTPREL_LO12 = 533,
        /// Likewise; no check.
        R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC = 534,
        /// DTP-rel. LD/ST imm. 11:2.
        R_AARCH64_TLSLD_LDST32_DTPREL_LO12 = 535,
        /// Likewise; no check.
        R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC = 536,
        /// DTP-rel. LD/ST imm. 11:3.
        R_AARCH64_TLSLD_LDST64_DTPREL_LO12 = 537,
        /// Likewise; no check.
        R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC = 538,
        /// GOT-rel. MOV{N,Z} 31:16.
        R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 = 539,
        /// GOT-rel. MOVK 15:0.
        R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC = 540,
        /// Page-rel. ADRP 32:12.
        R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 = 541,
        /// Direct LD off. 11:3.
        R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC = 542,
        /// PC-rel. load imm. 20:2.
        R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 = 543,
        /// TLS TP-rel. MOV{N,Z} 47:32.
        R_AARCH64_TLSLE_MOVW_TPREL_G2 = 544,
        /// TLS TP-rel. MOV{N,Z} 31:16.
        R_AARCH64_TLSLE_MOVW_TPREL_G1 = 545,
        /// Likewise; MOVK; no check.
        R_AARCH64_TLSLE_MOVW_TPREL_G1_NC = 546,
        /// TLS TP-rel. MOV{N,Z} 15:0.
        R_AARCH64_TLSLE_MOVW_TPREL_G0 = 547,
        /// Likewise; MOVK; no check.
        R_AARCH64_TLSLE_MOVW_TPREL_G0_NC = 548,
        /// TP-rel. ADD imm. 23:12.
        R_AARCH64_TLSLE_ADD_TPREL_HI12 = 549,
        /// TP-rel. ADD imm. 11:0.
        R_AARCH64_TLSLE_ADD_TPREL_LO12 = 550,
        /// Likewise; no ovfl. check.
        R_AARCH64_TLSLE_ADD_TPREL_LO12_NC = 551,
        /// TP-rel. LD/ST off. 11:0.
        R_AARCH64_TLSLE_LDST8_TPREL_LO12 = 552,
        /// Likewise; no ovfl. check.
        R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC = 553,
        /// TP-rel. LD/ST off. 11:1.
        R_AARCH64_TLSLE_LDST16_TPREL_LO12 = 554,
        /// Likewise; no check.
        R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC = 555,
        /// TP-rel. LD/ST off. 11:2.
        R_AARCH64_TLSLE_LDST32_TPREL_LO12 = 556,
        /// Likewise; no check.
        R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC = 557,
        /// TP-rel. LD/ST off. 11:3.
        R_AARCH64_TLSLE_LDST64_TPREL_LO12 = 558,
        /// Likewise; no check.
        R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC = 559,
        /// PC-rel. load immediate 20:2.
        R_AARCH64_TLSDESC_LD_PREL19 = 560,
        /// PC-rel. ADR immediate 20:0.
        R_AARCH64_TLSDESC_ADR_PREL21 = 561,
        /// Page-rel. ADRP imm. 32:12.
        R_AARCH64_TLSDESC_ADR_PAGE21 = 562,
        /// Direct LD off. from 11:3.
        R_AARCH64_TLSDESC_LD64_LO12 = 563,
        /// Direct ADD imm. from 11:0.
        R_AARCH64_TLSDESC_ADD_LO12 = 564,
        /// GOT-rel. MOV{N,Z} imm. 31:16.
        R_AARCH64_TLSDESC_OFF_G1 = 565,
        /// GOT-rel. MOVK imm. 15:0; no ck.
        R_AARCH64_TLSDESC_OFF_G0_NC = 566,
        /// Relax LDR.
        R_AARCH64_TLSDESC_LDR = 567,
        /// Relax ADD.
        R_AARCH64_TLSDESC_ADD = 568,
        /// Relax BLR.
        R_AARCH64_TLSDESC_CALL = 569,
        /// TP-rel. LD/ST off. 11:4.
        R_AARCH64_TLSLE_LDST128_TPREL_LO12 = 570,
        /// Likewise; no check.
        R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC = 571,
        /// DTP-rel. LD/ST imm. 11:4.
        R_AARCH64_TLSLD_LDST128_DTPREL_LO12 = 572,
        /// Likewise; no check.
        R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC = 573,
        /// Copy symbol at runtime.
        R_AARCH64_COPY = 1024,
        /// Create GOT entry.
        R_AARCH64_GLOB_DAT = 1025,
        /// Create PLT entry.
        R_AARCH64_JUMP_SLOT = 1026,
        /// Adjust by program base.
        R_AARCH64_RELATIVE = 1027,
        /// Module number, 64 bit.
        R_AARCH64_TLS_DTPMOD = 1028,
        /// Module-relative offset, 64 bit.
        R_AARCH64_TLS_DTPREL = 1029,
        /// TP-relative offset, 64 bit.
        R_AARCH64_TLS_TPREL = 1030,
        /// TLS Descriptor.
        R_AARCH64_TLSDESC = 1031,
        /// STT_GNU_IFUNC relocation.
        R_AARCH64_IRELATIVE = 1032,
    };
}

pub const DT_AARCH64_NUM: i64 = 6;

names! {
    struct Avr(Base);
    flags ef: FileFlags(u32) = {
        /// If set, it is assumed that the elf file uses local symbols as reference
        /// for the relocations so that linker relaxation is possible.
        EF_AVR_LINKRELAX_PREPARED = 0x80,

        /// Bitmask for `EF_AVR_ARCH_*`.
        EF_AVR_ARCH = 0x7F => NAMES_EF_AVR_ARCH,
    };
    /// `Rel*::r_type` values for `EM_AVR`.
    consts r = pub NAMES_R_AVR: RelocationType(u32) = {
        R_AVR_NONE = 0,
        /// Direct 32 bit
        R_AVR_32 = 1,
        R_AVR_7_PCREL = 2,
        R_AVR_13_PCREL = 3,
        /// Direct 16 bit
        R_AVR_16 = 4,
        R_AVR_16_PM = 5,
        R_AVR_LO8_LDI = 6,
        R_AVR_HI8_LDI = 7,
        R_AVR_HH8_LDI = 8,
        R_AVR_LO8_LDI_NEG = 9,
        R_AVR_HI8_LDI_NEG = 10,
        R_AVR_HH8_LDI_NEG = 11,
        R_AVR_LO8_LDI_PM = 12,
        R_AVR_HI8_LDI_PM = 13,
        R_AVR_HH8_LDI_PM = 14,
        R_AVR_LO8_LDI_PM_NEG = 15,
        R_AVR_HI8_LDI_PM_NEG = 16,
        R_AVR_HH8_LDI_PM_NEG = 17,
        R_AVR_CALL = 18,
        R_AVR_LDI = 19,
        R_AVR_6 = 20,
        R_AVR_6_ADIW = 21,
        R_AVR_MS8_LDI = 22,
        R_AVR_MS8_LDI_NEG = 23,
        R_AVR_LO8_LDI_GS = 24,
        R_AVR_HI8_LDI_GS = 25,
        R_AVR_8 = 26,
        R_AVR_8_LO8 = 27,
        R_AVR_8_HI8 = 28,
        R_AVR_8_HLO8 = 29,
        R_AVR_DIFF8 = 30,
        R_AVR_DIFF16 = 31,
        R_AVR_DIFF32 = 32,
        R_AVR_LDS_STS_16 = 33,
        R_AVR_PORT6 = 34,
        R_AVR_PORT5 = 35,
        R_AVR_32_PCREL = 36,
    };
}

constant_names!(NAMES_EF_AVR_ARCH: FileFlags(u32) = {
    EF_AVR_ARCH_AVR1 = 1,
    EF_AVR_ARCH_AVR2 = 2,
    EF_AVR_ARCH_AVR25 = 25,
    EF_AVR_ARCH_AVR3 = 3,
    EF_AVR_ARCH_AVR31 = 31,
    EF_AVR_ARCH_AVR35 = 35,
    EF_AVR_ARCH_AVR4 = 4,
    EF_AVR_ARCH_AVR5 = 5,
    EF_AVR_ARCH_AVR51 = 51,
    EF_AVR_ARCH_AVR6 = 6,
    EF_AVR_ARCH_AVRTINY = 100,
    EF_AVR_ARCH_XMEGA1 = 101,
    EF_AVR_ARCH_XMEGA2 = 102,
    EF_AVR_ARCH_XMEGA3 = 103,
    EF_AVR_ARCH_XMEGA4 = 104,
    EF_AVR_ARCH_XMEGA5 = 105,
    EF_AVR_ARCH_XMEGA6 = 106,
    EF_AVR_ARCH_XMEGA7 = 107,
});

names! {
    struct Msp430(Base);
    /// `Rel*::r_type` values for `EM_MSP430`.
    consts r = pub NAMES_R_MSP430: RelocationType(u32) = {
        /// No reloc
        R_MSP430_NONE = 0,
        /// Direct 32 bit
        R_MSP430_32 = 1,
        /// Direct 16 bit
        R_MSP430_16_BYTE = 5,
    };
}

names! {
    struct Hex(Base);
    /// `Rel*::r_type` values for `EM_HEXAGON`.
    consts r = pub NAMES_R_HEX: RelocationType(u32) = {
        /// No reloc
        R_HEX_NONE = 0,
        /// Direct 32 bit
        R_HEX_32 = 6,
    };
}

names! {
    struct Csky(Base);
    /// `Rel*::r_type` values for `EM_CSKY`.
    consts r = pub NAMES_R_CKCORE: RelocationType(u32) = {
        /// no reloc
        R_CKCORE_NONE = 0,
        /// direct 32 bit (S + A)
        R_CKCORE_ADDR32 = 1,
        /// disp ((S + A - P) >> 2) & 0xff
        R_CKCORE_PCRELIMM8BY4 = 2,
        /// disp ((S + A - P) >> 1) & 0x7ff
        R_CKCORE_PCRELIMM11BY2 = 3,
        /// 32-bit rel (S + A - P)
        R_CKCORE_PCREL32 = 5,
        /// disp ((S + A - P) >>1) & 0x7ff
        R_CKCORE_PCRELJSR_IMM11BY2 = 6,
        /// 32 bit adjust program base(B + A)
        R_CKCORE_RELATIVE = 9,
        /// 32 bit adjust by program base
        R_CKCORE_COPY = 10,
        /// off between got and sym (S)
        R_CKCORE_GLOB_DAT = 11,
        /// PLT entry (S)
        R_CKCORE_JUMP_SLOT = 12,
        /// offset to GOT (S + A - GOT)
        R_CKCORE_GOTOFF = 13,
        /// PC offset to GOT (GOT + A - P)
        R_CKCORE_GOTPC = 14,
        /// 32 bit GOT entry (G)
        R_CKCORE_GOT32 = 15,
        /// 32 bit PLT entry (G)
        R_CKCORE_PLT32 = 16,
        /// GOT entry in GLOB_DAT (GOT + G)
        R_CKCORE_ADDRGOT = 17,
        /// PLT entry in GLOB_DAT (GOT + G)
        R_CKCORE_ADDRPLT = 18,
        /// ((S + A - P) >> 1) & 0x3ff_ffff
        R_CKCORE_PCREL_IMM26BY2 = 19,
        /// disp ((S + A - P) >> 1) & 0xffff
        R_CKCORE_PCREL_IMM16BY2 = 20,
        /// disp ((S + A - P) >> 2) & 0xffff
        R_CKCORE_PCREL_IMM16BY4 = 21,
        /// disp ((S + A - P) >> 1) & 0x3ff
        R_CKCORE_PCREL_IMM10BY2 = 22,
        /// disp ((S + A - P) >> 2) & 0x3ff
        R_CKCORE_PCREL_IMM10BY4 = 23,
        /// high & low 16 bit ADDR, ((S + A) >> 16) & 0xffff
        R_CKCORE_ADDR_HI16 = 24,
        /// (S + A) & 0xffff
        R_CKCORE_ADDR_LO16 = 25,
        /// high & low 16 bit GOTPC, ((GOT + A - P) >> 16) & 0xffff
        R_CKCORE_GOTPC_HI16 = 26,
        /// (GOT + A - P) & 0xffff
        R_CKCORE_GOTPC_LO16 = 27,
        /// high & low 16 bit GOTOFF, ((S + A - GOT) >> 16) & 0xffff
        R_CKCORE_GOTOFF_HI16 = 28,
        /// (S + A - GOT) & 0xffff
        R_CKCORE_GOTOFF_LO16 = 29,
        /// 12 bit disp GOT entry (G)
        R_CKCORE_GOT12 = 30,
        /// high & low 16 bit GOT, (G >> 16) & 0xffff
        R_CKCORE_GOT_HI16 = 31,
        /// (G & 0xffff)
        R_CKCORE_GOT_LO16 = 32,
        /// 12 bit disp PLT entry (G)
        R_CKCORE_PLT12 = 33,
        /// high & low 16 bit PLT, (G >> 16) & 0xffff
        R_CKCORE_PLT_HI16 = 34,
        /// G & 0xffff
        R_CKCORE_PLT_LO16 = 35,
        /// high & low 16 bit ADDRGOT, (GOT + G * 4) & 0xffff
        R_CKCORE_ADDRGOT_HI16 = 36,
        /// (GOT + G * 4) & 0xffff
        R_CKCORE_ADDRGOT_LO16 = 37,
        /// high & low 16 bit ADDRPLT, ((GOT + G * 4) >> 16) & 0xFFFF
        R_CKCORE_ADDRPLT_HI16 = 38,
        /// (GOT+G*4) & 0xffff
        R_CKCORE_ADDRPLT_LO16 = 39,
        /// disp ((S+A-P) >>1) & x3ff_ffff
        R_CKCORE_PCREL_JSR_IMM26BY2 = 40,
        /// (S+A-BTEXT) & 0xffff
        R_CKCORE_TOFFSET_LO16 = 41,
        /// (S+A-BTEXT) & 0xffff
        R_CKCORE_DOFFSET_LO16 = 42,
        /// disp ((S+A-P) >>1) & 0x3ffff
        R_CKCORE_PCREL_IMM18BY2 = 43,
        /// disp (S+A-BDATA) & 0x3ffff
        R_CKCORE_DOFFSET_IMM18 = 44,
        /// disp ((S+A-BDATA)>>1) & 0x3ffff
        R_CKCORE_DOFFSET_IMM18BY2 = 45,
        /// disp ((S+A-BDATA)>>2) & 0x3ffff
        R_CKCORE_DOFFSET_IMM18BY4 = 46,
        /// disp (G >> 2)
        R_CKCORE_GOT_IMM18BY4 = 48,
        /// disp (G >> 2)
        R_CKCORE_PLT_IMM18BY4 = 49,
        /// disp ((S+A-P) >>2) & 0x7f
        R_CKCORE_PCREL_IMM7BY4 = 50,
        /// 32 bit offset to TLS block
        R_CKCORE_TLS_LE32 = 51,
        R_CKCORE_TLS_IE32 = 52,
        R_CKCORE_TLS_GD32 = 53,
        R_CKCORE_TLS_LDM32 = 54,
        R_CKCORE_TLS_LDO32 = 55,
        R_CKCORE_TLS_DTPMOD32 = 56,
        R_CKCORE_TLS_DTPOFF32 = 57,
        R_CKCORE_TLS_TPOFF32 = 58,
    };
    flags ef: FileFlags(u32) = {
        _ = EF_CSKY_ABIMASK => NAMES_EF_CSKY_ABI,
    };
    consts sht: SectionType(u32) = {
        /// C-SKY attributes section.
        SHT_CSKY_ATTRIBUTES = SHT_LOPROC + 1,
    };
}

pub const EF_CSKY_ABIMASK: u32 = 0xF000_0000;
pub const EF_CSKY_OTHER: u32 = 0x0FFF_0000;
pub const EF_CSKY_PROCESSOR: u32 = 0x0000_FFFF;

constant_names!(NAMES_EF_CSKY_ABI: FileFlags(u32) = {
    EF_CSKY_ABIV1 = 0x1000_0000,
    EF_CSKY_ABIV2 = 0x2000_0000,
});

// IA-64 specific declarations.

names! {
    struct Ia64(Base);
    flags ef: FileFlags(u32) = {
        /// 64-bit ABI
        EF_IA_64_ABI64 = 0x0000_0010,
    };
    consts pt: ProgramType(u32) = {
        /// arch extension bits
        PT_IA_64_ARCHEXT = PT_LOPROC + 0,
        /// ia64 unwind bits
        PT_IA_64_UNWIND = PT_LOPROC + 1,
        PT_IA_64_HP_OPT_ANOT = PT_LOOS + 0x12,
        PT_IA_64_HP_HSL_ANOT = PT_LOOS + 0x13,
        PT_IA_64_HP_STACK = PT_LOOS + 0x14,
    };
    flags pf: ProgramFlags(u32) = {
        /// spec insns w/o recovery
        PF_IA_64_NORECOV = 0x8000_0000,
    };
    consts sht: SectionType(u32) = {
        /// extension bits
        SHT_IA_64_EXT = SHT_LOPROC + 0,
        /// unwind bits
        SHT_IA_64_UNWIND = SHT_LOPROC + 1,
    };
    flags shf: SectionFlags(u64) = {
        /// section near gp
        SHF_IA_64_SHORT = 0x1000_0000,
        /// spec insns w/o recovery
        SHF_IA_64_NORECOV = 0x2000_0000,
    };
    consts dt: DynamicTag(i64) = {
        DT_IA_64_PLT_RESERVE = DT_LOPROC + 0,
    };
    /// `Rel*::r_type` values for `EM_IA_64`.
    consts r = pub NAMES_R_IA64: RelocationType(u32) = {
        /// none
        R_IA64_NONE = 0x00,
        /// symbol + addend, add imm14
        R_IA64_IMM14 = 0x21,
        /// symbol + addend, add imm22
        R_IA64_IMM22 = 0x22,
        /// symbol + addend, mov imm64
        R_IA64_IMM64 = 0x23,
        /// symbol + addend, data4 MSB
        R_IA64_DIR32MSB = 0x24,
        /// symbol + addend, data4 LSB
        R_IA64_DIR32LSB = 0x25,
        /// symbol + addend, data8 MSB
        R_IA64_DIR64MSB = 0x26,
        /// symbol + addend, data8 LSB
        R_IA64_DIR64LSB = 0x27,
        /// @gprel(sym + add), add imm22
        R_IA64_GPREL22 = 0x2a,
        /// @gprel(sym + add), mov imm64
        R_IA64_GPREL64I = 0x2b,
        /// @gprel(sym + add), data4 MSB
        R_IA64_GPREL32MSB = 0x2c,
        /// @gprel(sym + add), data4 LSB
        R_IA64_GPREL32LSB = 0x2d,
        /// @gprel(sym + add), data8 MSB
        R_IA64_GPREL64MSB = 0x2e,
        /// @gprel(sym + add), data8 LSB
        R_IA64_GPREL64LSB = 0x2f,
        /// @ltoff(sym + add), add imm22
        R_IA64_LTOFF22 = 0x32,
        /// @ltoff(sym + add), mov imm64
        R_IA64_LTOFF64I = 0x33,
        /// @pltoff(sym + add), add imm22
        R_IA64_PLTOFF22 = 0x3a,
        /// @pltoff(sym + add), mov imm64
        R_IA64_PLTOFF64I = 0x3b,
        /// @pltoff(sym + add), data8 MSB
        R_IA64_PLTOFF64MSB = 0x3e,
        /// @pltoff(sym + add), data8 LSB
        R_IA64_PLTOFF64LSB = 0x3f,
        /// @fptr(sym + add), mov imm64
        R_IA64_FPTR64I = 0x43,
        /// @fptr(sym + add), data4 MSB
        R_IA64_FPTR32MSB = 0x44,
        /// @fptr(sym + add), data4 LSB
        R_IA64_FPTR32LSB = 0x45,
        /// @fptr(sym + add), data8 MSB
        R_IA64_FPTR64MSB = 0x46,
        /// @fptr(sym + add), data8 LSB
        R_IA64_FPTR64LSB = 0x47,
        /// @pcrel(sym + add), brl
        R_IA64_PCREL60B = 0x48,
        /// @pcrel(sym + add), ptb, call
        R_IA64_PCREL21B = 0x49,
        /// @pcrel(sym + add), chk.s
        R_IA64_PCREL21M = 0x4a,
        /// @pcrel(sym + add), fchkf
        R_IA64_PCREL21F = 0x4b,
        /// @pcrel(sym + add), data4 MSB
        R_IA64_PCREL32MSB = 0x4c,
        /// @pcrel(sym + add), data4 LSB
        R_IA64_PCREL32LSB = 0x4d,
        /// @pcrel(sym + add), data8 MSB
        R_IA64_PCREL64MSB = 0x4e,
        /// @pcrel(sym + add), data8 LSB
        R_IA64_PCREL64LSB = 0x4f,
        /// @ltoff(@fptr(s+a)), imm22
        R_IA64_LTOFF_FPTR22 = 0x52,
        /// @ltoff(@fptr(s+a)), imm64
        R_IA64_LTOFF_FPTR64I = 0x53,
        /// @ltoff(@fptr(s+a)), data4 MSB
        R_IA64_LTOFF_FPTR32MSB = 0x54,
        /// @ltoff(@fptr(s+a)), data4 LSB
        R_IA64_LTOFF_FPTR32LSB = 0x55,
        /// @ltoff(@fptr(s+a)), data8 MSB
        R_IA64_LTOFF_FPTR64MSB = 0x56,
        /// @ltoff(@fptr(s+a)), data8 LSB
        R_IA64_LTOFF_FPTR64LSB = 0x57,
        /// @segrel(sym + add), data4 MSB
        R_IA64_SEGREL32MSB = 0x5c,
        /// @segrel(sym + add), data4 LSB
        R_IA64_SEGREL32LSB = 0x5d,
        /// @segrel(sym + add), data8 MSB
        R_IA64_SEGREL64MSB = 0x5e,
        /// @segrel(sym + add), data8 LSB
        R_IA64_SEGREL64LSB = 0x5f,
        /// @secrel(sym + add), data4 MSB
        R_IA64_SECREL32MSB = 0x64,
        /// @secrel(sym + add), data4 LSB
        R_IA64_SECREL32LSB = 0x65,
        /// @secrel(sym + add), data8 MSB
        R_IA64_SECREL64MSB = 0x66,
        /// @secrel(sym + add), data8 LSB
        R_IA64_SECREL64LSB = 0x67,
        /// data 4 + REL
        R_IA64_REL32MSB = 0x6c,
        /// data 4 + REL
        R_IA64_REL32LSB = 0x6d,
        /// data 8 + REL
        R_IA64_REL64MSB = 0x6e,
        /// data 8 + REL
        R_IA64_REL64LSB = 0x6f,
        /// symbol + addend, data4 MSB
        R_IA64_LTV32MSB = 0x74,
        /// symbol + addend, data4 LSB
        R_IA64_LTV32LSB = 0x75,
        /// symbol + addend, data8 MSB
        R_IA64_LTV64MSB = 0x76,
        /// symbol + addend, data8 LSB
        R_IA64_LTV64LSB = 0x77,
        /// @pcrel(sym + add), 21bit inst
        R_IA64_PCREL21BI = 0x79,
        /// @pcrel(sym + add), 22bit inst
        R_IA64_PCREL22 = 0x7a,
        /// @pcrel(sym + add), 64bit inst
        R_IA64_PCREL64I = 0x7b,
        /// dynamic reloc, imported PLT, MSB
        R_IA64_IPLTMSB = 0x80,
        /// dynamic reloc, imported PLT, LSB
        R_IA64_IPLTLSB = 0x81,
        /// copy relocation
        R_IA64_COPY = 0x84,
        /// Addend and symbol difference
        R_IA64_SUB = 0x85,
        /// LTOFF22, relaxable.
        R_IA64_LTOFF22X = 0x86,
        /// Use of LTOFF22X.
        R_IA64_LDXMOV = 0x87,
        /// @tprel(sym + add), imm14
        R_IA64_TPREL14 = 0x91,
        /// @tprel(sym + add), imm22
        R_IA64_TPREL22 = 0x92,
        /// @tprel(sym + add), imm64
        R_IA64_TPREL64I = 0x93,
        /// @tprel(sym + add), data8 MSB
        R_IA64_TPREL64MSB = 0x96,
        /// @tprel(sym + add), data8 LSB
        R_IA64_TPREL64LSB = 0x97,
        /// @ltoff(@tprel(s+a)), imm2
        R_IA64_LTOFF_TPREL22 = 0x9a,
        /// @dtpmod(sym + add), data8 MSB
        R_IA64_DTPMOD64MSB = 0xa6,
        /// @dtpmod(sym + add), data8 LSB
        R_IA64_DTPMOD64LSB = 0xa7,
        /// @ltoff(@dtpmod(sym + add)), imm22
        R_IA64_LTOFF_DTPMOD22 = 0xaa,
        /// @dtprel(sym + add), imm14
        R_IA64_DTPREL14 = 0xb1,
        /// @dtprel(sym + add), imm22
        R_IA64_DTPREL22 = 0xb2,
        /// @dtprel(sym + add), imm64
        R_IA64_DTPREL64I = 0xb3,
        /// @dtprel(sym + add), data4 MSB
        R_IA64_DTPREL32MSB = 0xb4,
        /// @dtprel(sym + add), data4 LSB
        R_IA64_DTPREL32LSB = 0xb5,
        /// @dtprel(sym + add), data8 MSB
        R_IA64_DTPREL64MSB = 0xb6,
        /// @dtprel(sym + add), data8 LSB
        R_IA64_DTPREL64LSB = 0xb7,
        /// @ltoff(@dtprel(s+a)), imm22
        R_IA64_LTOFF_DTPREL22 = 0xba,
    };
}

/// os-specific flags
pub const EF_IA_64_MASKOS: u32 = 0x0000_000f;
/// arch. version mask
pub const EF_IA_64_ARCH: u32 = 0xff00_0000;

// SH specific declarations.

names! {
    struct Sh(Base);
    flags ef: FileFlags(u32) = {
        EF_SH_MACH_MASK = 0x1f => NAMES_EF_SH_MACH,
    };
    /// `Rel*::r_type` values for `EM_SH`.
    consts r = pub NAMES_R_SH: RelocationType(u32) = {
        R_SH_NONE = 0,
        R_SH_DIR32 = 1,
        R_SH_REL32 = 2,
        R_SH_DIR8WPN = 3,
        R_SH_IND12W = 4,
        R_SH_DIR8WPL = 5,
        R_SH_DIR8WPZ = 6,
        R_SH_DIR8BP = 7,
        R_SH_DIR8W = 8,
        R_SH_DIR8L = 9,
        R_SH_SWITCH16 = 25,
        R_SH_SWITCH32 = 26,
        R_SH_USES = 27,
        R_SH_COUNT = 28,
        R_SH_ALIGN = 29,
        R_SH_CODE = 30,
        R_SH_DATA = 31,
        R_SH_LABEL = 32,
        R_SH_SWITCH8 = 33,
        R_SH_GNU_VTINHERIT = 34,
        R_SH_GNU_VTENTRY = 35,
        R_SH_TLS_GD_32 = 144,
        R_SH_TLS_LD_32 = 145,
        R_SH_TLS_LDO_32 = 146,
        R_SH_TLS_IE_32 = 147,
        R_SH_TLS_LE_32 = 148,
        R_SH_TLS_DTPMOD32 = 149,
        R_SH_TLS_DTPOFF32 = 150,
        R_SH_TLS_TPOFF32 = 151,
        R_SH_GOT32 = 160,
        R_SH_PLT32 = 161,
        R_SH_COPY = 162,
        R_SH_GLOB_DAT = 163,
        R_SH_JMP_SLOT = 164,
        R_SH_RELATIVE = 165,
        R_SH_GOTOFF = 166,
        R_SH_GOTPC = 167,
    };
}

// S/390 specific definitions.

names! {
    struct S390(Base);
    flags ef: FileFlags(u32) = {
        /// High GPRs kernel facility needed.
        EF_S390_HIGH_GPRS = 0x0000_0001,
    };
    /// `Rel*::r_type` values for `EM_S390`.
    consts r = pub NAMES_R_390: RelocationType(u32) = {
        /// No reloc.
        R_390_NONE = 0,
        /// Direct 8 bit.
        R_390_8 = 1,
        /// Direct 12 bit.
        R_390_12 = 2,
        /// Direct 16 bit.
        R_390_16 = 3,
        /// Direct 32 bit.
        R_390_32 = 4,
        /// PC relative 32 bit.
        R_390_PC32 = 5,
        /// 12 bit GOT offset.
        R_390_GOT12 = 6,
        /// 32 bit GOT offset.
        R_390_GOT32 = 7,
        /// 32 bit PC relative PLT address.
        R_390_PLT32 = 8,
        /// Copy symbol at runtime.
        R_390_COPY = 9,
        /// Create GOT entry.
        R_390_GLOB_DAT = 10,
        /// Create PLT entry.
        R_390_JMP_SLOT = 11,
        /// Adjust by program base.
        R_390_RELATIVE = 12,
        /// 32 bit offset to GOT.
        R_390_GOTOFF32 = 13,
        /// 32 bit PC relative offset to GOT.
        R_390_GOTPC = 14,
        /// 16 bit GOT offset.
        R_390_GOT16 = 15,
        /// PC relative 16 bit.
        R_390_PC16 = 16,
        /// PC relative 16 bit shifted by 1.
        R_390_PC16DBL = 17,
        /// 16 bit PC rel. PLT shifted by 1.
        R_390_PLT16DBL = 18,
        /// PC relative 32 bit shifted by 1.
        R_390_PC32DBL = 19,
        /// 32 bit PC rel. PLT shifted by 1.
        R_390_PLT32DBL = 20,
        /// 32 bit PC rel. GOT shifted by 1.
        R_390_GOTPCDBL = 21,
        /// Direct 64 bit.
        R_390_64 = 22,
        /// PC relative 64 bit.
        R_390_PC64 = 23,
        /// 64 bit GOT offset.
        R_390_GOT64 = 24,
        /// 64 bit PC relative PLT address.
        R_390_PLT64 = 25,
        /// 32 bit PC rel. to GOT entry >> 1.
        R_390_GOTENT = 26,
        /// 16 bit offset to GOT.
        R_390_GOTOFF16 = 27,
        /// 64 bit offset to GOT.
        R_390_GOTOFF64 = 28,
        /// 12 bit offset to jump slot.
        R_390_GOTPLT12 = 29,
        /// 16 bit offset to jump slot.
        R_390_GOTPLT16 = 30,
        /// 32 bit offset to jump slot.
        R_390_GOTPLT32 = 31,
        /// 64 bit offset to jump slot.
        R_390_GOTPLT64 = 32,
        /// 32 bit rel. offset to jump slot.
        R_390_GOTPLTENT = 33,
        /// 16 bit offset from GOT to PLT.
        R_390_PLTOFF16 = 34,
        /// 32 bit offset from GOT to PLT.
        R_390_PLTOFF32 = 35,
        /// 16 bit offset from GOT to PLT.
        R_390_PLTOFF64 = 36,
        /// Tag for load insn in TLS code.
        R_390_TLS_LOAD = 37,
        /// Tag for function call in general dynamic TLS code.
        R_390_TLS_GDCALL = 38,
        /// Tag for function call in local dynamic TLS code.
        R_390_TLS_LDCALL = 39,
        /// Direct 32 bit for general dynamic thread local data.
        R_390_TLS_GD32 = 40,
        /// Direct 64 bit for general dynamic thread local data.
        R_390_TLS_GD64 = 41,
        /// 12 bit GOT offset for static TLS block offset.
        R_390_TLS_GOTIE12 = 42,
        /// 32 bit GOT offset for static TLS block offset.
        R_390_TLS_GOTIE32 = 43,
        /// 64 bit GOT offset for static TLS block offset.
        R_390_TLS_GOTIE64 = 44,
        /// Direct 32 bit for local dynamic thread local data in LE code.
        R_390_TLS_LDM32 = 45,
        /// Direct 64 bit for local dynamic thread local data in LE code.
        R_390_TLS_LDM64 = 46,
        /// 32 bit address of GOT entry for negated static TLS block offset.
        R_390_TLS_IE32 = 47,
        /// 64 bit address of GOT entry for negated static TLS block offset.
        R_390_TLS_IE64 = 48,
        /// 32 bit rel. offset to GOT entry for negated static TLS block offset.
        R_390_TLS_IEENT = 49,
        /// 32 bit negated offset relative to static TLS block.
        R_390_TLS_LE32 = 50,
        /// 64 bit negated offset relative to static TLS block.
        R_390_TLS_LE64 = 51,
        /// 32 bit offset relative to TLS block.
        R_390_TLS_LDO32 = 52,
        /// 64 bit offset relative to TLS block.
        R_390_TLS_LDO64 = 53,
        /// ID of module containing symbol.
        R_390_TLS_DTPMOD = 54,
        /// Offset in TLS block.
        R_390_TLS_DTPOFF = 55,
        /// Negated offset in static TLS block.
        R_390_TLS_TPOFF = 56,
        /// Direct 20 bit.
        R_390_20 = 57,
        /// 20 bit GOT offset.
        R_390_GOT20 = 58,
        /// 20 bit offset to jump slot.
        R_390_GOTPLT20 = 59,
        /// 20 bit GOT offset for static TLS block offset.
        R_390_TLS_GOTIE20 = 60,
        /// STT_GNU_IFUNC relocation.
        R_390_IRELATIVE = 61,
    };
}

constant_names!(NAMES_EF_SH_MACH: FileFlags(u32) = {
    EF_SH_UNKNOWN = 0x0,
    EF_SH1 = 0x1,
    EF_SH2 = 0x2,
    EF_SH3 = 0x3,
    EF_SH_DSP = 0x4,
    EF_SH3_DSP = 0x5,
    EF_SH4AL_DSP = 0x6,
    EF_SH3E = 0x8,
    EF_SH4 = 0x9,
    EF_SH2E = 0xb,
    EF_SH4A = 0xc,
    EF_SH2A = 0xd,
    EF_SH4_NOFPU = 0x10,
    EF_SH4A_NOFPU = 0x11,
    EF_SH4_NOMMU_NOFPU = 0x12,
    EF_SH2A_NOFPU = 0x13,
    EF_SH3_NOMMU = 0x14,
    EF_SH2A_SH4_NOFPU = 0x15,
    EF_SH2A_SH3_NOFPU = 0x16,
    EF_SH2A_SH4 = 0x17,
    EF_SH2A_SH3E = 0x18,
});

names! {
    struct Cris(Base);
    /// `Rel*::r_type` values for `EM_CRIS`.
    consts r = pub NAMES_R_CRIS: RelocationType(u32) = {
        R_CRIS_NONE = 0,
        R_CRIS_8 = 1,
        R_CRIS_16 = 2,
        R_CRIS_32 = 3,
        R_CRIS_8_PCREL = 4,
        R_CRIS_16_PCREL = 5,
        R_CRIS_32_PCREL = 6,
        R_CRIS_GNU_VTINHERIT = 7,
        R_CRIS_GNU_VTENTRY = 8,
        R_CRIS_COPY = 9,
        R_CRIS_GLOB_DAT = 10,
        R_CRIS_JUMP_SLOT = 11,
        R_CRIS_RELATIVE = 12,
        R_CRIS_16_GOT = 13,
        R_CRIS_32_GOT = 14,
        R_CRIS_16_GOTPLT = 15,
        R_CRIS_32_GOTPLT = 16,
        R_CRIS_32_GOTREL = 17,
        R_CRIS_32_PLT_GOTREL = 18,
        R_CRIS_32_PLT_PCREL = 19,
    };
}

names! {
    struct X86_64(Base);
    /// `Rel*::r_type` values for `EM_X86_64`.
    consts r = pub NAMES_R_X86_64: RelocationType(u32) = {
        /// No reloc
        R_X86_64_NONE = 0,
        /// Direct 64 bit
        R_X86_64_64 = 1,
        /// PC relative 32 bit signed
        R_X86_64_PC32 = 2,
        /// 32 bit GOT entry
        R_X86_64_GOT32 = 3,
        /// 32 bit PLT address
        R_X86_64_PLT32 = 4,
        /// Copy symbol at runtime
        R_X86_64_COPY = 5,
        /// Create GOT entry
        R_X86_64_GLOB_DAT = 6,
        /// Create PLT entry
        R_X86_64_JUMP_SLOT = 7,
        /// Adjust by program base
        R_X86_64_RELATIVE = 8,
        /// 32 bit signed PC relative offset to GOT
        R_X86_64_GOTPCREL = 9,
        /// Direct 32 bit zero extended
        R_X86_64_32 = 10,
        /// Direct 32 bit sign extended
        R_X86_64_32S = 11,
        /// Direct 16 bit zero extended
        R_X86_64_16 = 12,
        /// 16 bit sign extended pc relative
        R_X86_64_PC16 = 13,
        /// Direct 8 bit sign extended
        R_X86_64_8 = 14,
        /// 8 bit sign extended pc relative
        R_X86_64_PC8 = 15,
        /// ID of module containing symbol
        R_X86_64_DTPMOD64 = 16,
        /// Offset in module's TLS block
        R_X86_64_DTPOFF64 = 17,
        /// Offset in initial TLS block
        R_X86_64_TPOFF64 = 18,
        /// 32 bit signed PC relative offset to two GOT entries for GD symbol
        R_X86_64_TLSGD = 19,
        /// 32 bit signed PC relative offset to two GOT entries for LD symbol
        R_X86_64_TLSLD = 20,
        /// Offset in TLS block
        R_X86_64_DTPOFF32 = 21,
        /// 32 bit signed PC relative offset to GOT entry for IE symbol
        R_X86_64_GOTTPOFF = 22,
        /// Offset in initial TLS block
        R_X86_64_TPOFF32 = 23,
        /// PC relative 64 bit
        R_X86_64_PC64 = 24,
        /// 64 bit offset to GOT
        R_X86_64_GOTOFF64 = 25,
        /// 32 bit signed pc relative offset to GOT
        R_X86_64_GOTPC32 = 26,
        /// 64-bit GOT entry offset
        R_X86_64_GOT64 = 27,
        /// 64-bit PC relative offset to GOT entry
        R_X86_64_GOTPCREL64 = 28,
        /// 64-bit PC relative offset to GOT
        R_X86_64_GOTPC64 = 29,
        /// like GOT64, says PLT entry needed
        R_X86_64_GOTPLT64 = 30,
        /// 64-bit GOT relative offset to PLT entry
        R_X86_64_PLTOFF64 = 31,
        /// Size of symbol plus 32-bit addend
        R_X86_64_SIZE32 = 32,
        /// Size of symbol plus 64-bit addend
        R_X86_64_SIZE64 = 33,
        /// GOT offset for TLS descriptor.
        R_X86_64_GOTPC32_TLSDESC = 34,
        /// Marker for call through TLS descriptor.
        R_X86_64_TLSDESC_CALL = 35,
        /// TLS descriptor.
        R_X86_64_TLSDESC = 36,
        /// Adjust indirectly by program base
        R_X86_64_IRELATIVE = 37,
        /// 64-bit adjust by program base
        R_X86_64_RELATIVE64 = 38,
        // 39 Reserved was R_X86_64_PC32_BND
        // 40 Reserved was R_X86_64_PLT32_BND
        /// Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable.
        R_X86_64_GOTPCRELX = 41,
        /// Load from 32 bit signed pc relative offset to GOT entry with REX prefix, relaxable.
        R_X86_64_REX_GOTPCRELX = 42,
        /// 32 bit signed PC relative offset to GOT if the instruction starts at 4 bytes before the relocation offset, relaxable.
        R_X86_64_CODE_4_GOTPCRELX = 43,
        /// 32 bit signed PC relative offset to GOT entry for IE symbol if the instruction starts at 4 bytes before the relocation offset.
        R_X86_64_CODE_4_GOTTPOFF = 44,
        /// 32-bit PC relative to TLS descriptor in GOT if the instruction starts at 4 bytes before the relocation offset.
        R_X86_64_CODE_4_GOTPC32_TLSDESC = 45,
        /// 32 bit signed PC relative offset to GOT if the instruction starts at 5 bytes before the relocation offset, relaxable.
        R_X86_64_CODE_5_GOTPCRELX = 46,
        /// 32 bit signed PC relative offset to GOT entry for IE symbol if the instruction starts at 5 bytes before the relocation offset.
        R_X86_64_CODE_5_GOTTPOFF = 47,
        /// 32-bit PC relative to TLS descriptor in GOT if the instruction starts at 5 bytes before the relocation offset.
        R_X86_64_CODE_5_GOTPC32_TLSDESC = 48,
        /// 32 bit signed PC relative offset to GOT if the instruction starts at 6 bytes before the relocation offset, relaxable.
        R_X86_64_CODE_6_GOTPCRELX = 49,
        /// 32 bit signed PC relative offset to GOT entry for IE symbol if the instruction starts at 6 bytes before the relocation offset.
        R_X86_64_CODE_6_GOTTPOFF = 50,
        /// 32-bit PC relative to TLS descriptor in GOT if the instruction starts at 6 bytes before the relocation offset.
        R_X86_64_CODE_6_GOTPC32_TLSDESC = 51,
    };
    consts sht: SectionType(u32) = {
        /// Unwind information.
        SHT_X86_64_UNWIND = 0x7000_0001,
    };
}

names! {
    struct Mn10300(Base);
    /// `Rel*::r_type` values for `EM_MN10300`.
    consts r = pub NAMES_R_MN10300: RelocationType(u32) = {
        /// No reloc.
        R_MN10300_NONE = 0,
        /// Direct 32 bit.
        R_MN10300_32 = 1,
        /// Direct 16 bit.
        R_MN10300_16 = 2,
        /// Direct 8 bit.
        R_MN10300_8 = 3,
        /// PC-relative 32-bit.
        R_MN10300_PCREL32 = 4,
        /// PC-relative 16-bit signed.
        R_MN10300_PCREL16 = 5,
        /// PC-relative 8-bit signed.
        R_MN10300_PCREL8 = 6,
        /// Ancient C++ vtable garbage...
        R_MN10300_GNU_VTINHERIT = 7,
        /// ... collection annotation.
        R_MN10300_GNU_VTENTRY = 8,
        /// Direct 24 bit.
        R_MN10300_24 = 9,
        /// 32-bit PCrel offset to GOT.
        R_MN10300_GOTPC32 = 10,
        /// 16-bit PCrel offset to GOT.
        R_MN10300_GOTPC16 = 11,
        /// 32-bit offset from GOT.
        R_MN10300_GOTOFF32 = 12,
        /// 24-bit offset from GOT.
        R_MN10300_GOTOFF24 = 13,
        /// 16-bit offset from GOT.
        R_MN10300_GOTOFF16 = 14,
        /// 32-bit PCrel to PLT entry.
        R_MN10300_PLT32 = 15,
        /// 16-bit PCrel to PLT entry.
        R_MN10300_PLT16 = 16,
        /// 32-bit offset to GOT entry.
        R_MN10300_GOT32 = 17,
        /// 24-bit offset to GOT entry.
        R_MN10300_GOT24 = 18,
        /// 16-bit offset to GOT entry.
        R_MN10300_GOT16 = 19,
        /// Copy symbol at runtime.
        R_MN10300_COPY = 20,
        /// Create GOT entry.
        R_MN10300_GLOB_DAT = 21,
        /// Create PLT entry.
        R_MN10300_JMP_SLOT = 22,
        /// Adjust by program base.
        R_MN10300_RELATIVE = 23,
        /// 32-bit offset for global dynamic.
        R_MN10300_TLS_GD = 24,
        /// 32-bit offset for local dynamic.
        R_MN10300_TLS_LD = 25,
        /// Module-relative offset.
        R_MN10300_TLS_LDO = 26,
        /// GOT offset for static TLS block offset.
        R_MN10300_TLS_GOTIE = 27,
        /// GOT address for static TLS block offset.
        R_MN10300_TLS_IE = 28,
        /// Offset relative to static TLS block.
        R_MN10300_TLS_LE = 29,
        /// ID of module containing symbol.
        R_MN10300_TLS_DTPMOD = 30,
        /// Offset in module TLS block.
        R_MN10300_TLS_DTPOFF = 31,
        /// Offset in static TLS block.
        R_MN10300_TLS_TPOFF = 32,
        /// Adjustment for next reloc as needed by linker relaxation.
        R_MN10300_SYM_DIFF = 33,
        /// Alignment requirement for linker relaxation.
        R_MN10300_ALIGN = 34,
    };
}

names! {
    struct M32r(Base);
    /// `Rel*::r_type` values for `EM_M32R`.
    consts r = pub NAMES_R_M32R: RelocationType(u32) = {
        /// No reloc.
        R_M32R_NONE = 0,
        /// Direct 16 bit.
        R_M32R_16 = 1,
        /// Direct 32 bit.
        R_M32R_32 = 2,
        /// Direct 24 bit.
        R_M32R_24 = 3,
        /// PC relative 10 bit shifted.
        R_M32R_10_PCREL = 4,
        /// PC relative 18 bit shifted.
        R_M32R_18_PCREL = 5,
        /// PC relative 26 bit shifted.
        R_M32R_26_PCREL = 6,
        /// High 16 bit with unsigned low.
        R_M32R_HI16_ULO = 7,
        /// High 16 bit with signed low.
        R_M32R_HI16_SLO = 8,
        /// Low 16 bit.
        R_M32R_LO16 = 9,
        /// 16 bit offset in SDA.
        R_M32R_SDA16 = 10,
        R_M32R_GNU_VTINHERIT = 11,
        R_M32R_GNU_VTENTRY = 12,
        // M32R values `Rela32::r_type`.
        /// Direct 16 bit.
        R_M32R_16_RELA = 33,
        /// Direct 32 bit.
        R_M32R_32_RELA = 34,
        /// Direct 24 bit.
        R_M32R_24_RELA = 35,
        /// PC relative 10 bit shifted.
        R_M32R_10_PCREL_RELA = 36,
        /// PC relative 18 bit shifted.
        R_M32R_18_PCREL_RELA = 37,
        /// PC relative 26 bit shifted.
        R_M32R_26_PCREL_RELA = 38,
        /// High 16 bit with unsigned low
        R_M32R_HI16_ULO_RELA = 39,
        /// High 16 bit with signed low
        R_M32R_HI16_SLO_RELA = 40,
        /// Low 16 bit
        R_M32R_LO16_RELA = 41,
        /// 16 bit offset in SDA
        R_M32R_SDA16_RELA = 42,
        R_M32R_RELA_GNU_VTINHERIT = 43,
        R_M32R_RELA_GNU_VTENTRY = 44,
        /// PC relative 32 bit.
        R_M32R_REL32 = 45,

        /// 24 bit GOT entry
        R_M32R_GOT24 = 48,
        /// 26 bit PC relative to PLT shifted
        R_M32R_26_PLTREL = 49,
        /// Copy symbol at runtime
        R_M32R_COPY = 50,
        /// Create GOT entry
        R_M32R_GLOB_DAT = 51,
        /// Create PLT entry
        R_M32R_JMP_SLOT = 52,
        /// Adjust by program base
        R_M32R_RELATIVE = 53,
        /// 24 bit offset to GOT
        R_M32R_GOTOFF = 54,
        /// 24 bit PC relative offset to GOT
        R_M32R_GOTPC24 = 55,
        /// High 16 bit GOT entry with unsigned low
        R_M32R_GOT16_HI_ULO = 56,
        /// High 16 bit GOT entry with signed low
        R_M32R_GOT16_HI_SLO = 57,
        /// Low 16 bit GOT entry
        R_M32R_GOT16_LO = 58,
        /// High 16 bit PC relative offset to GOT with unsigned low
        R_M32R_GOTPC_HI_ULO = 59,
        /// High 16 bit PC relative offset to GOT with signed low
        R_M32R_GOTPC_HI_SLO = 60,
        /// Low 16 bit PC relative offset to GOT
        R_M32R_GOTPC_LO = 61,
        /// High 16 bit offset to GOT with unsigned low
        R_M32R_GOTOFF_HI_ULO = 62,
        /// High 16 bit offset to GOT with signed low
        R_M32R_GOTOFF_HI_SLO = 63,
        /// Low 16 bit offset to GOT
        R_M32R_GOTOFF_LO = 64,
        /// Keep this the last entry.
        R_M32R_NUM = 256,
    };
}

names! {
    struct Microblaze(Base);
    /// `Rel*::r_type` values for `EM_MICROBLAZE`.
    consts r = pub NAMES_R_MICROBLAZE: RelocationType(u32) = {
        /// No reloc.
        R_MICROBLAZE_NONE = 0,
        /// Direct 32 bit.
        R_MICROBLAZE_32 = 1,
        /// PC relative 32 bit.
        R_MICROBLAZE_32_PCREL = 2,
        /// PC relative 64 bit.
        R_MICROBLAZE_64_PCREL = 3,
        /// Low 16 bits of PCREL32.
        R_MICROBLAZE_32_PCREL_LO = 4,
        /// Direct 64 bit.
        R_MICROBLAZE_64 = 5,
        /// Low 16 bit.
        R_MICROBLAZE_32_LO = 6,
        /// Read-only small data area.
        R_MICROBLAZE_SRO32 = 7,
        /// Read-write small data area.
        R_MICROBLAZE_SRW32 = 8,
        /// No reloc.
        R_MICROBLAZE_64_NONE = 9,
        /// Symbol Op Symbol relocation.
        R_MICROBLAZE_32_SYM_OP_SYM = 10,
        /// GNU C++ vtable hierarchy.
        R_MICROBLAZE_GNU_VTINHERIT = 11,
        /// GNU C++ vtable member usage.
        R_MICROBLAZE_GNU_VTENTRY = 12,
        /// PC-relative GOT offset.
        R_MICROBLAZE_GOTPC_64 = 13,
        /// GOT entry offset.
        R_MICROBLAZE_GOT_64 = 14,
        /// PLT offset (PC-relative).
        R_MICROBLAZE_PLT_64 = 15,
        /// Adjust by program base.
        R_MICROBLAZE_REL = 16,
        /// Create PLT entry.
        R_MICROBLAZE_JUMP_SLOT = 17,
        /// Create GOT entry.
        R_MICROBLAZE_GLOB_DAT = 18,
        /// 64 bit offset to GOT.
        R_MICROBLAZE_GOTOFF_64 = 19,
        /// 32 bit offset to GOT.
        R_MICROBLAZE_GOTOFF_32 = 20,
        /// Runtime copy.
        R_MICROBLAZE_COPY = 21,
        /// TLS Reloc.
        R_MICROBLAZE_TLS = 22,
        /// TLS General Dynamic.
        R_MICROBLAZE_TLSGD = 23,
        /// TLS Local Dynamic.
        R_MICROBLAZE_TLSLD = 24,
        /// TLS Module ID.
        R_MICROBLAZE_TLSDTPMOD32 = 25,
        /// TLS Offset Within TLS Block.
        R_MICROBLAZE_TLSDTPREL32 = 26,
        /// TLS Offset Within TLS Block.
        R_MICROBLAZE_TLSDTPREL64 = 27,
        /// TLS Offset From Thread Pointer.
        R_MICROBLAZE_TLSGOTTPREL32 = 28,
        /// TLS Offset From Thread Pointer.
        R_MICROBLAZE_TLSTPREL32 = 29,
    };
}

// Nios II
names! {
    struct Nios2(Base);
    consts dt: DynamicTag(i64) = {
        /// Address of _gp.
        DT_NIOS2_GP = 0x7000_0002,
    };
    /// `Rel*::r_type` values for `EM_ALTERA_NIOS2`.
    consts r = pub NAMES_R_NIOS2: RelocationType(u32) = {
        /// No reloc.
        R_NIOS2_NONE = 0,
        /// Direct signed 16 bit.
        R_NIOS2_S16 = 1,
        /// Direct unsigned 16 bit.
        R_NIOS2_U16 = 2,
        /// PC relative 16 bit.
        R_NIOS2_PCREL16 = 3,
        /// Direct call.
        R_NIOS2_CALL26 = 4,
        /// 5 bit constant expression.
        R_NIOS2_IMM5 = 5,
        /// 5 bit expression, shift 22.
        R_NIOS2_CACHE_OPX = 6,
        /// 6 bit constant expression.
        R_NIOS2_IMM6 = 7,
        /// 8 bit constant expression.
        R_NIOS2_IMM8 = 8,
        /// High 16 bit.
        R_NIOS2_HI16 = 9,
        /// Low 16 bit.
        R_NIOS2_LO16 = 10,
        /// High 16 bit, adjusted.
        R_NIOS2_HIADJ16 = 11,
        /// 32 bit symbol value + addend.
        R_NIOS2_BFD_RELOC_32 = 12,
        /// 16 bit symbol value + addend.
        R_NIOS2_BFD_RELOC_16 = 13,
        /// 8 bit symbol value + addend.
        R_NIOS2_BFD_RELOC_8 = 14,
        /// 16 bit GP pointer offset.
        R_NIOS2_GPREL = 15,
        /// GNU C++ vtable hierarchy.
        R_NIOS2_GNU_VTINHERIT = 16,
        /// GNU C++ vtable member usage.
        R_NIOS2_GNU_VTENTRY = 17,
        /// Unconditional branch.
        R_NIOS2_UJMP = 18,
        /// Conditional branch.
        R_NIOS2_CJMP = 19,
        /// Indirect call through register.
        R_NIOS2_CALLR = 20,
        /// Alignment requirement for linker relaxation.
        R_NIOS2_ALIGN = 21,
        /// 16 bit GOT entry.
        R_NIOS2_GOT16 = 22,
        /// 16 bit GOT entry for function.
        R_NIOS2_CALL16 = 23,
        /// %lo of offset to GOT pointer.
        R_NIOS2_GOTOFF_LO = 24,
        /// %hiadj of offset to GOT pointer.
        R_NIOS2_GOTOFF_HA = 25,
        /// %lo of PC relative offset.
        R_NIOS2_PCREL_LO = 26,
        /// %hiadj of PC relative offset.
        R_NIOS2_PCREL_HA = 27,
        /// 16 bit GOT offset for TLS GD.
        R_NIOS2_TLS_GD16 = 28,
        /// 16 bit GOT offset for TLS LDM.
        R_NIOS2_TLS_LDM16 = 29,
        /// 16 bit module relative offset.
        R_NIOS2_TLS_LDO16 = 30,
        /// 16 bit GOT offset for TLS IE.
        R_NIOS2_TLS_IE16 = 31,
        /// 16 bit LE TP-relative offset.
        R_NIOS2_TLS_LE16 = 32,
        /// Module number.
        R_NIOS2_TLS_DTPMOD = 33,
        /// Module-relative offset.
        R_NIOS2_TLS_DTPREL = 34,
        /// TP-relative offset.
        R_NIOS2_TLS_TPREL = 35,
        /// Copy symbol at runtime.
        R_NIOS2_COPY = 36,
        /// Create GOT entry.
        R_NIOS2_GLOB_DAT = 37,
        /// Create PLT entry.
        R_NIOS2_JUMP_SLOT = 38,
        /// Adjust by program base.
        R_NIOS2_RELATIVE = 39,
        /// 16 bit offset to GOT pointer.
        R_NIOS2_GOTOFF = 40,
        /// Direct call in .noat section.
        R_NIOS2_CALL26_NOAT = 41,
        /// %lo() of GOT entry.
        R_NIOS2_GOT_LO = 42,
        /// %hiadj() of GOT entry.
        R_NIOS2_GOT_HA = 43,
        /// %lo() of function GOT entry.
        R_NIOS2_CALL_LO = 44,
        /// %hiadj() of function GOT entry.
        R_NIOS2_CALL_HA = 45,
    };
}

// TILEPro
names! {
    struct Tilepro(Base);
    /// `Rel*::r_type` values for `EM_TILEPRO`.
    consts r = pub NAMES_R_TILEPRO: RelocationType(u32) = {
        /// No reloc
        R_TILEPRO_NONE = 0,
        /// Direct 32 bit
        R_TILEPRO_32 = 1,
        /// Direct 16 bit
        R_TILEPRO_16 = 2,
        /// Direct 8 bit
        R_TILEPRO_8 = 3,
        /// PC relative 32 bit
        R_TILEPRO_32_PCREL = 4,
        /// PC relative 16 bit
        R_TILEPRO_16_PCREL = 5,
        /// PC relative 8 bit
        R_TILEPRO_8_PCREL = 6,
        /// Low 16 bit
        R_TILEPRO_LO16 = 7,
        /// High 16 bit
        R_TILEPRO_HI16 = 8,
        /// High 16 bit, adjusted
        R_TILEPRO_HA16 = 9,
        /// Copy relocation
        R_TILEPRO_COPY = 10,
        /// Create GOT entry
        R_TILEPRO_GLOB_DAT = 11,
        /// Create PLT entry
        R_TILEPRO_JMP_SLOT = 12,
        /// Adjust by program base
        R_TILEPRO_RELATIVE = 13,
        /// X1 pipe branch offset
        R_TILEPRO_BROFF_X1 = 14,
        /// X1 pipe jump offset
        R_TILEPRO_JOFFLONG_X1 = 15,
        /// X1 pipe jump offset to PLT
        R_TILEPRO_JOFFLONG_X1_PLT = 16,
        /// X0 pipe 8-bit
        R_TILEPRO_IMM8_X0 = 17,
        /// Y0 pipe 8-bit
        R_TILEPRO_IMM8_Y0 = 18,
        /// X1 pipe 8-bit
        R_TILEPRO_IMM8_X1 = 19,
        /// Y1 pipe 8-bit
        R_TILEPRO_IMM8_Y1 = 20,
        /// X1 pipe mtspr
        R_TILEPRO_MT_IMM15_X1 = 21,
        /// X1 pipe mfspr
        R_TILEPRO_MF_IMM15_X1 = 22,
        /// X0 pipe 16-bit
        R_TILEPRO_IMM16_X0 = 23,
        /// X1 pipe 16-bit
        R_TILEPRO_IMM16_X1 = 24,
        /// X0 pipe low 16-bit
        R_TILEPRO_IMM16_X0_LO = 25,
        /// X1 pipe low 16-bit
        R_TILEPRO_IMM16_X1_LO = 26,
        /// X0 pipe high 16-bit
        R_TILEPRO_IMM16_X0_HI = 27,
        /// X1 pipe high 16-bit
        R_TILEPRO_IMM16_X1_HI = 28,
        /// X0 pipe high 16-bit, adjusted
        R_TILEPRO_IMM16_X0_HA = 29,
        /// X1 pipe high 16-bit, adjusted
        R_TILEPRO_IMM16_X1_HA = 30,
        /// X0 pipe PC relative 16 bit
        R_TILEPRO_IMM16_X0_PCREL = 31,
        /// X1 pipe PC relative 16 bit
        R_TILEPRO_IMM16_X1_PCREL = 32,
        /// X0 pipe PC relative low 16 bit
        R_TILEPRO_IMM16_X0_LO_PCREL = 33,
        /// X1 pipe PC relative low 16 bit
        R_TILEPRO_IMM16_X1_LO_PCREL = 34,
        /// X0 pipe PC relative high 16 bit
        R_TILEPRO_IMM16_X0_HI_PCREL = 35,
        /// X1 pipe PC relative high 16 bit
        R_TILEPRO_IMM16_X1_HI_PCREL = 36,
        /// X0 pipe PC relative ha() 16 bit
        R_TILEPRO_IMM16_X0_HA_PCREL = 37,
        /// X1 pipe PC relative ha() 16 bit
        R_TILEPRO_IMM16_X1_HA_PCREL = 38,
        /// X0 pipe 16-bit GOT offset
        R_TILEPRO_IMM16_X0_GOT = 39,
        /// X1 pipe 16-bit GOT offset
        R_TILEPRO_IMM16_X1_GOT = 40,
        /// X0 pipe low 16-bit GOT offset
        R_TILEPRO_IMM16_X0_GOT_LO = 41,
        /// X1 pipe low 16-bit GOT offset
        R_TILEPRO_IMM16_X1_GOT_LO = 42,
        /// X0 pipe high 16-bit GOT offset
        R_TILEPRO_IMM16_X0_GOT_HI = 43,
        /// X1 pipe high 16-bit GOT offset
        R_TILEPRO_IMM16_X1_GOT_HI = 44,
        /// X0 pipe ha() 16-bit GOT offset
        R_TILEPRO_IMM16_X0_GOT_HA = 45,
        /// X1 pipe ha() 16-bit GOT offset
        R_TILEPRO_IMM16_X1_GOT_HA = 46,
        /// X0 pipe mm "start"
        R_TILEPRO_MMSTART_X0 = 47,
        /// X0 pipe mm "end"
        R_TILEPRO_MMEND_X0 = 48,
        /// X1 pipe mm "start"
        R_TILEPRO_MMSTART_X1 = 49,
        /// X1 pipe mm "end"
        R_TILEPRO_MMEND_X1 = 50,
        /// X0 pipe shift amount
        R_TILEPRO_SHAMT_X0 = 51,
        /// X1 pipe shift amount
        R_TILEPRO_SHAMT_X1 = 52,
        /// Y0 pipe shift amount
        R_TILEPRO_SHAMT_Y0 = 53,
        /// Y1 pipe shift amount
        R_TILEPRO_SHAMT_Y1 = 54,
        /// X1 pipe destination 8-bit
        R_TILEPRO_DEST_IMM8_X1 = 55,
        // Relocs 56-59 are currently not defined.
        /// "jal" for TLS GD
        R_TILEPRO_TLS_GD_CALL = 60,
        /// X0 pipe "addi" for TLS GD
        R_TILEPRO_IMM8_X0_TLS_GD_ADD = 61,
        /// X1 pipe "addi" for TLS GD
        R_TILEPRO_IMM8_X1_TLS_GD_ADD = 62,
        /// Y0 pipe "addi" for TLS GD
        R_TILEPRO_IMM8_Y0_TLS_GD_ADD = 63,
        /// Y1 pipe "addi" for TLS GD
        R_TILEPRO_IMM8_Y1_TLS_GD_ADD = 64,
        /// "lw_tls" for TLS IE
        R_TILEPRO_TLS_IE_LOAD = 65,
        /// X0 pipe 16-bit TLS GD offset
        R_TILEPRO_IMM16_X0_TLS_GD = 66,
        /// X1 pipe 16-bit TLS GD offset
        R_TILEPRO_IMM16_X1_TLS_GD = 67,
        /// X0 pipe low 16-bit TLS GD offset
        R_TILEPRO_IMM16_X0_TLS_GD_LO = 68,
        /// X1 pipe low 16-bit TLS GD offset
        R_TILEPRO_IMM16_X1_TLS_GD_LO = 69,
        /// X0 pipe high 16-bit TLS GD offset
        R_TILEPRO_IMM16_X0_TLS_GD_HI = 70,
        /// X1 pipe high 16-bit TLS GD offset
        R_TILEPRO_IMM16_X1_TLS_GD_HI = 71,
        /// X0 pipe ha() 16-bit TLS GD offset
        R_TILEPRO_IMM16_X0_TLS_GD_HA = 72,
        /// X1 pipe ha() 16-bit TLS GD offset
        R_TILEPRO_IMM16_X1_TLS_GD_HA = 73,
        /// X0 pipe 16-bit TLS IE offset
        R_TILEPRO_IMM16_X0_TLS_IE = 74,
        /// X1 pipe 16-bit TLS IE offset
        R_TILEPRO_IMM16_X1_TLS_IE = 75,
        /// X0 pipe low 16-bit TLS IE offset
        R_TILEPRO_IMM16_X0_TLS_IE_LO = 76,
        /// X1 pipe low 16-bit TLS IE offset
        R_TILEPRO_IMM16_X1_TLS_IE_LO = 77,
        /// X0 pipe high 16-bit TLS IE offset
        R_TILEPRO_IMM16_X0_TLS_IE_HI = 78,
        /// X1 pipe high 16-bit TLS IE offset
        R_TILEPRO_IMM16_X1_TLS_IE_HI = 79,
        /// X0 pipe ha() 16-bit TLS IE offset
        R_TILEPRO_IMM16_X0_TLS_IE_HA = 80,
        /// X1 pipe ha() 16-bit TLS IE offset
        R_TILEPRO_IMM16_X1_TLS_IE_HA = 81,
        /// ID of module containing symbol
        R_TILEPRO_TLS_DTPMOD32 = 82,
        /// Offset in TLS block
        R_TILEPRO_TLS_DTPOFF32 = 83,
        /// Offset in static TLS block
        R_TILEPRO_TLS_TPOFF32 = 84,
        /// X0 pipe 16-bit TLS LE offset
        R_TILEPRO_IMM16_X0_TLS_LE = 85,
        /// X1 pipe 16-bit TLS LE offset
        R_TILEPRO_IMM16_X1_TLS_LE = 86,
        /// X0 pipe low 16-bit TLS LE offset
        R_TILEPRO_IMM16_X0_TLS_LE_LO = 87,
        /// X1 pipe low 16-bit TLS LE offset
        R_TILEPRO_IMM16_X1_TLS_LE_LO = 88,
        /// X0 pipe high 16-bit TLS LE offset
        R_TILEPRO_IMM16_X0_TLS_LE_HI = 89,
        /// X1 pipe high 16-bit TLS LE offset
        R_TILEPRO_IMM16_X1_TLS_LE_HI = 90,
        /// X0 pipe ha() 16-bit TLS LE offset
        R_TILEPRO_IMM16_X0_TLS_LE_HA = 91,
        /// X1 pipe ha() 16-bit TLS LE offset
        R_TILEPRO_IMM16_X1_TLS_LE_HA = 92,

        /// GNU C++ vtable hierarchy
        R_TILEPRO_GNU_VTINHERIT = 128,
        /// GNU C++ vtable member usage
        R_TILEPRO_GNU_VTENTRY = 129,
    };
}

// TILE-Gx
names! {
    struct Tilegx(Base);
    /// `Rel*::r_type` values for `EM_TILEGX`.
    consts r = pub NAMES_R_TILEGX: RelocationType(u32) = {
        /// No reloc
        R_TILEGX_NONE = 0,
        /// Direct 64 bit
        R_TILEGX_64 = 1,
        /// Direct 32 bit
        R_TILEGX_32 = 2,
        /// Direct 16 bit
        R_TILEGX_16 = 3,
        /// Direct 8 bit
        R_TILEGX_8 = 4,
        /// PC relative 64 bit
        R_TILEGX_64_PCREL = 5,
        /// PC relative 32 bit
        R_TILEGX_32_PCREL = 6,
        /// PC relative 16 bit
        R_TILEGX_16_PCREL = 7,
        /// PC relative 8 bit
        R_TILEGX_8_PCREL = 8,
        /// hword 0 16-bit
        R_TILEGX_HW0 = 9,
        /// hword 1 16-bit
        R_TILEGX_HW1 = 10,
        /// hword 2 16-bit
        R_TILEGX_HW2 = 11,
        /// hword 3 16-bit
        R_TILEGX_HW3 = 12,
        /// last hword 0 16-bit
        R_TILEGX_HW0_LAST = 13,
        /// last hword 1 16-bit
        R_TILEGX_HW1_LAST = 14,
        /// last hword 2 16-bit
        R_TILEGX_HW2_LAST = 15,
        /// Copy relocation
        R_TILEGX_COPY = 16,
        /// Create GOT entry
        R_TILEGX_GLOB_DAT = 17,
        /// Create PLT entry
        R_TILEGX_JMP_SLOT = 18,
        /// Adjust by program base
        R_TILEGX_RELATIVE = 19,
        /// X1 pipe branch offset
        R_TILEGX_BROFF_X1 = 20,
        /// X1 pipe jump offset
        R_TILEGX_JUMPOFF_X1 = 21,
        /// X1 pipe jump offset to PLT
        R_TILEGX_JUMPOFF_X1_PLT = 22,
        /// X0 pipe 8-bit
        R_TILEGX_IMM8_X0 = 23,
        /// Y0 pipe 8-bit
        R_TILEGX_IMM8_Y0 = 24,
        /// X1 pipe 8-bit
        R_TILEGX_IMM8_X1 = 25,
        /// Y1 pipe 8-bit
        R_TILEGX_IMM8_Y1 = 26,
        /// X1 pipe destination 8-bit
        R_TILEGX_DEST_IMM8_X1 = 27,
        /// X1 pipe mtspr
        R_TILEGX_MT_IMM14_X1 = 28,
        /// X1 pipe mfspr
        R_TILEGX_MF_IMM14_X1 = 29,
        /// X0 pipe mm "start"
        R_TILEGX_MMSTART_X0 = 30,
        /// X0 pipe mm "end"
        R_TILEGX_MMEND_X0 = 31,
        /// X0 pipe shift amount
        R_TILEGX_SHAMT_X0 = 32,
        /// X1 pipe shift amount
        R_TILEGX_SHAMT_X1 = 33,
        /// Y0 pipe shift amount
        R_TILEGX_SHAMT_Y0 = 34,
        /// Y1 pipe shift amount
        R_TILEGX_SHAMT_Y1 = 35,
        /// X0 pipe hword 0
        R_TILEGX_IMM16_X0_HW0 = 36,
        /// X1 pipe hword 0
        R_TILEGX_IMM16_X1_HW0 = 37,
        /// X0 pipe hword 1
        R_TILEGX_IMM16_X0_HW1 = 38,
        /// X1 pipe hword 1
        R_TILEGX_IMM16_X1_HW1 = 39,
        /// X0 pipe hword 2
        R_TILEGX_IMM16_X0_HW2 = 40,
        /// X1 pipe hword 2
        R_TILEGX_IMM16_X1_HW2 = 41,
        /// X0 pipe hword 3
        R_TILEGX_IMM16_X0_HW3 = 42,
        /// X1 pipe hword 3
        R_TILEGX_IMM16_X1_HW3 = 43,
        /// X0 pipe last hword 0
        R_TILEGX_IMM16_X0_HW0_LAST = 44,
        /// X1 pipe last hword 0
        R_TILEGX_IMM16_X1_HW0_LAST = 45,
        /// X0 pipe last hword 1
        R_TILEGX_IMM16_X0_HW1_LAST = 46,
        /// X1 pipe last hword 1
        R_TILEGX_IMM16_X1_HW1_LAST = 47,
        /// X0 pipe last hword 2
        R_TILEGX_IMM16_X0_HW2_LAST = 48,
        /// X1 pipe last hword 2
        R_TILEGX_IMM16_X1_HW2_LAST = 49,
        /// X0 pipe PC relative hword 0
        R_TILEGX_IMM16_X0_HW0_PCREL = 50,
        /// X1 pipe PC relative hword 0
        R_TILEGX_IMM16_X1_HW0_PCREL = 51,
        /// X0 pipe PC relative hword 1
        R_TILEGX_IMM16_X0_HW1_PCREL = 52,
        /// X1 pipe PC relative hword 1
        R_TILEGX_IMM16_X1_HW1_PCREL = 53,
        /// X0 pipe PC relative hword 2
        R_TILEGX_IMM16_X0_HW2_PCREL = 54,
        /// X1 pipe PC relative hword 2
        R_TILEGX_IMM16_X1_HW2_PCREL = 55,
        /// X0 pipe PC relative hword 3
        R_TILEGX_IMM16_X0_HW3_PCREL = 56,
        /// X1 pipe PC relative hword 3
        R_TILEGX_IMM16_X1_HW3_PCREL = 57,
        /// X0 pipe PC-rel last hword 0
        R_TILEGX_IMM16_X0_HW0_LAST_PCREL = 58,
        /// X1 pipe PC-rel last hword 0
        R_TILEGX_IMM16_X1_HW0_LAST_PCREL = 59,
        /// X0 pipe PC-rel last hword 1
        R_TILEGX_IMM16_X0_HW1_LAST_PCREL = 60,
        /// X1 pipe PC-rel last hword 1
        R_TILEGX_IMM16_X1_HW1_LAST_PCREL = 61,
        /// X0 pipe PC-rel last hword 2
        R_TILEGX_IMM16_X0_HW2_LAST_PCREL = 62,
        /// X1 pipe PC-rel last hword 2
        R_TILEGX_IMM16_X1_HW2_LAST_PCREL = 63,
        /// X0 pipe hword 0 GOT offset
        R_TILEGX_IMM16_X0_HW0_GOT = 64,
        /// X1 pipe hword 0 GOT offset
        R_TILEGX_IMM16_X1_HW0_GOT = 65,
        /// X0 pipe PC-rel PLT hword 0
        R_TILEGX_IMM16_X0_HW0_PLT_PCREL = 66,
        /// X1 pipe PC-rel PLT hword 0
        R_TILEGX_IMM16_X1_HW0_PLT_PCREL = 67,
        /// X0 pipe PC-rel PLT hword 1
        R_TILEGX_IMM16_X0_HW1_PLT_PCREL = 68,
        /// X1 pipe PC-rel PLT hword 1
        R_TILEGX_IMM16_X1_HW1_PLT_PCREL = 69,
        /// X0 pipe PC-rel PLT hword 2
        R_TILEGX_IMM16_X0_HW2_PLT_PCREL = 70,
        /// X1 pipe PC-rel PLT hword 2
        R_TILEGX_IMM16_X1_HW2_PLT_PCREL = 71,
        /// X0 pipe last hword 0 GOT offset
        R_TILEGX_IMM16_X0_HW0_LAST_GOT = 72,
        /// X1 pipe last hword 0 GOT offset
        R_TILEGX_IMM16_X1_HW0_LAST_GOT = 73,
        /// X0 pipe last hword 1 GOT offset
        R_TILEGX_IMM16_X0_HW1_LAST_GOT = 74,
        /// X1 pipe last hword 1 GOT offset
        R_TILEGX_IMM16_X1_HW1_LAST_GOT = 75,
        /// X0 pipe PC-rel PLT hword 3
        R_TILEGX_IMM16_X0_HW3_PLT_PCREL = 76,
        /// X1 pipe PC-rel PLT hword 3
        R_TILEGX_IMM16_X1_HW3_PLT_PCREL = 77,
        /// X0 pipe hword 0 TLS GD offset
        R_TILEGX_IMM16_X0_HW0_TLS_GD = 78,
        /// X1 pipe hword 0 TLS GD offset
        R_TILEGX_IMM16_X1_HW0_TLS_GD = 79,
        /// X0 pipe hword 0 TLS LE offset
        R_TILEGX_IMM16_X0_HW0_TLS_LE = 80,
        /// X1 pipe hword 0 TLS LE offset
        R_TILEGX_IMM16_X1_HW0_TLS_LE = 81,
        /// X0 pipe last hword 0 LE off
        R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE = 82,
        /// X1 pipe last hword 0 LE off
        R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE = 83,
        /// X0 pipe last hword 1 LE off
        R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE = 84,
        /// X1 pipe last hword 1 LE off
        R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE = 85,
        /// X0 pipe last hword 0 GD off
        R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD = 86,
        /// X1 pipe last hword 0 GD off
        R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD = 87,
        /// X0 pipe last hword 1 GD off
        R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD = 88,
        /// X1 pipe last hword 1 GD off
        R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD = 89,
        // Relocs 90-91 are currently not defined.
        /// X0 pipe hword 0 TLS IE offset
        R_TILEGX_IMM16_X0_HW0_TLS_IE = 92,
        /// X1 pipe hword 0 TLS IE offset
        R_TILEGX_IMM16_X1_HW0_TLS_IE = 93,
        /// X0 pipe PC-rel PLT last hword 0
        R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL = 94,
        /// X1 pipe PC-rel PLT last hword 0
        R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL = 95,
        /// X0 pipe PC-rel PLT last hword 1
        R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL = 96,
        /// X1 pipe PC-rel PLT last hword 1
        R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL = 97,
        /// X0 pipe PC-rel PLT last hword 2
        R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL = 98,
        /// X1 pipe PC-rel PLT last hword 2
        R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL = 99,
        /// X0 pipe last hword 0 IE off
        R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE = 100,
        /// X1 pipe last hword 0 IE off
        R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE = 101,
        /// X0 pipe last hword 1 IE off
        R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE = 102,
        /// X1 pipe last hword 1 IE off
        R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE = 103,
        // Relocs 104-105 are currently not defined.
        /// 64-bit ID of symbol's module
        R_TILEGX_TLS_DTPMOD64 = 106,
        /// 64-bit offset in TLS block
        R_TILEGX_TLS_DTPOFF64 = 107,
        /// 64-bit offset in static TLS block
        R_TILEGX_TLS_TPOFF64 = 108,
        /// 32-bit ID of symbol's module
        R_TILEGX_TLS_DTPMOD32 = 109,
        /// 32-bit offset in TLS block
        R_TILEGX_TLS_DTPOFF32 = 110,
        /// 32-bit offset in static TLS block
        R_TILEGX_TLS_TPOFF32 = 111,
        /// "jal" for TLS GD
        R_TILEGX_TLS_GD_CALL = 112,
        /// X0 pipe "addi" for TLS GD
        R_TILEGX_IMM8_X0_TLS_GD_ADD = 113,
        /// X1 pipe "addi" for TLS GD
        R_TILEGX_IMM8_X1_TLS_GD_ADD = 114,
        /// Y0 pipe "addi" for TLS GD
        R_TILEGX_IMM8_Y0_TLS_GD_ADD = 115,
        /// Y1 pipe "addi" for TLS GD
        R_TILEGX_IMM8_Y1_TLS_GD_ADD = 116,
        /// "ld_tls" for TLS IE
        R_TILEGX_TLS_IE_LOAD = 117,
        /// X0 pipe "addi" for TLS GD/IE
        R_TILEGX_IMM8_X0_TLS_ADD = 118,
        /// X1 pipe "addi" for TLS GD/IE
        R_TILEGX_IMM8_X1_TLS_ADD = 119,
        /// Y0 pipe "addi" for TLS GD/IE
        R_TILEGX_IMM8_Y0_TLS_ADD = 120,
        /// Y1 pipe "addi" for TLS GD/IE
        R_TILEGX_IMM8_Y1_TLS_ADD = 121,

        /// GNU C++ vtable hierarchy
        R_TILEGX_GNU_VTINHERIT = 128,
        /// GNU C++ vtable member usage
        R_TILEGX_GNU_VTENTRY = 129,
    };
}

names! {
    struct Riscv(Base);
    flags ef: FileFlags(u32) = {
        EF_RISCV_RVC = 0x0001,
        EF_RISCV_FLOAT_ABI = 0x0006 => NAMES_EF_RISCV_FLOAT_ABI,
        EF_RISCV_RVE = 0x0008,
        EF_RISCV_TSO = 0x0010,
        EF_RISCV_RV64ILP32 = 0x0020,
    };
    flags sto: SymbolOther(u8) = {
        /// Function uses variant calling convention.
        STO_RISCV_VARIANT_CC = 0x80,
    };
    consts sht: SectionType(u32) = {
        /// RISC-V attributes section.
        SHT_RISCV_ATTRIBUTES = SHT_LOPROC + 3,
    };
    consts pt: ProgramType(u32) = {
        PT_RISCV_ATTRIBUTES = PT_LOPROC + 3,
    };
    consts dt: DynamicTag(i64) = {
        DT_RISCV_VARIANT_CC = DT_LOPROC + 1,
    };
    /// `Rel*::r_type` values for `EM_RISCV`.
    consts r = pub NAMES_R_RISCV: RelocationType(u32) = {
        R_RISCV_NONE = 0,
        R_RISCV_32 = 1,
        R_RISCV_64 = 2,
        R_RISCV_RELATIVE = 3,
        R_RISCV_COPY = 4,
        R_RISCV_JUMP_SLOT = 5,
        R_RISCV_TLS_DTPMOD32 = 6,
        R_RISCV_TLS_DTPMOD64 = 7,
        R_RISCV_TLS_DTPREL32 = 8,
        R_RISCV_TLS_DTPREL64 = 9,
        R_RISCV_TLS_TPREL32 = 10,
        R_RISCV_TLS_TPREL64 = 11,
        R_RISCV_TLSDESC = 12,
        R_RISCV_BRANCH = 16,
        R_RISCV_JAL = 17,
        R_RISCV_CALL = 18,
        R_RISCV_CALL_PLT = 19,
        R_RISCV_GOT_HI20 = 20,
        R_RISCV_TLS_GOT_HI20 = 21,
        R_RISCV_TLS_GD_HI20 = 22,
        R_RISCV_PCREL_HI20 = 23,
        R_RISCV_PCREL_LO12_I = 24,
        R_RISCV_PCREL_LO12_S = 25,
        R_RISCV_HI20 = 26,
        R_RISCV_LO12_I = 27,
        R_RISCV_LO12_S = 28,
        R_RISCV_TPREL_HI20 = 29,
        R_RISCV_TPREL_LO12_I = 30,
        R_RISCV_TPREL_LO12_S = 31,
        R_RISCV_TPREL_ADD = 32,
        R_RISCV_ADD8 = 33,
        R_RISCV_ADD16 = 34,
        R_RISCV_ADD32 = 35,
        R_RISCV_ADD64 = 36,
        R_RISCV_SUB8 = 37,
        R_RISCV_SUB16 = 38,
        R_RISCV_SUB32 = 39,
        R_RISCV_SUB64 = 40,
        R_RISCV_GOT32_PCREL = 41,
        // 42 Reserved was R_RISCV_GNU_VTENTRY
        R_RISCV_ALIGN = 43,
        R_RISCV_RVC_BRANCH = 44,
        R_RISCV_RVC_JUMP = 45,
        R_RISCV_RVC_LUI = 46,
        R_RISCV_GPREL_I = 47,
        R_RISCV_GPREL_S = 48,
        R_RISCV_TPREL_I = 49,
        R_RISCV_TPREL_S = 50,
        R_RISCV_RELAX = 51,
        R_RISCV_SUB6 = 52,
        R_RISCV_SET6 = 53,
        R_RISCV_SET8 = 54,
        R_RISCV_SET16 = 55,
        R_RISCV_SET32 = 56,
        R_RISCV_32_PCREL = 57,
        R_RISCV_IRELATIVE = 58,
        R_RISCV_PLT32 = 59,
        R_RISCV_SET_ULEB128 = 60,
        R_RISCV_SUB_ULEB128 = 61,
        R_RISCV_TLSDESC_HI20 = 62,
        R_RISCV_TLSDESC_LOAD_LO12 = 63,
        R_RISCV_TLSDESC_ADD_LO12 = 64,
        R_RISCV_TLSDESC_CALL = 65,
    };
}

constant_names!(NAMES_EF_RISCV_FLOAT_ABI: FileFlags(u32) = {
    EF_RISCV_FLOAT_ABI_SOFT = 0x0000,
    EF_RISCV_FLOAT_ABI_SINGLE = 0x0002,
    EF_RISCV_FLOAT_ABI_DOUBLE = 0x0004,
    EF_RISCV_FLOAT_ABI_QUAD = 0x0006,
});

names! {
    struct Bpf(Base);
    /// `Rel*::r_type` values for `EM_BPF`.
    consts r = pub NAMES_R_BPF: RelocationType(u32) = {
        /// No reloc
        R_BPF_NONE = 0,
        R_BPF_64_64 = 1,
        R_BPF_64_32 = 10,
    };
}

names! {
    struct Sbf(Base);
    /// `Rel*::r_type` values for `EM_SBF`.
    consts r = pub NAMES_R_SBF: RelocationType(u32) = {
        /// No reloc
        R_SBF_NONE = 0,
        R_SBF_64_64 = 1,
        R_SBF_64_32 = 10,
    };
}

// Imagination Meta

names! {
    struct Metag(Base);
    /// `Rel*::r_type` values for `EM_METAG`.
    consts r = pub NAMES_R_METAG: RelocationType(u32) = {
        R_METAG_HIADDR16 = 0,
        R_METAG_LOADDR16 = 1,
        /// 32bit absolute address
        R_METAG_ADDR32 = 2,
        /// No reloc
        R_METAG_NONE = 3,
        R_METAG_RELBRANCH = 4,
        R_METAG_GETSETOFF = 5,

        // Backward compatibility
        R_METAG_REG32OP1 = 6,
        R_METAG_REG32OP2 = 7,
        R_METAG_REG32OP3 = 8,
        R_METAG_REG16OP1 = 9,
        R_METAG_REG16OP2 = 10,
        R_METAG_REG16OP3 = 11,
        R_METAG_REG32OP4 = 12,

        R_METAG_HIOG = 13,
        R_METAG_LOOG = 14,

        R_METAG_REL8 = 15,
        R_METAG_REL16 = 16,

        R_METAG_GNU_VTINHERIT = 30,
        R_METAG_GNU_VTENTRY = 31,

        // PIC relocations
        R_METAG_HI16_GOTOFF = 32,
        R_METAG_LO16_GOTOFF = 33,
        R_METAG_GETSET_GOTOFF = 34,
        R_METAG_GETSET_GOT = 35,
        R_METAG_HI16_GOTPC = 36,
        R_METAG_LO16_GOTPC = 37,
        R_METAG_HI16_PLT = 38,
        R_METAG_LO16_PLT = 39,
        R_METAG_RELBRANCH_PLT = 40,
        R_METAG_GOTOFF = 41,
        R_METAG_PLT = 42,
        R_METAG_COPY = 43,
        R_METAG_JMP_SLOT = 44,
        R_METAG_RELATIVE = 45,
        R_METAG_GLOB_DAT = 46,

        // TLS relocations
        R_METAG_TLS_GD = 47,
        R_METAG_TLS_LDM = 48,
        R_METAG_TLS_LDO_HI16 = 49,
        R_METAG_TLS_LDO_LO16 = 50,
        R_METAG_TLS_LDO = 51,
        R_METAG_TLS_IE = 52,
        R_METAG_TLS_IENONPIC = 53,
        R_METAG_TLS_IENONPIC_HI16 = 54,
        R_METAG_TLS_IENONPIC_LO16 = 55,
        R_METAG_TLS_TPOFF = 56,
        R_METAG_TLS_DTPMOD = 57,
        R_METAG_TLS_DTPOFF = 58,
        R_METAG_TLS_LE = 59,
        R_METAG_TLS_LE_HI16 = 60,
        R_METAG_TLS_LE_LO16 = 61,
    };
}

names! {
    struct Nds32(Base);
    /// `Rel*::r_type` values for `EM_NDS32`.
    consts r = pub NAMES_R_NDS32: RelocationType(u32) = {
        R_NDS32_NONE = 0,
        R_NDS32_32_RELA = 20,
        R_NDS32_COPY = 39,
        R_NDS32_GLOB_DAT = 40,
        R_NDS32_JMP_SLOT = 41,
        R_NDS32_RELATIVE = 42,
        R_NDS32_TLS_TPOFF = 102,
        R_NDS32_TLS_DESC = 119,
    };
}

names! {
    struct Larch(Base);
    flags ef: FileFlags(u32) = {
        /// Additional properties of the base ABI type, including the FP calling
        /// convention.
        EF_LARCH_ABI_MODIFIER_MASK = 0x7 => NAMES_EF_LARCH_ABI,
        /// Uses relocation types directly writing to immediate slots
        EF_LARCH_OBJABI_V1 = 0x40,
    };
    /// `Rel*::r_type` values for `EM_LOONGARCH`.
    consts r = pub NAMES_R_LARCH: RelocationType(u32) = {
        /// No reloc
        R_LARCH_NONE = 0,
        /// Runtime address resolving
        R_LARCH_32 = 1,
        /// Runtime address resolving
        R_LARCH_64 = 2,
        /// Runtime fixup for load-address
        R_LARCH_RELATIVE = 3,
        /// Runtime memory copy in executable
        R_LARCH_COPY = 4,
        /// Runtime PLT supporting
        R_LARCH_JUMP_SLOT = 5,
        /// Runtime relocation for TLS-GD
        R_LARCH_TLS_DTPMOD32 = 6,
        /// Runtime relocation for TLS-GD
        R_LARCH_TLS_DTPMOD64 = 7,
        /// Runtime relocation for TLS-GD
        R_LARCH_TLS_DTPREL32 = 8,
        /// Runtime relocation for TLS-GD
        R_LARCH_TLS_DTPREL64 = 9,
        /// Runtime relocation for TLE-IE
        R_LARCH_TLS_TPREL32 = 10,
        /// Runtime relocation for TLE-IE
        R_LARCH_TLS_TPREL64 = 11,
        /// Runtime local indirect function resolving
        R_LARCH_IRELATIVE = 12,
        /// Runtime relocation for TLS descriptors
        R_LARCH_TLS_DESC32 = 13,
        /// Runtime relocation for TLS descriptors
        R_LARCH_TLS_DESC64 = 14,
        /// Mark la.abs: load absolute address for static link.
        R_LARCH_MARK_LA = 20,
        /// Mark external label branch: access PC relative address for static link.
        R_LARCH_MARK_PCREL = 21,
        /// Push PC-relative offset
        R_LARCH_SOP_PUSH_PCREL = 22,
        /// Push constant or absolute address
        R_LARCH_SOP_PUSH_ABSOLUTE = 23,
        /// Duplicate stack top
        R_LARCH_SOP_PUSH_DUP = 24,
        /// Push for access GOT entry
        R_LARCH_SOP_PUSH_GPREL = 25,
        /// Push for TLS-LE
        R_LARCH_SOP_PUSH_TLS_TPREL = 26,
        /// Push for TLS-IE
        R_LARCH_SOP_PUSH_TLS_GOT = 27,
        /// Push for TLS-GD
        R_LARCH_SOP_PUSH_TLS_GD = 28,
        /// Push for external function calling
        R_LARCH_SOP_PUSH_PLT_PCREL = 29,
        /// Assert stack top
        R_LARCH_SOP_ASSERT = 30,
        /// Stack top logical not (unary)
        R_LARCH_SOP_NOT = 31,
        /// Stack top subtraction (binary)
        R_LARCH_SOP_SUB = 32,
        /// Stack top left shift (binary)
        R_LARCH_SOP_SL = 33,
        /// Stack top right shift (binary)
        R_LARCH_SOP_SR = 34,
        /// Stack top addition (binary)
        R_LARCH_SOP_ADD = 35,
        /// Stack top bitwise and (binary)
        R_LARCH_SOP_AND = 36,
        /// Stack top selection (tertiary)
        R_LARCH_SOP_IF_ELSE = 37,
        /// Pop stack top to fill 5-bit signed immediate operand
        R_LARCH_SOP_POP_32_S_10_5 = 38,
        /// Pop stack top to fill 12-bit unsigned immediate operand
        R_LARCH_SOP_POP_32_U_10_12 = 39,
        /// Pop stack top to fill 12-bit signed immediate operand
        R_LARCH_SOP_POP_32_S_10_12 = 40,
        /// Pop stack top to fill 16-bit signed immediate operand
        R_LARCH_SOP_POP_32_S_10_16 = 41,
        /// Pop stack top to fill 18-bit signed immediate operand with two trailing
        /// zeros implied
        R_LARCH_SOP_POP_32_S_10_16_S2 = 42,
        /// Pop stack top to fill 20-bit signed immediate operand
        R_LARCH_SOP_POP_32_S_5_20 = 43,
        /// Pop stack top to fill 23-bit signed immediate operand with two trailing
        /// zeros implied
        R_LARCH_SOP_POP_32_S_0_5_10_16_S2 = 44,
        /// Pop stack top to fill 28-bit signed immediate operand with two trailing
        /// zeros implied
        R_LARCH_SOP_POP_32_S_0_10_10_16_S2 = 45,
        /// Pop stack top to fill an instruction
        R_LARCH_SOP_POP_32_U = 46,
        /// 8-bit in-place addition
        R_LARCH_ADD8 = 47,
        /// 16-bit in-place addition
        R_LARCH_ADD16 = 48,
        /// 24-bit in-place addition
        R_LARCH_ADD24 = 49,
        /// 32-bit in-place addition
        R_LARCH_ADD32 = 50,
        /// 64-bit in-place addition
        R_LARCH_ADD64 = 51,
        /// 8-bit in-place subtraction
        R_LARCH_SUB8 = 52,
        /// 16-bit in-place subtraction
        R_LARCH_SUB16 = 53,
        /// 24-bit in-place subtraction
        R_LARCH_SUB24 = 54,
        /// 32-bit in-place subtraction
        R_LARCH_SUB32 = 55,
        /// 64-bit in-place subtraction
        R_LARCH_SUB64 = 56,
        /// GNU C++ vtable hierarchy
        R_LARCH_GNU_VTINHERIT = 57,
        /// GNU C++ vtable member usage
        R_LARCH_GNU_VTENTRY = 58,
        /// 18-bit PC-relative jump offset with two trailing zeros
        R_LARCH_B16 = 64,
        /// 23-bit PC-relative jump offset with two trailing zeros
        R_LARCH_B21 = 65,
        /// 28-bit PC-relative jump offset with two trailing zeros
        R_LARCH_B26 = 66,
        /// 12..=31 bits of 32/64-bit absolute address
        R_LARCH_ABS_HI20 = 67,
        /// 0..=11 bits of 32/64-bit absolute address
        R_LARCH_ABS_LO12 = 68,
        /// 32..=51 bits of 64-bit absolute address
        R_LARCH_ABS64_LO20 = 69,
        /// 52..=63 bits of 64-bit absolute address
        R_LARCH_ABS64_HI12 = 70,
        /// The signed 32-bit offset `offs` from `PC & 0xfffff000` to
        /// `(S + A + 0x800) & 0xfffff000`, with 12 trailing zeros removed.
        ///
        /// We define the *PC relative anchor* for `S + A` as `PC + offs` (`offs`
        /// is sign-extended to VA bits).
        R_LARCH_PCALA_HI20 = 71,
        /// Same as R_LARCH_ABS_LO12.  0..=11 bits of the 32/64-bit offset from the
        /// [PC relative anchor][R_LARCH_PCALA_HI20].
        R_LARCH_PCALA_LO12 = 72,
        /// 32..=51 bits of the 64-bit offset from the
        /// [PC relative anchor][R_LARCH_PCALA_HI20].
        R_LARCH_PCALA64_LO20 = 73,
        /// 52..=63 bits of the 64-bit offset from the
        /// [PC relative anchor][R_LARCH_PCALA_HI20].
        R_LARCH_PCALA64_HI12 = 74,
        /// The signed 32-bit offset `offs` from `PC & 0xfffff000` to
        /// `(GP + G + 0x800) & 0xfffff000`, with 12 trailing zeros removed.
        ///
        /// We define the *PC relative anchor* for the GOT entry at `GP + G` as
        /// `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_GOT_PC_HI20 = 75,
        /// 0..=11 bits of the 32/64-bit offset from the
        /// [PC relative anchor][R_LARCH_GOT_PC_HI20] to the GOT entry.
        R_LARCH_GOT_PC_LO12 = 76,
        /// 32..=51 bits of the 64-bit offset from the
        /// [PC relative anchor][R_LARCH_GOT_PC_HI20] to the GOT entry.
        R_LARCH_GOT64_PC_LO20 = 77,
        /// 52..=63 bits of the 64-bit offset from the
        /// [PC relative anchor][R_LARCH_GOT_PC_HI20] to the GOT entry.
        R_LARCH_GOT64_PC_HI12 = 78,
        /// 12..=31 bits of 32/64-bit GOT entry absolute address
        R_LARCH_GOT_HI20 = 79,
        /// 0..=11 bits of 32/64-bit GOT entry absolute address
        R_LARCH_GOT_LO12 = 80,
        /// 32..=51 bits of 64-bit GOT entry absolute address
        R_LARCH_GOT64_LO20 = 81,
        /// 52..=63 bits of 64-bit GOT entry absolute address
        R_LARCH_GOT64_HI12 = 82,
        /// 12..=31 bits of TLS LE 32/64-bit offset from thread pointer
        R_LARCH_TLS_LE_HI20 = 83,
        /// 0..=11 bits of TLS LE 32/64-bit offset from thread pointer
        R_LARCH_TLS_LE_LO12 = 84,
        /// 32..=51 bits of TLS LE 64-bit offset from thread pointer
        R_LARCH_TLS_LE64_LO20 = 85,
        /// 52..=63 bits of TLS LE 64-bit offset from thread pointer
        R_LARCH_TLS_LE64_HI12 = 86,
        /// The signed 32-bit offset `offs` from `PC & 0xfffff000` to
        /// `(GP + IE + 0x800) & 0xfffff000`, with 12 trailing zeros removed.
        ///
        /// We define the *PC relative anchor* for the TLS IE GOT entry at
        /// `GP + IE` as `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_TLS_IE_PC_HI20 = 87,
        /// 0..=12 bits of the 32/64-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_IE_PC_HI20] to the TLS IE GOT entry.
        R_LARCH_TLS_IE_PC_LO12 = 88,
        /// 32..=51 bits of the 64-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_IE_PC_HI20] to the TLS IE GOT entry.
        R_LARCH_TLS_IE64_PC_LO20 = 89,
        /// 52..=63 bits of the 64-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_IE_PC_HI20] to the TLS IE GOT entry.
        R_LARCH_TLS_IE64_PC_HI12 = 90,
        /// 12..=31 bits of TLS IE GOT entry 32/64-bit absolute address
        R_LARCH_TLS_IE_HI20 = 91,
        /// 0..=11 bits of TLS IE GOT entry 32/64-bit absolute address
        R_LARCH_TLS_IE_LO12 = 92,
        /// 32..=51 bits of TLS IE GOT entry 64-bit absolute address
        R_LARCH_TLS_IE64_LO20 = 93,
        /// 51..=63 bits of TLS IE GOT entry 64-bit absolute address
        R_LARCH_TLS_IE64_HI12 = 94,
        /// 12..=31 bits of the offset from `PC` to `GP + GD + 0x800`, where
        /// `GP + GD` is a TLS LD GOT entry
        R_LARCH_TLS_LD_PC_HI20 = 95,
        /// 12..=31 bits of TLS LD GOT entry 32/64-bit absolute address
        R_LARCH_TLS_LD_HI20 = 96,
        /// 12..=31 bits of the 32/64-bit PC-relative offset to the PC-relative
        /// anchor for the TLE GD GOT entry.
        R_LARCH_TLS_GD_PC_HI20 = 97,
        /// 12..=31 bits of TLS GD GOT entry 32/64-bit absolute address
        R_LARCH_TLS_GD_HI20 = 98,
        /// 32-bit PC relative
        R_LARCH_32_PCREL = 99,
        /// Paired with a normal relocation at the same address to indicate the
        /// instruction can be relaxed
        R_LARCH_RELAX = 100,
        /// Reserved
        R_LARCH_DELETE = 101,
        /// Delete some bytes to ensure the instruction at PC + A aligned to
        /// `A.next_power_of_two()`-byte boundary
        R_LARCH_ALIGN = 102,
        /// 22-bit PC-relative offset with two trailing zeros
        R_LARCH_PCREL20_S2 = 103,
        /// Reserved
        R_LARCH_CFA = 104,
        /// 6-bit in-place addition
        R_LARCH_ADD6 = 105,
        /// 6-bit in-place subtraction
        R_LARCH_SUB6 = 106,
        /// LEB128 in-place addition
        R_LARCH_ADD_ULEB128 = 107,
        /// LEB128 in-place subtraction
        R_LARCH_SUB_ULEB128 = 108,
        /// 64-bit PC relative
        R_LARCH_64_PCREL = 109,
        /// 18..=37 bits of `S + A - PC` into the `pcaddu18i` instruction at `PC`,
        /// and 2..=17 bits of `S + A - PC` into the `jirl` instruction at `PC + 4`
        R_LARCH_CALL36 = 110,
        /// 12..=31 bits of 32/64-bit PC-relative offset to TLS DESC GOT entry
        R_LARCH_TLS_DESC_PC_HI20 = 111,
        /// 0..=11 bits of 32/64-bit TLS DESC GOT entry address
        R_LARCH_TLS_DESC_PC_LO12 = 112,
        /// 32..=51 bits of 64-bit PC-relative offset to TLS DESC GOT entry
        R_LARCH_TLS_DESC64_PC_LO20 = 113,
        /// 52..=63 bits of 64-bit PC-relative offset to TLS DESC GOT entry
        R_LARCH_TLS_DESC64_PC_HI12 = 114,
        /// 12..=31 bits of 32/64-bit TLS DESC GOT entry absolute address
        R_LARCH_TLS_DESC_HI20 = 115,
        /// 0..=11 bits of 32/64-bit TLS DESC GOT entry absolute address
        R_LARCH_TLS_DESC_LO12 = 116,
        /// 32..=51 bits of 64-bit TLS DESC GOT entry absolute address
        R_LARCH_TLS_DESC64_LO20 = 117,
        /// 52..=63 bits of 64-bit TLS DESC GOT entry absolute address
        R_LARCH_TLS_DESC64_HI12 = 118,
        /// Used on ld.{w,d} for TLS DESC to get the resolve function address
        /// from GOT entry
        R_LARCH_TLS_DESC_LD = 119,
        /// Used on jirl for TLS DESC to call the resolve function
        R_LARCH_TLS_DESC_CALL = 120,
        /// 12..=31 bits of TLS LE 32/64-bit offset from TP register, can be relaxed
        R_LARCH_TLS_LE_HI20_R = 121,
        /// TLS LE thread pointer usage, can be relaxed
        R_LARCH_TLS_LE_ADD_R = 122,
        /// 0..=11 bits of TLS LE 32/64-bit offset from TP register, sign-extended,
        /// can be relaxed.
        R_LARCH_TLS_LE_LO12_R = 123,
        /// 22-bit PC-relative offset to TLS LD GOT entry
        R_LARCH_TLS_LD_PCREL20_S2 = 124,
        /// 22-bit PC-relative offset to TLS GD GOT entry
        R_LARCH_TLS_GD_PCREL20_S2 = 125,
        /// 22-bit PC-relative offset to TLS DESC GOT entry
        R_LARCH_TLS_DESC_PCREL20_S2 = 126,
        /// 12..=31 bits of `S + A - PC` into the `pcaddu12i` instruction at `PC`,
        /// and 2..=11 bits of `S + A - PC` into the `jirl` instruction at `PC + 4`
        R_LARCH_CALL30 = 127,
        /// The signed 32-bit offset `offs` from `PC` to `(S + A + 0x800) & 0xfffff000`.
        ///
        /// We define the *PC relative anchor* for `S + A` as `PC + offs` (`offs`
        /// is sign-extended to VA bits).
        R_LARCH_PCADD_HI20 = 128,
        /// 0..=11 bits of the 32-bit offset from the
        /// [PC relative anchor][R_LARCH_PCADD_HI20].
        R_LARCH_PCADD_LO12 = 129,
        /// The signed 32-bit offset `offs` from `PC` to
        /// `(GP + G + 0x800) & 0xfffff000`.
        ///
        /// We define the *PC relative anchor* for the GOT entry at `GP + G` as
        /// `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_GOT_PCADD_HI20 = 130,
        /// 0..=11 bits of the 32-bit offset from the
        /// [PC relative anchor][R_LARCH_GOT_PCADD_HI20] to the GOT entry.
        R_LARCH_GOT_PCADD_LO12 = 131,
        /// The signed 32-bit offset `offs` from `PC` to
        /// `(GP + IE + 0x800) & 0xfffff000`.
        ///
        /// We define the *PC relative anchor* for the TLS IE GOT entry at
        /// `GP + IE` as `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_TLS_IE_PCADD_HI20 = 132,
        /// 0..=11 bits of the 32-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_IE_PCADD_HI20] to the TLS IE GOT entry.
        R_LARCH_TLS_IE_PCADD_LO12 = 133,
        /// The signed 32-bit offset `offs` from `PC` to
        /// `(GP + GD + 0x800) & 0xfffff000`.
        ///
        /// We define the *PC relative anchor* for the TLS LD GOT entry at
        /// `GP + GD` as `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_TLS_LD_PCADD_HI20 = 134,
        /// 0..=11 bits of the 32-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_LD_PCADD_HI20] to the TLS LD GOT entry.
        R_LARCH_TLS_LD_PCADD_LO12 = 135,
        /// The signed 32-bit offset `offs` from `PC` to
        /// `(GP + GD + 0x800) & 0xfffff000`.
        ///
        /// We define the *PC relative anchor* for the TLS GD GOT entry at
        /// `GP + GD` as `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_TLS_GD_PCADD_HI20 = 136,
        /// 0..=11 bits of the 32-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_GD_PCADD_HI20] to the TLS GD GOT entry.
        R_LARCH_TLS_GD_PCADD_LO12 = 137,
        /// The signed 32-bit offset `offs` from `PC` to
        /// `(GP + GD + 0x800) & 0xfffff000`.
        ///
        /// We define the *PC relative anchor* for the TLS DESC GOT entry at
        /// `GP + GD` as `PC + offs` (`offs` is sign-extended to VA bits).
        R_LARCH_TLS_DESC_PCADD_HI20 = 138,
        /// 0..=11 bits of the 32-bit offset from the
        /// [PC-relative anchor][R_LARCH_TLS_DESC_PCADD_HI20] to the TLS DESC GOT entry.
        R_LARCH_TLS_DESC_PCADD_LO12 = 139,
    };
}

constant_names!(NAMES_EF_LARCH_ABI: FileFlags(u32) = {
    /// Uses GPRs and the stack for parameter passing
    EF_LARCH_ABI_SOFT_FLOAT = 0x1,
    /// Uses GPRs, 32-bit FPRs and the stack for parameter passing
    EF_LARCH_ABI_SINGLE_FLOAT = 0x2,
    /// Uses GPRs, 64-bit FPRs and the stack for parameter passing
    EF_LARCH_ABI_DOUBLE_FLOAT = 0x3,
});

names! {
    struct Xtensa(Base);
    /// `Rel*::r_type` values for `EM_XTENSA`.
    consts r = pub NAMES_R_XTENSA: RelocationType(u32) = {
        R_XTENSA_NONE = 0,
        R_XTENSA_32 = 1,
        R_XTENSA_RTLD = 2,
        R_XTENSA_GLOB_DAT = 3,
        R_XTENSA_JMP_SLOT = 4,
        R_XTENSA_RELATIVE = 5,
        R_XTENSA_PLT = 6,
        R_XTENSA_OP0 = 8,
        R_XTENSA_OP1 = 9,
        R_XTENSA_OP2 = 10,
        R_XTENSA_ASM_EXPAND = 11,
        R_XTENSA_ASM_SIMPLIFY = 12,
        R_XTENSA_32_PCREL = 14,
        R_XTENSA_GNU_VTINHERIT = 15,
        R_XTENSA_GNU_VTENTRY = 16,
        R_XTENSA_DIFF8 = 17,
        R_XTENSA_DIFF16 = 18,
        R_XTENSA_DIFF32 = 19,
        R_XTENSA_SLOT0_OP = 20,
        R_XTENSA_SLOT1_OP = 21,
        R_XTENSA_SLOT2_OP = 22,
        R_XTENSA_SLOT3_OP = 23,
        R_XTENSA_SLOT4_OP = 24,
        R_XTENSA_SLOT5_OP = 25,
        R_XTENSA_SLOT6_OP = 26,
        R_XTENSA_SLOT7_OP = 27,
        R_XTENSA_SLOT8_OP = 28,
        R_XTENSA_SLOT9_OP = 29,
        R_XTENSA_SLOT10_OP = 30,
        R_XTENSA_SLOT11_OP = 31,
        R_XTENSA_SLOT12_OP = 32,
        R_XTENSA_SLOT13_OP = 33,
        R_XTENSA_SLOT14_OP = 34,
        R_XTENSA_SLOT0_ALT = 35,
        R_XTENSA_SLOT1_ALT = 36,
        R_XTENSA_SLOT2_ALT = 37,
        R_XTENSA_SLOT3_ALT = 38,
        R_XTENSA_SLOT4_ALT = 39,
        R_XTENSA_SLOT5_ALT = 40,
        R_XTENSA_SLOT6_ALT = 41,
        R_XTENSA_SLOT7_ALT = 42,
        R_XTENSA_SLOT8_ALT = 43,
        R_XTENSA_SLOT9_ALT = 44,
        R_XTENSA_SLOT10_ALT = 45,
        R_XTENSA_SLOT11_ALT = 46,
        R_XTENSA_SLOT12_ALT = 47,
        R_XTENSA_SLOT13_ALT = 48,
        R_XTENSA_SLOT14_ALT = 49,
        R_XTENSA_TLSDESC_FN = 50,
        R_XTENSA_TLSDESC_ARG = 51,
        R_XTENSA_TLS_DTPOFF = 52,
        R_XTENSA_TLS_TPOFF = 53,
        R_XTENSA_TLS_FUNC = 54,
        R_XTENSA_TLS_ARG = 55,
        R_XTENSA_TLS_CALL = 56,
        R_XTENSA_PDIFF8 = 57,
        R_XTENSA_PDIFF16 = 58,
        R_XTENSA_PDIFF32 = 59,
        R_XTENSA_NDIFF8 = 60,
        R_XTENSA_NDIFF16 = 61,
        R_XTENSA_NDIFF32 = 62,
    };
}

/// Encode `E_E2K_MACH_*` into `FileHeader*::e_flags`.
pub const fn ef_e2k_mach_to_flag(e_flags: u32, x: u32) -> u32 {
    (e_flags & 0xffffff) | (x << 24)
}

/// Decode `E_E2K_MACH_*` from `FileHeader*::e_flags`.
pub const fn ef_e2k_flag_to_mach(e_flags: u32) -> u32 {
    e_flags >> 24
}

// Codes of supported E2K machines.

/// -march=generic code.
///
/// Legacy. Shouldn't be created nowadays.
pub const E_E2K_MACH_BASE: u32 = 0;
/// -march=elbrus-v1 code.
///
/// Legacy. Shouldn't be created nowadays.
pub const E_E2K_MACH_EV1: u32 = 1;
/// -march=elbrus-v2 code.
pub const E_E2K_MACH_EV2: u32 = 2;
/// -march=elbrus-v3 code.
pub const E_E2K_MACH_EV3: u32 = 3;
/// -march=elbrus-v4 code.
pub const E_E2K_MACH_EV4: u32 = 4;
/// -march=elbrus-v5 code.
pub const E_E2K_MACH_EV5: u32 = 5;
/// -march=elbrus-v6 code.
pub const E_E2K_MACH_EV6: u32 = 6;
/// -march=elbrus-v7 code.
pub const E_E2K_MACH_EV7: u32 = 7;
/// -mtune=elbrus-8c code.
pub const E_E2K_MACH_8C: u32 = 19;
/// -mtune=elbrus-1c+ code.
pub const E_E2K_MACH_1CPLUS: u32 = 20;
/// -mtune=elbrus-12c code.
pub const E_E2K_MACH_12C: u32 = 21;
/// -mtune=elbrus-16c code.
pub const E_E2K_MACH_16C: u32 = 22;
/// -mtune=elbrus-2c3 code.
pub const E_E2K_MACH_2C3: u32 = 23;
/// -mtune=elbrus-48c code.
pub const E_E2K_MACH_48C: u32 = 24;
/// -mtune=elbrus-8v7 code.
pub const E_E2K_MACH_8V7: u32 = 25;

names! {
    struct E2k(Base);
    flags ef: FileFlags(u32) = {
        EF_E2K_IPD = 3,
        EF_E2K_X86APP = 4,
        EF_E2K_4MB_PAGES = 8,
        EF_E2K_INCOMPAT = 16,
        EF_E2K_PM = 32,
        EF_E2K_PACK_SEGMENTS = 64,
    };
    /// `Rel*::r_type` values for `EM_MCST_ELBRUS`.
    consts r = pub NAMES_R_E2K: RelocationType(u32) = {
        /// Direct 32 bit.
        R_E2K_32_ABS = 0,
        /// PC relative 32 bit.
        R_E2K_32_PC = 2,
        /// 32-bit offset of AP GOT entry.
        R_E2K_AP_GOT = 3,
        /// 32-bit offset of PL GOT entry.
        R_E2K_PL_GOT = 4,
        /// Create PLT entry.
        R_E2K_32_JMP_SLOT = 8,
        /// Copy relocation, 32-bit case.
        R_E2K_32_COPY = 9,
        /// Adjust by program base, 32-bit case.
        R_E2K_32_RELATIVE = 10,
        /// Adjust indirectly by program base, 32-bit case.
        R_E2K_32_IRELATIVE = 11,
        /// Size of symbol plus 32-bit addend.
        R_E2K_32_SIZE = 12,
        /// Symbol value if resolved by the definition in the same
        /// compilation unit or NULL otherwise, 32-bit case.
        R_E2K_32_DYNOPT = 13,
        /// Direct 64 bit.
        R_E2K_64_ABS = 50,
        /// Direct 64 bit for literal.
        R_E2K_64_ABS_LIT = 51,
        /// PC relative 64 bit for literal.
        R_E2K_64_PC_LIT = 54,
        /// Create PLT entry, 64-bit case.
        R_E2K_64_JMP_SLOT = 63,
        /// Copy relocation, 64-bit case.
        R_E2K_64_COPY = 64,
        /// Adjust by program base, 64-bit case.
        R_E2K_64_RELATIVE = 65,
        /// Adjust by program base for literal, 64-bit case.
        R_E2K_64_RELATIVE_LIT = 66,
        /// Adjust indirectly by program base, 64-bit case.
        R_E2K_64_IRELATIVE = 67,
        /// Size of symbol plus 64-bit addend.
        R_E2K_64_SIZE = 68,
        /// 64-bit offset of the symbol from GOT.
        R_E2K_64_GOTOFF = 69,

        /// GOT entry for ID of module containing symbol.
        R_E2K_TLS_GDMOD = 70,
        /// GOT entry for offset in module TLS block.
        R_E2K_TLS_GDREL = 71,
        /// Static TLS block offset GOT entry.
        R_E2K_TLS_IE = 74,
        /// Offset relative to static TLS block, 32-bit case.
        R_E2K_32_TLS_LE = 75,
        /// Offset relative to static TLS block, 64-bit case.
        R_E2K_64_TLS_LE = 76,
        /// ID of module containing symbol, 32-bit case.
        R_E2K_TLS_32_DTPMOD = 80,
        /// Offset in module TLS block, 32-bit case.
        R_E2K_TLS_32_DTPREL = 81,
        /// ID of module containing symbol, 64-bit case.
        R_E2K_TLS_64_DTPMOD = 82,
        /// Offset in module TLS block, 64-bit case.
        R_E2K_TLS_64_DTPREL = 83,
        /// Offset in static TLS block, 32-bit case.
        R_E2K_TLS_32_TPREL = 84,
        /// Offset in static TLS block, 64-bit case.
        R_E2K_TLS_64_TPREL = 85,

        /// Direct AP.
        R_E2K_AP = 100,
        /// Direct PL.
        R_E2K_PL = 101,

        /// 32-bit offset of the symbol's entry in GOT.
        R_E2K_GOT = 108,
        /// 32-bit offset of the symbol from GOT.
        R_E2K_GOTOFF = 109,
        /// PC relative 28 bit for DISP.
        R_E2K_DISP = 110,
        /// Prefetch insn line containing the label (symbol).
        R_E2K_PREF = 111,
        /// No reloc.
        R_E2K_NONE = 112,
        /// 32-bit offset of the symbol's entry in .got.plt.
        R_E2K_GOTPLT = 114,
        /// Is symbol resolved locally during the link.
        /// The result is encoded in 5-bit ALS.src1.
        R_E2K_ISLOCAL = 115,
        /// Is symbol resloved locally during the link.
        /// The result is encoded in a long 32-bit LTS.
        R_E2K_ISLOCAL32 = 118,
        /// The symbol's offset from GOT encoded within a 64-bit literal.
        R_E2K_64_GOTOFF_LIT = 256,
        /// Symbol value if resolved by the definition in the same
        /// compilation unit or NULL otherwise, 64-bit case.
        R_E2K_64_DYNOPT = 257,
        /// PC relative 64 bit in data.
        R_E2K_64_PC = 258,
    };
    consts dt: DynamicTag(i64) = {
        DT_E2K_LAZY = DT_LOPROC + 1,
        DT_E2K_LAZY_GOT = DT_LOPROC + 3,

        DT_E2K_INIT_GOT = DT_LOPROC + 0x101c,
        DT_E2K_EXPORT_PL = DT_LOPROC + 0x101d,
        DT_E2K_EXPORT_PLSZ = DT_LOPROC + 0x101e,
        DT_E2K_REAL_PLTGOT = DT_LOPROC + 0x101f,
        DT_E2K_NO_SELFINIT = DT_LOPROC + 0x1020,
    };
}

pub const DT_E2K_NUM: i64 = 0x1021;

newtype!(
    /// Value for the subsubsection tag in an attributes section.
    struct AttributeTag(u8);
);

newtype_constant_names!(NAMES_TAG: AttributeTag(u8) = {
    #[allow(non_upper_case_globals)]
    Tag_File = 1,
    #[allow(non_upper_case_globals)]
    Tag_Section = 2,
    #[allow(non_upper_case_globals)]
    Tag_Symbol = 3,
});

unsafe_impl_endian_pod!(
    FileHeader32,
    FileHeader64,
    SectionHeader32,
    SectionHeader64,
    CompressionHeader32,
    CompressionHeader64,
    Sym32,
    Sym64,
    Syminfo32,
    Syminfo64,
    Rel32,
    Rel64,
    Rela32,
    Rela64,
    Relr32,
    Relr64,
    ProgramHeader32,
    ProgramHeader64,
    Dyn32,
    Dyn64,
    Versym,
    Verdef,
    Verdaux,
    Verneed,
    Vernaux,
    NoteHeader32,
    NoteHeader64,
    HashHeader,
    GnuHashHeader,
);