summaryrefslogtreecommitdiffstats
path: root/patches/binutils-2.20.1a/atmel/0002-Add-Atmels-AVR-COFF-output-to-objcopy-utility.patch
blob: 7c9c4008aff0b48c7be84df4ee53e9459c37a328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
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
From b88360877c2d1143074ea8d9bae2bdf9a104743a Mon Sep 17 00:00:00 2001
From: Stephan Linz <linz@li-pro.net>
Date: Mon, 18 Apr 2011 20:41:41 +0200
Subject: [PATCH 2/9] Add Atmels AVR COFF output to objcopy utility

In order to convert the ELF format used in the opensource AVR
toolchain with its debugging information to the AVR COFF format as
defined by Atmel for its AVR Studio, the objcopy utility needs an
associated extension.

There are two different file formats defined by Atmel, the original
AVR COFF format, and a newer version that is understood by AVR
Studio 4.07 and above called AVR Extended COFF. In order to provide
an easy way to distinguish both, two different BFD names have been
chose within GNU binutils, coff-avr for the former, coff-ext-avr
for the latter.

More details at:
http://www.sax.de/~joerg/README.coff-avr-patch
http://www.amelek.gda.pl/avr/old/binutils/avrcoff.pdf

Original ATMEL patch from:
http://distribute.atmel.no/tools/opensource/avr-gcc/binutils-2.20.1/31-binutils-2.20.1-avr-coff.patch

Signed-off-by: Stephan Linz <linz@li-pro.net>
---
 bfd/Makefile.am           |    4 +
 bfd/Makefile.in           |    4 +
 bfd/README.coff-avr-patch |  264 ++++
 bfd/coff-avr.c            |  613 ++++++++
 bfd/coff-ext-avr.c        |  428 ++++++
 bfd/coffcode.h            |   65 +-
 bfd/coffgen.c             |   63 +-
 bfd/coffswap.h            |   10 +-
 bfd/config.bfd            |    1 +
 bfd/configure             |    2 +
 bfd/configure.in          |    2 +
 bfd/targets.c             |    4 +
 binutils/Makefile.am      |    4 +-
 binutils/Makefile.in      |    6 +-
 binutils/bucomm.c         |   26 +
 binutils/bucomm.h         |    2 +
 binutils/budbg.h          |    5 +-
 binutils/debug.c          |   89 ++
 binutils/debug.h          |    6 +
 binutils/doc/objcopy.1    |   19 +
 binutils/objcopy.c        |   40 +-
 binutils/rdcoff.c         |   57 +-
 binutils/wrcoff.c         | 3410 +++++++++++++++++++++++++++++++++++++++++++++
 include/coff/avr.h        |  110 ++
 include/coff/internal.h   |    2 +
 25 files changed, 5199 insertions(+), 37 deletions(-)
 create mode 100644 bfd/README.coff-avr-patch
 create mode 100644 bfd/coff-avr.c
 create mode 100644 bfd/coff-ext-avr.c
 create mode 100644 binutils/wrcoff.c
 create mode 100644 include/coff/avr.h

diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 13ace29..9a12233 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -228,6 +228,8 @@ BFD32_BACKENDS = \
 	coff-apollo.lo \
 	coff-arm.lo \
 	coff-aux.lo \
+        coff-avr.lo \
+        coff-ext-avr.lo \
 	coff-go32.lo \
 	coff-h8300.lo \
 	coff-h8500.lo \
@@ -411,6 +413,8 @@ BFD32_BACKENDS_CFILES = \
 	coff-apollo.c \
 	coff-arm.c \
 	coff-aux.c \
+	coff-avr.c \
+	coff-ext-avr.c \
 	coff-go32.c \
 	coff-h8300.c \
 	coff-h8500.c \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index 4068a2d..696b628 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -524,6 +524,8 @@ BFD32_BACKENDS = \
 	coff-apollo.lo \
 	coff-arm.lo \
 	coff-aux.lo \
+	coff-avr.lo \
+        coff-ext-avr.lo \
 	coff-go32.lo \
 	coff-h8300.lo \
 	coff-h8500.lo \
@@ -707,6 +709,8 @@ BFD32_BACKENDS_CFILES = \
 	coff-apollo.c \
 	coff-arm.c \
 	coff-aux.c \
+	coff-avr.c \
+	coff-ext-avr.c \
 	coff-go32.c \
 	coff-h8300.c \
 	coff-h8500.c \
diff --git a/bfd/README.coff-avr-patch b/bfd/README.coff-avr-patch
new file mode 100644
index 0000000..1694089
--- /dev/null
+++ b/bfd/README.coff-avr-patch
@@ -0,0 +1,264 @@
+README for the »coff-avr-patch«                     2003-05-16
+===============================
+
+Background
+----------
+
+In order to convert the ELF format used in the opensource AVR
+toolchain (commonly known as just »avr-gcc«) with its debugging
+information that is called »stabs« to the AVR COFF format as defined
+by Atmel for its AVR Studio, two conversion steps are basically
+necessary: the object file format itself needs to be translated from
+ELF to COFF, which is a relatively simple conversion for the most
+part, since all the contents of the various sections of the object
+file can be copied verbatim, and the main change is a different object
+file header.  The »objcopy« tool that comes with GNU binutils (called
+»avr-objcopy« in our case) has been designed for this kind of
+conversions, and the GNU binutils itself could already handle more
+than two dozens of different COFF file formats, so for most of the
+part, a common subset of COFF utilities could already be used.  (COFF
+is a very old object file format that has been in wide use by end of
+the 1980s/beginning of the 1990s.)
+
+There are two different file formats defined by Atmel, the original
+AVR COFF format, and a newer version that is understood by AVR Studio
+4.07 and above called AVR »extended« COFF.  In order to provide an
+easy way to distinguish both, two different so-called BFD names have
+been chose within GNU binutils, coff-avr for the former, coff-ext-avr
+for the latter.  (BFD stands for »binary filedescriptor« and is
+basically the central library of the GNU binutils suite that handles
+all the object file IO.)
+
+In short, chose coff-ext-avr for AVR Studio 4.07 and above, and
+coff-avr for anything else (which includes AVR Studio 3.x, and VMLAB).
+The main differences are that the newer format can transport long
+filenames (so directory information will be retained), and has the
+option to debug struct types.
+
+The tough part was to convert the stabs debugging information into the
+so-called native COFF debugging format, which is basically an
+extension of the symbol table that can usually be found in object file
+formats.  Symbol tables provide a listing of names vs. object file
+sections plus addresses within that section, that can be displayed
+with the (avr-)nm tool.  Now COFF has extended the meaning of a symbol
+by adding some debugging information to it within the symbol table.
+In contrast, the approach taken with ELF is to leave the symbol table
+as it is (the so-called non-debugging symbols), and add the debugging
+information in separate sections within the object file.  Since the
+amount of information that can be transported by native COFF
+debugging, the approach to use (stabs) debugging information in
+separate sections has also been in widespread use with COFF on Unix
+systems, but unfortunately Atmel had chosen native COFF debugging
+information instead.
+
+Fortunately, the objcopy tool already had implemented part of the
+task: the --debugging option was already there, and is meant to
+convert the debugging information from the input file into a generic
+internal debugging format, and from there into the debugging
+information required for the output file.  So it was ``only'' that a
+COFF debugging generator needed to be written.  (The source code for
+this converter alone is close to 100 KB, in almost 3,500 lines of C
+code...)
+
+
+The conversion from ELF/stabs to AVR COFF
+-----------------------------------------
+
+The usage of objcopy to convert ELF/stabs debugging information into
+AVR COFF debugging information is (long lines wrapped with
+backslashes):
+
+avr-objcopy \
+        --debugging \
+        -O ${FORMAT} \
+        --change-section-address .data-0x800000 \
+        --change-section-address .bss-0x800000 \
+        --change-section-address .noinit-0x800000 \
+        --change-section-address .eeprom-0x810000 \
+        ${filename}.elf ${filename}.cof
+
+where ${FORMAT} should either be "coff-avr" (COFF format that matches
+the older Atmel AVR COFF documentation, as understood by AVR Studio 3,
+early versions of AVR Studio 4, and also by VMLAB), or "coff-ext-avr"
+(current AVR »extended« COFF specification, as understood by AVR
+Studio 4.07; adds long filenames and structure debugging).  There are
+some more options dealing with the mapping of debugging source file
+names for coff-ext-avr which i can explain later if you need this
+(coff-avr only supports 14-char filenames, so no source file directory
+information can be tranferred there).
+
+In the WinAVR template Makefile, you can say »make coff« to get the
+resulting file ($(TARGET).cof) in the coff-avr format, and »make
+extcoff« to get it in the coff-ext-avr format.
+
+There might be some warnings when you run the above, like
+
+Warning: file {standard input} not found in symbol table, ignoring
+Warning: ignoring function __vectors() outside any compilation unit
+Warning: ignoring function __bad_interrupt() outside any compilation unit
+
+Perhaps more of them if your avr-libc has been installed with
+debugging symbols (the default WinAVR installation strips debugging
+symbols from the installed library files).  There should be no other
+warning normally.
+
+Run it on your jobs, see if it works as expected.  In particular, i'm
+interested in getting results for more complex datatypes, like arrays
+of pointers to function, or functions returning pointers to
+structures, and such.
+
+
+COFF woes
+---------
+
+When working with COFF files, keep in mind that it's fairly limited.
+Basically, you can cut it down to stating that native COFF debugging
+can only support anything that was already defined in the very first C
+implementation, the so-called Kernighan/Ritchie C.  There wasn't a
+standard for C by that time, so the de-facto standard was what has
+been described by the creators of C, Brian Kernighan and Dennis
+Ritchie, in their book ``The C programming language''.
+
+Anything that appeared later, starting with the extension by the
+so-called ANSI C (now called C89), is basically unsupported in COFF,
+because the debugging format has not been designed with extension in
+mind.  Needless to say, this also includes any C99 or C++ extensions.
+
+Also not supported in COFF are include files.  So if you've got an
+include file that actually produces code (e. g. in an inline
+function), don't be surprised that the line numbers in the object file
+will come out as junk.
+
+COFF tried to save space everywhere, so they defined line numbers as
+16-bit quantities.  In order to not limit a single source file to 64 K
+lines, they then defined their line numbers relative to the beginning
+of a function.  Thus, COFF line numbers can only exist inside
+functions, and since functions need an input file name, if we don't
+have one (as it can happen in some assembler files assembled with
+--gstabs), we are hosed.
+
+Finally, even AVR Studio 4.07 implements only a subset of COFF
+debugging information.  Currently still unsupported are bitfield
+structs, enums, and typedefs.  Note that the binutils patch does
+support all of these features -- only AVR Studio cannot handle them.
+
+
+COFF file analysis using abr-objdump
+------------------------------------
+
+avr-objdump -g gives a nice pseudo-C code listing of the debug
+information contained in an object file.  If you suspect any problems
+with the conversion of the debugging information, try first running
+this on both, the input ELF, and the output COFF file.
+
+avr-objdump -t gives the raw COFF symbol table listing.  It's not
+completely "raw" though, since AVR COFF has so many twists and
+abominations compared to the historic standard COFF, and in order to
+be able to use all the COFF infrastructure in GNU binutils, i'm
+"normalizing" most of this when reading the file (at the same boundary
+where the byte-swapping is handled inside binutils), and de-normalize
+it to the AVRisms when writing it.  Thus, objdump -t shows the
+normalized internal form.
+
+Should you ever need this, i'm happy to explain you in more detail,
+and give you both the current Atmel specs for AVR COFF, as well as a
+pointer to a generic COFF description.  It'll be lengthy to explain
+that right now.
+
+
+Bug reporting
+-------------
+
+If you suspect a bug, please make first sure that you've read and
+understood all of the above, in particular the limitations of COFF.
+Please also make sure that you don't just have a plain usage error.
+Remember that there has been a fair amount of alpha testing, so all
+the basic problems should have been shaken out by now.
+
+Then, try breaking down what the bug might be.  Use the avr-objdump
+tool as described above, to see what the debugging information in both
+files looks like.  Obviously, they will never look identical (there
+are two many differences in the internal representation between stabs
+and native COFF debugging), but they should be similar.  If
+avr-objdump -g produces the expected result but AVR Studio doesn't
+work the way you think, it's most likely not a bug in the conversion,
+but maybe either that the compiler gave incorrect information about an
+object to debug (i've seen situations where a variable got optimized
+completely away in a simple function, so obviously, the debugging
+information for it was wrong), or a problem in the debugger used (like
+AVR Studio).
+
+Finally, try to make it reproducable.  Don't send 500 KB entire
+project ZIP files.  Keep in mind that i don't have Windows, and don't
+run AVR Studio -- so don't just make the assumption i could reproduce
+your problem.  Please, break it down to the respective portion of the
+avr-objdump -t output (you can see the symbol name in the right
+column, use that for navigation), and send the portion of this dump
+that describes the problem.  For a function, that »portion« starts at
+the symbol with the name of the function, and then goes from the .bf
+symbol to the corresponding .ef symbol.  For a structure definition,
+it starts with the name of the struct, and goes through the .eos
+symbol.
+
+So in order to send a bug report, please use the address
+
+<avrcoff-bugs@uriah.heep.sax.de>
+
+Depending on the time available, and the degree of your own
+investigation, i'll try to answer them.
+
+
+Known issues
+------------
+
+There are few remaining known issues with the generated COFF.
+
+The so-called AUX entry pointerization is sometimes wrong.  According
+to the COFF specs, all the .bf symbols should form a linked-list,
+where the "next" pointer in each of them points to the next .bf.
+There are similar issues for some other of these records.  This should
+normally not upset the debuggers like AVR Studio because they don't
+care about it, and will be fixed anytime soon (but the fix is not so
+easy unfortunately).
+
+There is a known and still uninvestigated issue where some bootloader
+code could not be debugged.
+
+There is one issue with memory de-allocation that is not yet properly
+handled, which is merely cosmetical since when the objcopy tool exits,
+the memory will of course be freed anyway.
+
+There are two known issues with the latest official (by now) version
+of AVR Studio 4.07's COFF parser.  The first is that this parser used
+to assume a fixed section ordering instead of checking the COFF file
+header.  Usually, gcc also emits the various sections in the order
+assumed by that parser (.text first, .data following), but under some
+circumstances, gcc could put .data first as well.  With the buggy
+parser, this would make AVR Studio believe your variables were located
+in ROM.
+
+The second issue is that AVR Studio until now didn't support the way
+gcc allocates the initialization data for initialized variables: they
+are not issued as part of the program code, but instead need to
+appended manually after the program code itself.  (When preparing an
+Intel Hex file, this is usually done by specifying both, the .text and
+.data section in the call to avr-objcopy.)  So in the end, AVR Studio
+was simulating with all the initializers still using 0xff as ROM
+contents.  There is no fix for this behaviour for AVR Studio 3.x,
+and/or for older versions of AVR Studio 4.x (all released versions by
+now), and/or for other ELF->COFF conversion tools than the GNU
+binutils with the current coff-avr-patch.  Starting with this patch,
+we have negotiated our own vendor ID in the extended AVR COFF header
+(0x9cc, mnemonic for "gcc"), and Atmel agreed to adjust their COFF
+parser so it also loads the contents of .data into the simulator flash
+after .text when it sees this vendor ID.
+
+Both issues have been fixed internally in Atmel's sources, but by now,
+there is no official version of the updated COFF parser available yet.
+There have been rumours that they might release their own beta site to
+the public in order to test the updated COFF parser as well (which is
+just a DLL that needs to be replaced).
+
+
+Dresden, Germany, 2003-05-16
+Joerg Wunsch
diff --git a/bfd/coff-avr.c b/bfd/coff-avr.c
new file mode 100644
index 0000000..d02e933
--- /dev/null
+++ b/bfd/coff-avr.c
@@ -0,0 +1,613 @@
+/* BFD back-end for Atmel AVR COFF files.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
+   Free Software Foundation, Inc.
+   Created mostly by substituting "avr" for "i860" in coff-i860.c
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+
+#include "coff/avr.h"
+
+#include "coff/internal.h"
+
+#include "libcoff.h"
+
+static bfd_reloc_status_type coff_avr_reloc
+  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+static reloc_howto_type *coff_avr_rtype_to_howto
+  PARAMS ((bfd *, asection *, struct internal_reloc *,
+	   struct coff_link_hash_entry *, struct internal_syment *,
+	   bfd_vma *));
+static const bfd_target * coff_avr_object_p PARAMS ((bfd *));
+
+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
+/* The page size is a guess based on ELF.  */
+
+#define COFF_PAGE_SIZE 0x1000
+
+/* For some reason when using avr COFF the value stored in the .text
+   section for a reference to a common symbol is the value itself plus
+   any desired offset.  Ian Taylor, Cygnus Support.  */
+
+/* If we are producing relocateable output, we need to do some
+   adjustments to the object file that are not done by the
+   bfd_perform_relocation function.  This function is called by every
+   reloc type to make any required adjustments.  */
+
+static bfd_reloc_status_type
+coff_avr_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
+		 error_message)
+     bfd *abfd;
+     arelent *reloc_entry;
+     asymbol *symbol;
+     PTR data;
+     asection *input_section ATTRIBUTE_UNUSED;
+     bfd *output_bfd;
+     char **error_message ATTRIBUTE_UNUSED;
+{
+  symvalue diff;
+
+  if (output_bfd == (bfd *) NULL)
+    return bfd_reloc_continue;
+
+  if (bfd_is_com_section (symbol->section))
+    {
+      /* We are relocating a common symbol.  The current value in the
+	 object file is ORIG + OFFSET, where ORIG is the value of the
+	 common symbol as seen by the object file when it was compiled
+	 (this may be zero if the symbol was undefined) and OFFSET is
+	 the offset into the common symbol (normally zero, but may be
+	 non-zero when referring to a field in a common structure).
+	 ORIG is the negative of reloc_entry->addend, which is set by
+	 the CALC_ADDEND macro below.  We want to replace the value in
+	 the object file with NEW + OFFSET, where NEW is the value of
+	 the common symbol which we are going to put in the final
+	 object file.  NEW is symbol->value.  */
+      diff = symbol->value + reloc_entry->addend;
+    }
+  else
+    {
+      /* For some reason bfd_perform_relocation always effectively
+	 ignores the addend for a COFF target when producing
+	 relocateable output.  This seems to be always wrong for 860
+	 COFF, so we handle the addend here instead.  */
+      diff = reloc_entry->addend;
+    }
+
+#define DOIT(x) \
+  x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
+
+    if (diff != 0)
+      {
+	reloc_howto_type *howto = reloc_entry->howto;
+	unsigned char *addr = (unsigned char *) data + reloc_entry->address;
+
+	switch (howto->size)
+	  {
+	  case 0:
+	    {
+	      char x = bfd_get_8 (abfd, addr);
+	      DOIT (x);
+	      bfd_put_8 (abfd, x, addr);
+	    }
+	    break;
+
+	  case 1:
+	    {
+	      short x = bfd_get_16 (abfd, addr);
+	      DOIT (x);
+	      bfd_put_16 (abfd, (bfd_vma) x, addr);
+	    }
+	    break;
+
+	  case 2:
+	    {
+	      long x = bfd_get_32 (abfd, addr);
+	      DOIT (x);
+	      bfd_put_32 (abfd, (bfd_vma) x, addr);
+	    }
+	    break;
+
+	  default:
+	    abort ();
+	  }
+      }
+
+  /* Now let bfd_perform_relocation finish everything up.  */
+  return bfd_reloc_continue;
+}
+
+#ifndef PCRELOFFSET
+#define PCRELOFFSET FALSE
+#endif
+
+static reloc_howto_type howto_table[] =
+{
+  EMPTY_HOWTO (0),
+  EMPTY_HOWTO (1),
+  EMPTY_HOWTO (2),
+  EMPTY_HOWTO (3),
+  EMPTY_HOWTO (4),
+  EMPTY_HOWTO (5),
+  HOWTO (R_DIR32,               /* type */
+	 0,	                /* rightshift */
+	 2,	                /* size (0 = byte, 1 = short, 2 = long) */
+	 32,	                /* bitsize */
+	 FALSE,	                /* pc_relative */
+	 0,	                /* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_avr_reloc,       /* special_function */
+	 "dir32",               /* name */
+	 TRUE,	                /* partial_inplace */
+	 0xffffffff,            /* src_mask */
+	 0xffffffff,            /* dst_mask */
+	 TRUE),                /* pcrel_offset */
+  /* {7}, */
+  HOWTO (R_IMAGEBASE,            /* type */
+	 0,	                /* rightshift */
+	 2,	                /* size (0 = byte, 1 = short, 2 = long) */
+	 32,	                /* bitsize */
+	 FALSE,	                /* pc_relative */
+	 0,	                /* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_avr_reloc,       /* special_function */
+	 "rva32",	           /* name */
+	 TRUE,	                /* partial_inplace */
+	 0xffffffff,            /* src_mask */
+	 0xffffffff,            /* dst_mask */
+	 FALSE),                /* pcrel_offset */
+  EMPTY_HOWTO (010),
+  EMPTY_HOWTO (011),
+  EMPTY_HOWTO (012),
+  EMPTY_HOWTO (013),
+  EMPTY_HOWTO (014),
+  EMPTY_HOWTO (015),
+  EMPTY_HOWTO (016),
+  HOWTO (R_RELBYTE,		/* type */
+	 0,			/* rightshift */
+	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+	 8,			/* bitsize */
+	 FALSE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_avr_reloc,	/* special_function */
+	 "8",			/* name */
+	 TRUE,			/* partial_inplace */
+	 0x000000ff,		/* src_mask */
+	 0x000000ff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_RELWORD,		/* type */
+	 0,			/* rightshift */
+	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+	 16,			/* bitsize */
+	 FALSE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_avr_reloc,	/* special_function */
+	 "16",			/* name */
+	 TRUE,			/* partial_inplace */
+	 0x0000ffff,		/* src_mask */
+	 0x0000ffff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_RELLONG,		/* type */
+	 0,			/* rightshift */
+	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+	 32,			/* bitsize */
+	 FALSE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_avr_reloc,	/* special_function */
+	 "32",			/* name */
+	 TRUE,			/* partial_inplace */
+	 0xffffffff,		/* src_mask */
+	 0xffffffff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_PCRBYTE,		/* type */
+	 0,			/* rightshift */
+	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+	 8,			/* bitsize */
+	 TRUE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_signed, /* complain_on_overflow */
+	 coff_avr_reloc,	/* special_function */
+	 "DISP8",		/* name */
+	 TRUE,			/* partial_inplace */
+	 0x000000ff,		/* src_mask */
+	 0x000000ff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_PCRWORD,		/* type */
+	 0,			/* rightshift */
+	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+	 16,			/* bitsize */
+	 TRUE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_signed, /* complain_on_overflow */
+	 coff_avr_reloc,	/* special_function */
+	 "DISP16",		/* name */
+	 TRUE,			/* partial_inplace */
+	 0x0000ffff,		/* src_mask */
+	 0x0000ffff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_PCRLONG,		/* type */
+	 0,			/* rightshift */
+	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+	 32,			/* bitsize */
+	 TRUE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_signed, /* complain_on_overflow */
+	 coff_avr_reloc,	/* special_function */
+	 "DISP32",		/* name */
+	 TRUE,			/* partial_inplace */
+	 0xffffffff,		/* src_mask */
+	 0xffffffff,		/* dst_mask */
+	 PCRELOFFSET)		/* pcrel_offset */
+};
+
+/* Turn a howto into a reloc  nunmber */
+
+#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
+#define BADMAG(x) AVRBADMAG(x)
+#define AVR 1			/* Customize coffcode.h */
+
+#define RTYPE2HOWTO(cache_ptr, dst) \
+	    (cache_ptr)->howto = howto_table + (dst)->r_type;
+
+/* For AVR COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
+   library.  On some other COFF targets STYP_BSS is normally
+   STYP_NOLOAD.  */
+#define BSS_NOLOAD_IS_SHARED_LIBRARY
+
+/* Compute the addend of a reloc.  If the reloc is to a common symbol,
+   the object file contains the value of the common symbol.  By the
+   time this is called, the linker may be using a different symbol
+   from a different object file with a different value.  Therefore, we
+   hack wildly to locate the original symbol from this file so that we
+   can make the correct adjustment.  This macro sets coffsym to the
+   symbol from the original file, and uses it to set the addend value
+   correctly.  If this is not a common symbol, the usual addend
+   calculation is done, except that an additional tweak is needed for
+   PC relative relocs.
+   FIXME: This macro refers to symbols and asect; these are from the
+   calling function, not the macro arguments.  */
+
+#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)		\
+  {								\
+    coff_symbol_type *coffsym = (coff_symbol_type *) NULL;	\
+    if (ptr && bfd_asymbol_bfd (ptr) != abfd)			\
+      coffsym = (obj_symbols (abfd)				\
+	         + (cache_ptr->sym_ptr_ptr - symbols));		\
+    else if (ptr)						\
+      coffsym = coff_symbol_from (abfd, ptr);			\
+    if (coffsym != (coff_symbol_type *) NULL			\
+	&& coffsym->native->u.syment.n_scnum == 0)		\
+      cache_ptr->addend = - coffsym->native->u.syment.n_value;	\
+    else if (ptr && bfd_asymbol_bfd (ptr) == abfd		\
+	     && ptr->section != (asection *) NULL)		\
+      cache_ptr->addend = - (ptr->section->vma + ptr->value);	\
+    else							\
+      cache_ptr->addend = 0;					\
+    if (ptr && howto_table[reloc.r_type].pc_relative)		\
+      cache_ptr->addend += asect->vma;				\
+  }
+
+/* We use the special COFF backend linker.  */
+#define coff_relocate_section _bfd_coff_generic_relocate_section
+
+static reloc_howto_type *
+coff_avr_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     asection *sec;
+     struct internal_reloc *rel;
+     struct coff_link_hash_entry *h;
+     struct internal_syment *sym;
+     bfd_vma *addendp;
+{
+
+  reloc_howto_type *howto;
+
+  howto = howto_table + rel->r_type;
+
+  if (howto->pc_relative)
+    *addendp += sec->vma;
+
+  if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
+    {
+      /* This is a common symbol.  The section contents include the
+	 size (sym->n_value) as an addend.  The relocate_section
+	 function will be adding in the final value of the symbol.  We
+	 need to subtract out the current size in order to get the
+	 correct result.  */
+
+      BFD_ASSERT (h != NULL);
+
+      /* I think we *do* want to bypass this.  If we don't, I have seen some data
+	 parameters get the wrong relcation address.  If I link two versions
+	 with and without this section bypassed and then do a binary comparison,
+	 the addresses which are different can be looked up in the map.  The
+	 case in which this section has been bypassed has addresses which correspond
+	 to values I can find in the map.  */
+      *addendp -= sym->n_value;
+    }
+
+  /* If the output symbol is common (in which case this must be a
+     relocateable link), we need to add in the final size of the
+     common symbol.  */
+  if (h != NULL && h->root.type == bfd_link_hash_common)
+    *addendp += h->root.u.c.size;
+
+  return howto;
+}
+
+#define coff_rtype_to_howto coff_avr_rtype_to_howto
+
+#ifndef bfd_pe_print_pdata
+#define bfd_pe_print_pdata	NULL
+#endif
+
+#include "coffcode.h"
+
+static const bfd_target *
+coff_avr_object_p(a)
+     bfd *a;
+{
+  return coff_object_p (a);
+}
+
+/* Handle all the abominations of AVR COFF:
+
+   Generic COFF always uses the D1 slot to indicate the "most
+   important" derived type, and the D2...Dn slots for decreasing
+   importance.  E. g., a function symbol will always have its DT_FCN
+   element in D1, an array its DT_ARY (its first DT_ARY in a
+   multi-dimensional array).  In contrast, AVR COFF expects this most
+   important derived type specifier in the upmost Dn slot that is
+   allocated at all (i. e. that is != 0).
+
+   Generic COFF says that "Any symbol that satisfies more than one
+   condition [... for AUX entries] should have a union format in its
+   auxiliary entry."  AVR COFF uses sepearate AUX entries for multiple
+   derived types, and in some cases (like the ISFCN one), even puts
+   the most important one into the last allocated AUX entry.  We
+   join/split them here at the border as well.  Note that when
+   generating AUX entries (where we need to split them), the n_numaux
+   field must already have been set up properly (e. g. in
+   binutils/wrcoff.c) since the entry renumbering and pointerization
+   would not work otherwise.  Thus, we only split the information into
+   multiple records if n_numaux > 1.  For similar reasons, we keep
+   n_numaux > 1 on input to keep the appropriate AUX entries
+   allocated, so a symbol can be reconstructed if it is being passed
+   through one of the GNU tools.
+
+   Note that this adjustment is called after the symbol itself has
+   been swapped in, but before the AUX entries are swapped in.  This
+   is the only hook available that could swap (or merge) AUX entries
+   at all, so we have to operate on the external AUX entries still. */
+
+void
+avr_coff_adjust_sym_in_post (abfd, ext, in)
+     bfd *abfd;
+     PTR ext;
+     PTR in;
+{
+  struct internal_syment *dst = (struct internal_syment *)in;
+  unsigned short dt, bt, ndt;
+  dt = dst->n_type & ~N_BTMASK;
+  bt = BTYPE (dst->n_type);
+
+  /* Some AVR COFF producers seem to violate the COFF specs, and
+     produce symbols for tag names that have the C_FOO filled in
+     properly, but T_NULL as the base type value.  Patch up here,
+     since some of our generic COFF tools (in particular
+     binutils/rdcoff.c) rely on the correct data. */
+  if (bt == T_NULL)
+    switch (dst->n_sclass)
+      {
+      case C_STRTAG:
+	bt = T_STRUCT;
+	break;
+
+      case C_UNTAG:
+	bt = T_UNION;
+	break;
+
+      case C_ENTAG:
+	bt = T_ENUM;
+	break;
+      }
+
+  /* Swap the derived type slots. */
+  if (dt != 0)
+    {
+      ndt = 0;
+      while (dt != 0)
+	{
+	  ndt = (ndt << N_TSHIFT) | (dt & (N_TMASK >> N_BTSHFT));
+	  dt >>= N_TSHIFT;
+	}
+      dst->n_type = (ndt << N_BTSHFT) | bt;
+    }
+  else
+    dst->n_type = bt;
+
+  /* If the derived type is function, and there is more than one AUX
+     entry, swap the first and the last AUX entry, so the most
+     interesting one will become the first.
+
+     If the fundamental type is a tagged type (struct/union/enum), try
+     to find the AUX entry describing the tagged type (the one that
+     has x_sym.x_tagndx filled in), and merge the tag index into the
+     first AUX entry.  Depending on the actual input file, there might
+     be further DT_PTR entries which we just ignore, since we could
+     not handle that information anyway. */
+  if (dst->n_numaux > 1 && dst->n_sclass != C_FILE)
+    {
+      AUXENT caux, *auxp1, *auxp2;
+      size_t symesz;
+      unsigned int i;
+
+      symesz = bfd_coff_symesz (abfd);
+      i = dst->n_numaux;
+
+      auxp1 = (AUXENT *)((char *)ext + symesz);
+      auxp2 = (AUXENT *)((char *)ext + i * symesz);
+
+      if (ISFCN (dst->n_type)
+	  || (ISPTR(dst->n_type)
+	      && (bt == T_STRUCT || bt == T_UNION || bt == T_ENUM)))
+	{
+	  caux = *auxp2;
+	  *auxp2 = *auxp1;
+	  *auxp1 = caux;
+	}
+      else
+	caux = *auxp1;
+
+      if ((ISFCN (dst->n_type) || ISARY (dst->n_type))
+	  && (bt == T_STRUCT || bt == T_UNION || bt == T_ENUM))
+	{
+	  while (i > 1)
+	    {
+	      auxp2 = (AUXENT *)((char *)ext + i * symesz);
+
+	      if (auxp2->x_sym.x_tagndx[0] != 0 || auxp2->x_sym.x_tagndx[1] != 0
+		  || auxp2->x_sym.x_tagndx[2] != 0 || auxp2->x_sym.x_tagndx[3] != 0)
+		{
+		  memcpy (caux.x_sym.x_tagndx, auxp2->x_sym.x_tagndx,
+			  4 * sizeof (char));
+		  break;
+		}
+	      i--;
+	    }
+	  if (i > 1)
+	    *auxp1 = caux;
+	}
+    }
+}
+
+/* When exporting an AVR COFF file, just undo all that has been done
+   above.  Again, we are called after the symbol itself has been
+   swapped out, but before the AUX entries are being written.
+   Unfortunately, we are only given a pointer to the symbol itself, so
+   we have to derive the pointer to the respective aux entries from
+   that address, which is a bit clumsy. */
+void
+avr_coff_adjust_sym_out_post (abfd, in, ext)
+     bfd *abfd;
+     PTR in;
+     PTR ext;
+{
+  struct internal_syment *src = (struct internal_syment *)(in);
+  struct external_syment *dst = (struct external_syment *)(ext);
+  unsigned short dt, bt, ndt;
+
+  dt = src->n_type & ~N_BTMASK;
+  bt = BTYPE (src->n_type);
+
+  if (dt != 0)
+    {
+      ndt = 0;
+      while (dt != 0)
+	{
+	  ndt = (ndt << N_TSHIFT) | (dt & (N_TMASK >> N_BTSHFT));
+	  dt >>= N_TSHIFT;
+	}
+      H_PUT_16 (abfd, (ndt << N_BTSHFT) | bt, dst->e_type);
+    }
+
+  if (src->n_numaux > 1 && src->n_sclass != C_FILE)
+    {
+      combined_entry_type *srce, *dste;
+      char *hackp;
+      unsigned int i;
+
+      /* Recover the original combinend_entry_type *. */
+      hackp = (char *)in;
+      hackp -= offsetof(combined_entry_type, u.syment);
+      srce = (combined_entry_type *)hackp;
+      srce++;
+
+      /* We simply duplicate the first AUX entry as many times as
+	 needed.  Since COFF itself normally uses just a single AUX
+	 entry for all the information, this will work -- each COFF
+	 consumer will then just pick the fields it is particularly
+	 interested in.  This would not work for the AVR COFF specific
+	 DT_PTR AUX entries, but we don't support them anyway. */
+      for (i = 1; i < src->n_numaux; i++)
+	{
+	  dste = srce + i;
+	  *dste = *srce;
+	}
+    }
+}
+
+const bfd_target
+#ifdef TARGET_SYM
+  TARGET_SYM =
+#else
+  avrcoff_vec =
+#endif
+{
+#ifdef TARGET_NAME
+  TARGET_NAME,
+#else
+  "coff-avr",			/* name */
+#endif
+  bfd_target_coff_flavour,
+  BFD_ENDIAN_LITTLE,		/* data byte order is little */
+  BFD_ENDIAN_LITTLE,		/* header byte order is little */
+
+  (HAS_RELOC | EXEC_P |		/* object flags */
+   HAS_LINENO | HAS_DEBUG |
+   HAS_SYMS | HAS_LOCALS | WP_TEXT),
+
+  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+  0,				/* leading char */
+  '/',				/* ar_pad_char */
+  15,				/* ar_max_namelen */
+
+  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
+     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
+     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
+  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
+     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
+     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
+
+/* Note that we allow an object file to be treated as a core file as well.  */
+    {_bfd_dummy_target, coff_avr_object_p, /* bfd_check_format */
+       bfd_generic_archive_p, coff_avr_object_p},
+    {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
+       bfd_false},
+    {bfd_false, coff_write_object_contents, /* bfd_write_contents */
+       _bfd_write_archive_contents, bfd_false},
+
+     BFD_JUMP_TABLE_GENERIC (coff),
+     BFD_JUMP_TABLE_COPY (coff),
+     BFD_JUMP_TABLE_CORE (_bfd_nocore),
+     BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
+     BFD_JUMP_TABLE_SYMBOLS (coff),
+     BFD_JUMP_TABLE_RELOCS (coff),
+     BFD_JUMP_TABLE_WRITE (coff),
+     BFD_JUMP_TABLE_LINK (coff),
+     BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
+
+  NULL,
+
+  COFF_SWAP_TABLE
+};
diff --git a/bfd/coff-ext-avr.c b/bfd/coff-ext-avr.c
new file mode 100644
index 0000000..717ef8e
--- /dev/null
+++ b/bfd/coff-ext-avr.c
@@ -0,0 +1,428 @@
+/* BFD back-end for Atmel AVR "extended" COFF files.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
+   Free Software Foundation, Inc.
+   This is mostly the same as avr-coff, except of the presence of the
+   COFF optional header.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+
+#define AVR_EXT_COFF 1
+#include "coff/avr.h"
+
+#include "coff/internal.h"
+
+#include "libcoff.h"
+
+static bfd_reloc_status_type coff_ext_avr_reloc
+  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+static reloc_howto_type *coff_ext_avr_rtype_to_howto
+  PARAMS ((bfd *, asection *, struct internal_reloc *,
+	   struct coff_link_hash_entry *, struct internal_syment *,
+	   bfd_vma *));
+static const bfd_target * coff_ext_avr_object_p PARAMS ((bfd *));
+
+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
+/* The page size is a guess based on ELF.  */
+
+#define COFF_PAGE_SIZE 0x1000
+
+/* For some reason when using avr COFF the value stored in the .text
+   section for a reference to a common symbol is the value itself plus
+   any desired offset.  Ian Taylor, Cygnus Support.  */
+
+/* If we are producing relocateable output, we need to do some
+   adjustments to the object file that are not done by the
+   bfd_perform_relocation function.  This function is called by every
+   reloc type to make any required adjustments.  */
+
+static bfd_reloc_status_type
+coff_ext_avr_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
+		 error_message)
+     bfd *abfd;
+     arelent *reloc_entry;
+     asymbol *symbol;
+     PTR data;
+     asection *input_section ATTRIBUTE_UNUSED;
+     bfd *output_bfd;
+     char **error_message ATTRIBUTE_UNUSED;
+{
+  symvalue diff;
+
+  if (output_bfd == (bfd *) NULL)
+    return bfd_reloc_continue;
+
+  if (bfd_is_com_section (symbol->section))
+    {
+      /* We are relocating a common symbol.  The current value in the
+	 object file is ORIG + OFFSET, where ORIG is the value of the
+	 common symbol as seen by the object file when it was compiled
+	 (this may be zero if the symbol was undefined) and OFFSET is
+	 the offset into the common symbol (normally zero, but may be
+	 non-zero when referring to a field in a common structure).
+	 ORIG is the negative of reloc_entry->addend, which is set by
+	 the CALC_ADDEND macro below.  We want to replace the value in
+	 the object file with NEW + OFFSET, where NEW is the value of
+	 the common symbol which we are going to put in the final
+	 object file.  NEW is symbol->value.  */
+      diff = symbol->value + reloc_entry->addend;
+    }
+  else
+    {
+      /* For some reason bfd_perform_relocation always effectively
+	 ignores the addend for a COFF target when producing
+	 relocateable output.  This seems to be always wrong for 860
+	 COFF, so we handle the addend here instead.  */
+      diff = reloc_entry->addend;
+    }
+
+#define DOIT(x) \
+  x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
+
+    if (diff != 0)
+      {
+	reloc_howto_type *howto = reloc_entry->howto;
+	unsigned char *addr = (unsigned char *) data + reloc_entry->address;
+
+	switch (howto->size)
+	  {
+	  case 0:
+	    {
+	      char x = bfd_get_8 (abfd, addr);
+	      DOIT (x);
+	      bfd_put_8 (abfd, x, addr);
+	    }
+	    break;
+
+	  case 1:
+	    {
+	      short x = bfd_get_16 (abfd, addr);
+	      DOIT (x);
+	      bfd_put_16 (abfd, (bfd_vma) x, addr);
+	    }
+	    break;
+
+	  case 2:
+	    {
+	      long x = bfd_get_32 (abfd, addr);
+	      DOIT (x);
+	      bfd_put_32 (abfd, (bfd_vma) x, addr);
+	    }
+	    break;
+
+	  default:
+	    abort ();
+	  }
+      }
+
+  /* Now let bfd_perform_relocation finish everything up.  */
+  return bfd_reloc_continue;
+}
+
+#ifndef PCRELOFFSET
+#define PCRELOFFSET FALSE
+#endif
+
+static reloc_howto_type howto_table[] =
+{
+  EMPTY_HOWTO (0),
+  EMPTY_HOWTO (1),
+  EMPTY_HOWTO (2),
+  EMPTY_HOWTO (3),
+  EMPTY_HOWTO (4),
+  EMPTY_HOWTO (5),
+  HOWTO (R_DIR32,               /* type */
+	 0,	                /* rightshift */
+	 2,	                /* size (0 = byte, 1 = short, 2 = long) */
+	 32,	                /* bitsize */
+	 FALSE,	                /* pc_relative */
+	 0,	                /* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_ext_avr_reloc,       /* special_function */
+	 "dir32",               /* name */
+	 TRUE,	                /* partial_inplace */
+	 0xffffffff,            /* src_mask */
+	 0xffffffff,            /* dst_mask */
+	 TRUE),                /* pcrel_offset */
+  /* {7}, */
+  HOWTO (R_IMAGEBASE,            /* type */
+	 0,	                /* rightshift */
+	 2,	                /* size (0 = byte, 1 = short, 2 = long) */
+	 32,	                /* bitsize */
+	 FALSE,	                /* pc_relative */
+	 0,	                /* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_ext_avr_reloc,       /* special_function */
+	 "rva32",	           /* name */
+	 TRUE,	                /* partial_inplace */
+	 0xffffffff,            /* src_mask */
+	 0xffffffff,            /* dst_mask */
+	 FALSE),                /* pcrel_offset */
+  EMPTY_HOWTO (010),
+  EMPTY_HOWTO (011),
+  EMPTY_HOWTO (012),
+  EMPTY_HOWTO (013),
+  EMPTY_HOWTO (014),
+  EMPTY_HOWTO (015),
+  EMPTY_HOWTO (016),
+  HOWTO (R_RELBYTE,		/* type */
+	 0,			/* rightshift */
+	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+	 8,			/* bitsize */
+	 FALSE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_ext_avr_reloc,	/* special_function */
+	 "8",			/* name */
+	 TRUE,			/* partial_inplace */
+	 0x000000ff,		/* src_mask */
+	 0x000000ff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_RELWORD,		/* type */
+	 0,			/* rightshift */
+	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+	 16,			/* bitsize */
+	 FALSE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_ext_avr_reloc,	/* special_function */
+	 "16",			/* name */
+	 TRUE,			/* partial_inplace */
+	 0x0000ffff,		/* src_mask */
+	 0x0000ffff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_RELLONG,		/* type */
+	 0,			/* rightshift */
+	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+	 32,			/* bitsize */
+	 FALSE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_bitfield, /* complain_on_overflow */
+	 coff_ext_avr_reloc,	/* special_function */
+	 "32",			/* name */
+	 TRUE,			/* partial_inplace */
+	 0xffffffff,		/* src_mask */
+	 0xffffffff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_PCRBYTE,		/* type */
+	 0,			/* rightshift */
+	 0,			/* size (0 = byte, 1 = short, 2 = long) */
+	 8,			/* bitsize */
+	 TRUE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_signed, /* complain_on_overflow */
+	 coff_ext_avr_reloc,	/* special_function */
+	 "DISP8",		/* name */
+	 TRUE,			/* partial_inplace */
+	 0x000000ff,		/* src_mask */
+	 0x000000ff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_PCRWORD,		/* type */
+	 0,			/* rightshift */
+	 1,			/* size (0 = byte, 1 = short, 2 = long) */
+	 16,			/* bitsize */
+	 TRUE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_signed, /* complain_on_overflow */
+	 coff_ext_avr_reloc,	/* special_function */
+	 "DISP16",		/* name */
+	 TRUE,			/* partial_inplace */
+	 0x0000ffff,		/* src_mask */
+	 0x0000ffff,		/* dst_mask */
+	 PCRELOFFSET),		/* pcrel_offset */
+  HOWTO (R_PCRLONG,		/* type */
+	 0,			/* rightshift */
+	 2,			/* size (0 = byte, 1 = short, 2 = long) */
+	 32,			/* bitsize */
+	 TRUE,			/* pc_relative */
+	 0,			/* bitpos */
+	 complain_overflow_signed, /* complain_on_overflow */
+	 coff_ext_avr_reloc,	/* special_function */
+	 "DISP32",		/* name */
+	 TRUE,			/* partial_inplace */
+	 0xffffffff,		/* src_mask */
+	 0xffffffff,		/* dst_mask */
+	 PCRELOFFSET)		/* pcrel_offset */
+};
+
+/* Turn a howto into a reloc  nunmber */
+
+#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
+#define BADMAG(x) AVRBADMAG(x)
+#define AVR 1			/* Customize coffcode.h */
+
+#define RTYPE2HOWTO(cache_ptr, dst) \
+	    (cache_ptr)->howto = howto_table + (dst)->r_type;
+
+/* For AVR COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
+   library.  On some other COFF targets STYP_BSS is normally
+   STYP_NOLOAD.  */
+#define BSS_NOLOAD_IS_SHARED_LIBRARY
+
+/* Compute the addend of a reloc.  If the reloc is to a common symbol,
+   the object file contains the value of the common symbol.  By the
+   time this is called, the linker may be using a different symbol
+   from a different object file with a different value.  Therefore, we
+   hack wildly to locate the original symbol from this file so that we
+   can make the correct adjustment.  This macro sets coffsym to the
+   symbol from the original file, and uses it to set the addend value
+   correctly.  If this is not a common symbol, the usual addend
+   calculation is done, except that an additional tweak is needed for
+   PC relative relocs.
+   FIXME: This macro refers to symbols and asect; these are from the
+   calling function, not the macro arguments.  */
+
+#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)		\
+  {								\
+    coff_symbol_type *coffsym = (coff_symbol_type *) NULL;	\
+    if (ptr && bfd_asymbol_bfd (ptr) != abfd)			\
+      coffsym = (obj_symbols (abfd)				\
+	         + (cache_ptr->sym_ptr_ptr - symbols));		\
+    else if (ptr)						\
+      coffsym = coff_symbol_from (abfd, ptr);			\
+    if (coffsym != (coff_symbol_type *) NULL			\
+	&& coffsym->native->u.syment.n_scnum == 0)		\
+      cache_ptr->addend = - coffsym->native->u.syment.n_value;	\
+    else if (ptr && bfd_asymbol_bfd (ptr) == abfd		\
+	     && ptr->section != (asection *) NULL)		\
+      cache_ptr->addend = - (ptr->section->vma + ptr->value);	\
+    else							\
+      cache_ptr->addend = 0;					\
+    if (ptr && howto_table[reloc.r_type].pc_relative)		\
+      cache_ptr->addend += asect->vma;				\
+  }
+
+/* We use the special COFF backend linker.  */
+#define coff_relocate_section _bfd_coff_generic_relocate_section
+
+static reloc_howto_type *
+coff_ext_avr_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     asection *sec;
+     struct internal_reloc *rel;
+     struct coff_link_hash_entry *h;
+     struct internal_syment *sym;
+     bfd_vma *addendp;
+{
+
+  reloc_howto_type *howto;
+
+  howto = howto_table + rel->r_type;
+
+  if (howto->pc_relative)
+    *addendp += sec->vma;
+
+  if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
+    {
+      /* This is a common symbol.  The section contents include the
+	 size (sym->n_value) as an addend.  The relocate_section
+	 function will be adding in the final value of the symbol.  We
+	 need to subtract out the current size in order to get the
+	 correct result.  */
+
+      BFD_ASSERT (h != NULL);
+
+      /* I think we *do* want to bypass this.  If we don't, I have seen some data
+	 parameters get the wrong relcation address.  If I link two versions
+	 with and without this section bypassed and then do a binary comparison,
+	 the addresses which are different can be looked up in the map.  The
+	 case in which this section has been bypassed has addresses which correspond
+	 to values I can find in the map.  */
+      *addendp -= sym->n_value;
+    }
+
+  /* If the output symbol is common (in which case this must be a
+     relocateable link), we need to add in the final size of the
+     common symbol.  */
+  if (h != NULL && h->root.type == bfd_link_hash_common)
+    *addendp += h->root.u.c.size;
+
+  return howto;
+}
+
+#define coff_rtype_to_howto coff_ext_avr_rtype_to_howto
+
+#ifndef bfd_pe_print_pdata
+#define bfd_pe_print_pdata	NULL
+#endif
+
+#include "coffcode.h"
+
+static const bfd_target *
+coff_ext_avr_object_p(a)
+     bfd *a;
+{
+  return coff_object_p (a);
+}
+
+const bfd_target
+#ifdef TARGET_SYM
+  TARGET_SYM =
+#else
+  avrextcoff_vec =
+#endif
+{
+#ifdef TARGET_NAME
+  TARGET_NAME,
+#else
+  "coff-ext-avr",			/* name */
+#endif
+  bfd_target_coff_flavour,
+  BFD_ENDIAN_LITTLE,		/* data byte order is little */
+  BFD_ENDIAN_LITTLE,		/* header byte order is little */
+
+  (HAS_RELOC | EXEC_P |		/* object flags */
+   HAS_LINENO | HAS_DEBUG |
+   HAS_SYMS | HAS_LOCALS | WP_TEXT),
+
+  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+  0,				/* leading char */
+  '/',				/* ar_pad_char */
+  15,				/* ar_max_namelen */
+
+  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
+     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
+     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
+  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
+     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
+     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
+
+/* Note that we allow an object file to be treated as a core file as well.  */
+    {_bfd_dummy_target, coff_ext_avr_object_p, /* bfd_check_format */
+       bfd_generic_archive_p, coff_ext_avr_object_p},
+    {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
+       bfd_false},
+    {bfd_false, coff_write_object_contents, /* bfd_write_contents */
+       _bfd_write_archive_contents, bfd_false},
+
+     BFD_JUMP_TABLE_GENERIC (coff),
+     BFD_JUMP_TABLE_COPY (coff),
+     BFD_JUMP_TABLE_CORE (_bfd_nocore),
+     BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
+     BFD_JUMP_TABLE_SYMBOLS (coff),
+     BFD_JUMP_TABLE_RELOCS (coff),
+     BFD_JUMP_TABLE_WRITE (coff),
+     BFD_JUMP_TABLE_LINK (coff),
+     BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
+
+  NULL,
+
+  COFF_SWAP_TABLE
+};
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 3beedef..0f8eed2 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -1,3 +1,4 @@
+
 /* Support for the generic parts of most COFF variants, for BFD.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
@@ -1910,6 +1911,17 @@ coff_mkobject (bfd * abfd)
   coff->relocbase = 0;
   coff->local_toc_sym_map = 0;
 
+  /* These members communicate important constants about the symbol
+     table to GDB's symbol-reading code.  These `constants'
+     unfortunately vary among coff implementations...  */
+  coff->local_n_btmask = N_BTMASK;
+  coff->local_n_btshft = N_BTSHFT;
+  coff->local_n_tmask = N_TMASK;
+  coff->local_n_tshift = N_TSHIFT;
+  coff->local_symesz = bfd_coff_symesz (abfd);
+  coff->local_auxesz = bfd_coff_auxesz (abfd);
+  coff->local_linesz = bfd_coff_linesz (abfd);
+
 /*  make_abs_section(abfd);*/
 
   return TRUE;
@@ -1934,17 +1946,6 @@ coff_mkobject_hook (bfd * abfd,
 
   coff->sym_filepos = internal_f->f_symptr;
 
-  /* These members communicate important constants about the symbol
-     table to GDB's symbol-reading code.  These `constants'
-     unfortunately vary among coff implementations...  */
-  coff->local_n_btmask = N_BTMASK;
-  coff->local_n_btshft = N_BTSHFT;
-  coff->local_n_tmask = N_TMASK;
-  coff->local_n_tshift = N_TSHIFT;
-  coff->local_symesz = bfd_coff_symesz (abfd);
-  coff->local_auxesz = bfd_coff_auxesz (abfd);
-  coff->local_linesz = bfd_coff_linesz (abfd);
-
   coff->timestamp = internal_f->f_timdat;
 
   obj_raw_syment_count (abfd) =
@@ -2076,6 +2077,11 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
 	}
       break;
 #endif
+#ifdef AVRMAGIC
+    case AVRMAGIC:
+      arch = bfd_arch_avr;
+      break;
+#endif
 #ifdef MC68MAGIC
     case MC68MAGIC:
     case M68MAGIC:
@@ -2871,6 +2877,13 @@ coff_set_flags (bfd * abfd,
       return TRUE;
 #endif
 
+#ifdef AVRMAGIC
+    case bfd_arch_avr:
+      *magicp = AVRMAGIC;
+      return TRUE;
+      break;
+#endif
+
 #ifdef PPCMAGIC
     case bfd_arch_powerpc:
       *magicp = PPCMAGIC;
@@ -3698,6 +3711,11 @@ coff_write_object_contents (bfd * abfd)
       section.s_page = 0;
 #endif
 
+#ifdef AVR
+      /* AVR uses s_paddr the way GNU uses s_vaddr, and effectively
+	 ignores s_vaddr. */
+      section.s_paddr = current->vma;
+#endif
 #ifdef COFF_WITH_PE
       section.s_paddr = 0;
 #endif
@@ -4042,6 +4060,17 @@ coff_write_object_contents (bfd * abfd)
     internal_a.magic = ZMAGIC;
 #endif
 
+#ifdef AVR
+    /* a.out is a dummy for non-extended COFF */
+    internal_a.magic = AVRAOUTMAGIC;
+    /* Upper nibble of f_flags must be set for historical reasons.
+       The upper byte remains blank on coff-avr, so undo the F_AR32WR
+       setting performed above. */
+    internal_f.f_flags |= F_JUNK;
+    internal_f.f_flags &= ~F_UNUSED;
+#define __A_MAGIC_SET__
+#endif /* AVR */
+
 #if defined(PPC_PE)
 #define __A_MAGIC_SET__
     internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
@@ -4109,8 +4138,16 @@ coff_write_object_contents (bfd * abfd)
 #endif
   }
 
+#ifdef AVR_EXT_COFF
+    /* Note that we do not set F_PTRINFO because the GNU toolchain
+       doesn't provide any information about the target of a pointer,
+       so we cannot derive which section our pointer target would be
+       in. */
+  internal_a.vstamp = F_FULLPATHS | F_STRUCTINFO;
+#else
   /* FIXME: Does anybody ever set this to another value?  */
   internal_a.vstamp = 0;
+#endif
 
   /* Now should write relocs, strings, syms.  */
   obj_sym_filepos (abfd) = sym_base;
@@ -4668,6 +4705,10 @@ coff_slurp_symbol_table (bfd * abfd)
 	    /* In PE, 0x69 (105) denotes a weak external symbol.  */
 	    case C_NT_WEAK:
 #endif
+#ifdef AVR
+	    /* Some AVR COFF compilers handle EXTDEF like EXT. */
+	    case C_EXTDEF:	/* external definition		 */
+#endif
 	      switch (coff_classify_symbol (abfd, &src->u.syment))
 		{
 		case COFF_SYMBOL_GLOBAL:
@@ -4891,7 +4932,9 @@ coff_slurp_symbol_table (bfd * abfd)
 		  && src->u.syment.n_scnum == 0)
 		break;
 	      /* Fall through.  */
+#if !defined(AVR)
 	    case C_EXTDEF:	/* External definition.  */
+#endif
 	    case C_ULABEL:	/* Undefined label.  */
 	    case C_USTATIC:	/* Undefined static.  */
 #ifndef COFF_WITH_PE
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 5f6921d..d521643 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -699,6 +699,20 @@ coff_renumber_symbols (bfd *bfd_ptr, int *first_undef)
 	      if (last_file != NULL)
 		last_file->n_value = native_index;
 	      last_file = &(s->u.syment);
+	      if (bfd_get_arch (bfd_ptr) == bfd_arch_avr
+		  && bfd_coff_long_filenames (bfd_ptr)
+		  && s->u.syment.n_numaux > 0)
+		{
+		  /* AVR COFF records long filenames in successive aux
+		     records.  Adjust the number of aux records
+		     required here, so the renumbering will account
+		     for them. */
+		  unsigned int filnmlen = bfd_coff_filnmlen (bfd_ptr);
+		  unsigned int namelen = strlen (coff_symbol_ptr->symbol.name);
+		  unsigned int n = (namelen + filnmlen - 1) / filnmlen;
+
+		  s->u.syment.n_numaux = n > NAUXENTS? NAUXENTS: n;
+		}
 	    }
 	  else
 	    /* Modify the symbol values according to their section and
@@ -827,6 +841,20 @@ coff_fix_symbol_name (bfd *abfd,
 	{
 	  if (name_length <= filnmlen)
 	    strncpy (auxent->x_file.x_fname, name, filnmlen);
+	  else if (bfd_get_arch (abfd) == bfd_arch_avr)
+	    {
+	      /* AVR COFF records long filenames in successive aux records. */
+	      int i = 1;
+	      while (name_length > filnmlen && i < NAUXENTS)
+		{
+		  strncpy (auxent->x_file.x_fname, name, filnmlen);
+		  name += filnmlen;
+		  name_length -= filnmlen;
+		  i++;
+		  auxent = &(native + i)->u.auxent;
+		}
+	      strncpy (auxent->x_file.x_fname, name, filnmlen);
+	    }
 	  else
 	    {
 	      auxent->x_file.x_n.x_offset = *string_size_p + STRING_SIZE_SIZE;
@@ -1272,6 +1300,10 @@ coff_write_symbols (bfd *abfd)
 		  if (bfd_bwrite (".file", (bfd_size_type) 6, abfd) != 6)
 		    return FALSE;
 		}
+	      if (bfd_get_arch (abfd) == bfd_arch_avr)
+		/* AVR COFF handles long file names in aux records. */
+		maxlen = name_length;
+	      else
 	      maxlen = bfd_coff_filnmlen (abfd);
 	    }
 	  else
@@ -1710,14 +1742,27 @@ coff_get_normalized_symtab (bfd *abfd)
 	    {
 	      /* Ordinary short filename, put into memory anyway.  The
                  Microsoft PE tools sometimes store a filename in
-                 multiple AUX entries.  */
+                 multiple AUX entries.
+		 AVR COFF does it that way, too. */
 	      if (internal_ptr->u.syment.n_numaux > 1
-		  && coff_data (abfd)->pe)
-		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((bfd_hostptr_t)
-		   copy_name (abfd,
-			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
-			      internal_ptr->u.syment.n_numaux * symesz));
+		  && (coff_data (abfd)->pe
+		      || (bfd_get_arch (abfd) == bfd_arch_avr)))
+		{
+		  char *b;
+		  unsigned int i;
+
+		  /* We allocate enough storage to fit the contents of
+		     this many aux records, and simply append a \0.
+		     This ensures the string will always be
+		     terminated, even in the case where it just fit
+		     into the aux records. */
+		  b = (char *) bfd_alloc (abfd,
+					  internal_ptr->u.syment.n_numaux * FILNMLEN + 1);
+		  internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t) b;
+		  b[internal_ptr->u.syment.n_numaux * FILNMLEN] = '\0';
+		  for (i = 0; i < internal_ptr->u.syment.n_numaux; i++, b += FILNMLEN)
+		    memcpy (b, (internal_ptr + i + 1)->u.auxent.x_file.x_fname, FILNMLEN);
+		}
 	      else
 		internal_ptr->u.syment._n._n_n._n_offset =
 		  ((bfd_hostptr_t)
@@ -1823,9 +1868,9 @@ coff_bfd_make_debug_symbol (bfd *abfd,
 
   if (new_symbol == NULL)
     return NULL;
-  /* @@ The 10 is a guess at a plausible maximum number of aux entries
+  /* @@ The NAUXENTS is a guess at a plausible maximum number of aux entries
      (but shouldn't be a constant).  */
-  amt = sizeof (combined_entry_type) * 10;
+  amt = sizeof (combined_entry_type) * (NAUXENTS + 1);
   new_symbol->native = (combined_entry_type *) bfd_zalloc (abfd, amt);
   if (!new_symbol->native)
     return NULL;
diff --git a/bfd/coffswap.h b/bfd/coffswap.h
index 674fdc7..785f7da 100644
--- a/bfd/coffswap.h
+++ b/bfd/coffswap.h
@@ -383,7 +383,11 @@ coff_swap_aux_in (bfd *abfd,
 		  void * ext1,
 		  int type,
 		  int in_class,
-		  int indx,
+		  int indx
+#if defined(AVR) && __GNUC__
+                __attribute__((unused))
+#endif
+		  ,
 		  int numaux,
 		  void * in1)
 {
@@ -409,9 +413,13 @@ coff_swap_aux_in (bfd *abfd,
 #else
 	  if (numaux > 1)
 	    {
+#if defined(AVR)
+	      memcpy (in->x_file.x_fname, ext->x_file.x_fname, sizeof (AUXENT));
+#else
 	      if (indx == 0)
 		memcpy (in->x_file.x_fname, ext->x_file.x_fname,
 			numaux * sizeof (AUXENT));
+#endif
 	    }
 	  else
 	    memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
diff --git a/bfd/config.bfd b/bfd/config.bfd
index e340251..7310224 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -339,6 +339,7 @@ case "${targ}" in
 
   avr-*-*)
     targ_defvec=bfd_elf32_avr_vec
+    targ_selvecs="bfd_elf32_avr_vec avrcoff_vec avrextcoff_vec"
     ;;
 
   bfin-*-*)
diff --git a/bfd/configure b/bfd/configure
index 6502be6..b836006 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -14782,6 +14782,8 @@ do
     armpe_little_vec)		tb="$tb pe-arm.lo peigen.lo cofflink.lo " ;;
     armpei_big_vec)		tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
     armpei_little_vec)		tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
+    avrcoff_vec)		tb="$tb coff-avr.lo cofflink.lo " ;;
+    avrextcoff_vec)		tb="$tb coff-ext-avr.lo cofflink.lo " ;;
     b_out_vec_big_host)		tb="$tb bout.lo aout32.lo" ;;
     b_out_vec_little_host)	tb="$tb bout.lo aout32.lo" ;;
     bfd_pei_ia64_vec)		tb="$tb pei-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
diff --git a/bfd/configure.in b/bfd/configure.in
index e39187d..154b4a9 100644
--- a/bfd/configure.in
+++ b/bfd/configure.in
@@ -670,6 +670,8 @@ do
     armpe_little_vec)		tb="$tb pe-arm.lo peigen.lo cofflink.lo " ;;
     armpei_big_vec)		tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
     armpei_little_vec)		tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
+    avrcoff_vec)		tb="$tb coff-avr.lo cofflink.lo " ;;
+    avrextcoff_vec)		tb="$tb coff-ext-avr.lo cofflink.lo " ;;
     b_out_vec_big_host)		tb="$tb bout.lo aout32.lo" ;;
     b_out_vec_little_host)	tb="$tb bout.lo aout32.lo" ;;
     bfd_pei_ia64_vec)		tb="$tb pei-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
diff --git a/bfd/targets.c b/bfd/targets.c
index a33790b..9d2964e 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -564,6 +564,8 @@ extern const bfd_target armpe_big_vec;
 extern const bfd_target armpe_little_vec;
 extern const bfd_target armpei_big_vec;
 extern const bfd_target armpei_little_vec;
+extern const bfd_target avrcoff_vec;
+extern const bfd_target avrextcoff_vec;
 extern const bfd_target b_out_vec_big_host;
 extern const bfd_target b_out_vec_little_host;
 extern const bfd_target bfd_pei_ia64_vec;
@@ -890,6 +892,8 @@ static const bfd_target * const _bfd_target_vector[] =
 	&armpe_little_vec,
 	&armpei_big_vec,
 	&armpei_little_vec,
+	&avrcoff_vec,
+	&avrextcoff_vec,
 	&b_out_vec_big_host,
 	&b_out_vec_little_host,
 #ifdef BFD64
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index db7a773..ace3138 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -101,7 +101,7 @@ CFILES = \
 	resbin.c rescoff.c resrc.c resres.c \
 	size.c srconv.c stabs.c strings.c sysdump.c \
 	unwind-ia64.c version.c \
-	windres.c winduni.c wrstabs.c \
+	windres.c winduni.c wrcoff.c wrstabs.c \
 	windmc.c mclex.c
 
 GENERATED_CFILES = \
@@ -109,7 +109,7 @@ GENERATED_CFILES = \
 	defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
 
 DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
-WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
+WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c wrcoff.c
 
 # Code shared by all the binutils.
 BULIBS = bucomm.c version.c filemode.c
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index ab0c1a6..3353fcc 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -126,7 +126,7 @@ am_nm_new_OBJECTS = nm.$(OBJEXT) $(am__objects_1)
 nm_new_OBJECTS = $(am_nm_new_OBJECTS)
 nm_new_LDADD = $(LDADD)
 am__objects_2 = rddbg.$(OBJEXT) debug.$(OBJEXT) stabs.$(OBJEXT) \
-	ieee.$(OBJEXT) rdcoff.$(OBJEXT)
+	ieee.$(OBJEXT) rdcoff.$(OBJEXT) wrcoff.$(OBJEXT)
 am__objects_3 = $(am__objects_2) wrstabs.$(OBJEXT)
 am_objcopy_OBJECTS = objcopy.$(OBJEXT) not-strip.$(OBJEXT) \
 	rename.$(OBJEXT) $(am__objects_3) $(am__objects_1)
@@ -439,7 +439,7 @@ CFILES = \
 	resbin.c rescoff.c resrc.c resres.c \
 	size.c srconv.c stabs.c strings.c sysdump.c \
 	unwind-ia64.c version.c \
-	windres.c winduni.c wrstabs.c \
+	windres.c winduni.c wrcoff.c wrstabs.c \
 	windmc.c mclex.c
 
 GENERATED_CFILES = \
@@ -447,7 +447,7 @@ GENERATED_CFILES = \
 	defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
 
 DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
-WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
+WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c wrcoff.c
 
 # Code shared by all the binutils.
 BULIBS = bucomm.c version.c filemode.c
diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index e006e61..094d3e3 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -550,6 +550,32 @@ parse_vma (const char *s, const char *arg)
   return ret;
 }
 
+/* Return the basename of "file", i. e. everything minus whatever
+   directory part has been provided.  Stolen from bfd/archive.c.
+   Should we also handle the VMS case (as in bfd/archive.c)?  */
+const char *
+bu_basename (file)
+     const char *file;
+{
+  const char *filename = strrchr (file, '/');
+
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  {
+    /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
+    char *bslash = strrchr (file, '\\');
+    if (filename == NULL || (bslash != NULL && bslash > filename))
+      filename = bslash;
+    if (filename == NULL && file[0] != '\0' && file[1] == ':')
+      filename = file + 1;
+  }
+#endif
+  if (filename != (char *) NULL)
+    filename++;
+  else
+    filename = file;
+  return filename;
+}
+
 /* Returns the size of the named file.  If the file does not
    exist, or if it is not a real file, then a suitable non-fatal
    error message is printed and zero is returned.  */
diff --git a/binutils/bucomm.h b/binutils/bucomm.h
index fcbc32b..3255d52 100644
--- a/binutils/bucomm.h
+++ b/binutils/bucomm.h
@@ -58,6 +58,8 @@ bfd_vma parse_vma (const char *, const char *);
 
 off_t get_file_size (const char *);
 
+const char *bu_basename PARAMS ((const char *));
+
 extern char *program_name;
 
 /* filemode.c */
diff --git a/binutils/budbg.h b/binutils/budbg.h
index b9de022..1bab100 100644
--- a/binutils/budbg.h
+++ b/binutils/budbg.h
@@ -52,8 +52,11 @@ extern bfd_boolean parse_ieee (void *, bfd *, const bfd_byte *, bfd_size_type);
 
 extern bfd_boolean write_ieee_debugging_info (bfd *, void *);
 
-/* Routine used to read COFF debugging information.  */
+/* Routine used to read and write COFF debugging information.  */
 
 extern bfd_boolean parse_coff (bfd *, asymbol **, long, void *);
 
+extern bfd_boolean write_coff_debugging_info
+  (bfd *abfd, void *, long *symcountp, asymbol ***);
+
 #endif
diff --git a/binutils/debug.c b/binutils/debug.c
index 57f5a2d..e4becfe 100644
--- a/binutils/debug.c
+++ b/binutils/debug.c
@@ -31,6 +31,7 @@
 #include <assert.h>
 #include "bfd.h"
 #include "libiberty.h"
+#include "bucomm.h"
 #include "debug.h"
 
 /* Global information we keep for debugging.  A pointer to this
@@ -552,6 +553,19 @@ struct debug_type_real_list
   struct debug_type_s *t;
 };
 
+/* Simple list, used for pathname translations. */
+struct xlat_list
+{
+  /* Next string on list. */
+  struct xlat_list *next;
+  /* Old part to match against. */
+  const char *old;
+  size_t olen;
+  /* New part to replace. */
+  const char *newstr;
+  size_t nlen;
+};
+
 /* Local functions.  */
 
 static void debug_error (const char *);
@@ -588,6 +602,11 @@ static bfd_boolean debug_type_samep
   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
 static bfd_boolean debug_class_type_samep
   (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
+static const char *debug_xlat_pathname (const char *);
+
+/* List of pathname translations. */
+static struct xlat_list *xlat, *xltail;
+static bfd_boolean xlat_basename;
 
 /* Issue an error message.  */
 
@@ -680,6 +699,8 @@ debug_set_filename (void *handle, const char *name)
 
   if (name == NULL)
     name = "";
+  else
+    name = debug_xlat_pathname (name);
 
   nfile = (struct debug_file *) xmalloc (sizeof *nfile);
   memset (nfile, 0, sizeof *nfile);
@@ -720,6 +741,8 @@ debug_start_source (void *handle, const char *name)
 
   if (name == NULL)
     name = "";
+  else
+    name = debug_xlat_pathname (name);
 
   if (info->current_unit == NULL)
     {
@@ -3370,3 +3393,69 @@ debug_class_type_samep (struct debug_handle *info, struct debug_type_s *t1,
 
   return TRUE;
 }
+
+/* Register a pathname translation. */
+void
+debug_register_pathname_xlat (oname, nname)
+     const char *oname;
+     const char *nname;
+{
+  struct xlat_list *xlp;
+
+  /* Special case: if oname is given as NULL, this means the
+     --basename option has been given to objcopy. */
+  if (oname == NULL)
+    {
+      xlat_basename = TRUE;
+      return;
+    }
+
+  xlp = (struct xlat_list *) xmalloc (sizeof (struct xlat_list));
+  xlp->next = NULL;
+  if (xlat == NULL)
+    xlat = xltail = xlp;
+  else
+    {
+      xltail->next = xlp;
+      xltail = xlp;
+    }
+  xlp->old = oname;
+  xlp->newstr = nname;
+  xlp->olen = strlen (oname);
+  xlp->nlen = strlen (nname);
+}
+
+/* Try to translate a pathname. */
+static const char *
+debug_xlat_pathname (oname)
+     const char *oname;
+{
+  struct xlat_list *xlp;
+  char *cp;
+  size_t olen;
+
+  if (xlat_basename)
+    return bu_basename (oname);
+
+  olen = strlen (oname);
+  for (xlp = xlat; xlp; xlp = xlp->next)
+    {
+      if (xlp->olen > olen)
+	/* This cannot be our turn. */
+	continue;
+      /* Since we have pre-computed all our length values to avoid
+	 repetitively computing them, just use memcmp() since it's
+	 faster than strcmp(). */
+      if (memcmp (xlp->old, oname, xlp->olen) == 0)
+	{
+	  cp = (char *) xmalloc (olen + xlp->nlen - xlp->olen + 1);
+	  memcpy (cp, xlp->newstr, xlp->nlen);
+	  memcpy (cp + xlp->nlen, oname + xlp->olen,
+		  olen - xlp->olen + 1);
+	  return cp;
+	}
+    }
+
+  /* Not found, pass the original name on. */
+  return oname;
+}
diff --git a/binutils/debug.h b/binutils/debug.h
index 3ba344c..e19cb07 100644
--- a/binutils/debug.h
+++ b/binutils/debug.h
@@ -440,6 +440,12 @@ extern bfd_boolean debug_set_filename (void *, const char *);
 
 extern bfd_boolean debug_start_source (void *, const char *);
 
+/* Register a pathname translation for source (and include) filenames.
+   This is used by the --change-pathname option of objcopy. */
+
+extern void debug_register_pathname_xlat
+  PARAMS ((const char *, const char *));
+
 /* Record a function definition.  This implicitly starts a function
    block.  The debug_type argument is the type of the return value.
    The bfd_boolean indicates whether the function is globally visible.
diff --git a/binutils/doc/objcopy.1 b/binutils/doc/objcopy.1
index cc041c0..5714f0d 100644
--- a/binutils/doc/objcopy.1
+++ b/binutils/doc/objcopy.1
@@ -202,6 +202,8 @@ objcopy [\fB\-F\fR \fIbfdname\fR|\fB\-\-target=\fR\fIbfdname\fR]
         [\fB\-\-readonly\-text\fR]
         [\fB\-\-pure\fR]
         [\fB\-\-impure\fR]
+	[\fB\-\-change\-pathname\fR \fIold\fR=\fInew\fR]
+	[\fB\-\-basename\fR]
         [\fB\-\-file\-alignment=\fR\fInum\fR]
         [\fB\-\-heap=\fR\fIsize\fR]
         [\fB\-\-image\-base=\fR\fIaddress\fR]
@@ -885,6 +887,23 @@ This option is used to build a \fI.sym\fR file for a VxWorks kernel.
 It can also be a useful way of reducing the size of a \fB\-\-just\-symbols\fR
 linker input file.
 .RE
+.IP "\fB\-\-change\-pathname\fR \fIold\fR=\fInew\fR" 4
+.IX Item "--change-pathname old=new"
+When converting debugging information using \fB\-\-debugging\fR, for
+every pathname that starts with \fIold\fR, replace the matching part
+by \fInew\fR.  This is intented to map pathnames between different
+debugging tools, or when parts of the object file(s) had their
+pathnames recorded in a different build environment.  Note that only
+leading directory name components might be changed that way, since the
+trailing filename could be recorded elsewhere as well (depending on the
+debugging format of the input file).
+.IP "\fB\-\-basename\fR"
+.IX Item "--basename"
+When converting debugging information using \fB\-\-debugging\fR, for
+every pathname, strip all leading directory information.  This option
+takes precedence over any \fB\-\-change\-pathname\fR option.  For some
+debugging formats that cannot handle long filenames, this options is
+implied (notably, some COFF debugging formats).
 .IP "\fB\-V\fR" 4
 .IX Item "-V"
 .PD 0
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index e0cac19..876b30d 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -32,6 +32,7 @@
 #include "elf-bfd.h"
 #include <sys/stat.h>
 #include "libbfd.h"
+#include "debug.h"
 #include "coff/internal.h"
 #include "libcoff.h"
 
@@ -297,6 +298,8 @@ enum command_line_switch
     OPTION_IMPURE,
     OPTION_EXTRACT_SYMBOL,
     OPTION_REVERSE_BYTES,
+    OPTION_CHANGE_PATHNAME,
+    OPTION_BASENAME,
     OPTION_FILE_ALIGNMENT,
     OPTION_HEAP,
     OPTION_IMAGE_BASE,
@@ -346,10 +349,12 @@ static struct option copy_options[] =
   {"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
   {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
   {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE},
+  {"basename", no_argument, 0, OPTION_BASENAME},
   {"binary-architecture", required_argument, 0, 'B'},
   {"byte", required_argument, 0, 'b'},
   {"change-addresses", required_argument, 0, OPTION_CHANGE_ADDRESSES},
   {"change-leading-char", no_argument, 0, OPTION_CHANGE_LEADING_CHAR},
+  {"change-pathname", required_argument, 0, OPTION_CHANGE_PATHNAME},
   {"change-section-address", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
   {"change-section-lma", required_argument, 0, OPTION_CHANGE_SECTION_LMA},
   {"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA},
@@ -543,6 +548,8 @@ copy_usage (FILE *stream, int exit_status)
      --prefix-alloc-sections <prefix>\n\
                                    Add <prefix> to start of every allocatable\n\
                                      section name\n\
+     --change-pathname <old>=<new> Change debug pathnames from <old> to <new>\n\
+     --basename                    Strip directory part from debug pathnames\n\
      --file-alignment <num>        Set PE file alignment to <num>\n\
      --heap <reserve>[,<commit>]   Set PE reserve/commit heap to <reserve>/\n\
                                    <commit>\n\
@@ -999,6 +1006,8 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
   asymbol **from = isyms, **to = osyms;
   long src_count = 0, dst_count = 0;
   int relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
+  bfd_boolean need_for_debugging = convert_debugging
+    && bfd_get_arch (abfd) == bfd_arch_avr;
 
   for (; src_count < symcount; src_count++)
     {
@@ -1099,7 +1108,8 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
 	       || bfd_is_com_section (bfd_get_section (sym)))
 	keep = strip_symbols != STRIP_UNNEEDED;
       else if ((flags & BSF_DEBUGGING) != 0)	/* Debugging symbol.  */
-	keep = (strip_symbols != STRIP_DEBUG
+	keep = need_for_debugging
+		|| (strip_symbols != STRIP_DEBUG
 		&& strip_symbols != STRIP_UNNEEDED
 		&& ! convert_debugging);
       else if (bfd_coff_get_comdat_section (abfd, bfd_get_section (sym)))
@@ -2817,6 +2827,10 @@ write_debugging_info (bfd *obfd, void *dhandle,
     return write_ieee_debugging_info (obfd, dhandle);
 
   if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
+      && bfd_get_arch (obfd) == bfd_arch_avr)
+    return write_coff_debugging_info (obfd, dhandle, symcountp, symppp);
+
+  if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
       || bfd_get_flavour (obfd) == bfd_target_elf_flavour)
     {
       bfd_byte *syms, *strings;
@@ -3641,6 +3655,30 @@ copy_main (int argc, char *argv[])
 	  prefix_alloc_sections_string = optarg;
 	  break;
 
+	case OPTION_CHANGE_PATHNAME:
+	  {
+	    const char *s;
+	    int len;
+	    char *name;
+
+	    s = strchr (optarg, '=');
+	    if (s == NULL)
+	      fatal (_("bad format for %s"), "--change-pathname");
+
+	    len = s - optarg;
+	    name = (char *) xmalloc (len + 1);
+	    strncpy (name, optarg, len);
+	    name[len] = '\0';
+
+	    debug_register_pathname_xlat (name, s + 1);
+	  }
+	  break;
+
+	case OPTION_BASENAME:
+	  /* very special case of pathname translation */
+	  debug_register_pathname_xlat (NULL, NULL);
+	  break;
+
 	case OPTION_READONLY_TEXT:
 	  bfd_flags_to_set |= WP_TEXT;
 	  bfd_flags_to_clear &= ~WP_TEXT;
diff --git a/binutils/rdcoff.c b/binutils/rdcoff.c
index 473305e..c3cbf77 100644
--- a/binutils/rdcoff.c
+++ b/binutils/rdcoff.c
@@ -82,6 +82,9 @@ struct coff_types
   struct coff_slots *slots;
   /* Basic types.  */
   debug_type basic[T_MAX + 1];
+  /* Some general information, kept here for convenience. */
+  size_t intsize;		/* sizeof (int) */
+  size_t doublesize;		/* sizeof (double) */
 };
 
 static debug_type *coff_get_slot (struct coff_types *, int);
@@ -101,6 +104,7 @@ static bfd_boolean parse_coff_symbol
   (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *,
    void *, debug_type, bfd_boolean);
 static bfd_boolean external_coff_symbol_p (int sym_class);
+static bfd_vma coff_convert_register (bfd *, bfd_vma);
 
 /* Return the slot for a type.  */
 
@@ -271,8 +275,7 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
       break;
 
     case T_INT:
-      /* FIXME: Perhaps the size should depend upon the architecture.  */
-      ret = debug_make_int_type (dhandle, 4, FALSE);
+      ret = debug_make_int_type (dhandle, types->intsize, FALSE);
       name = "int";
       break;
 
@@ -287,7 +290,7 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
       break;
 
     case T_DOUBLE:
-      ret = debug_make_float_type (dhandle, 8);
+      ret = debug_make_float_type (dhandle, types->doublesize);
       name = "double";
       break;
 
@@ -307,7 +310,7 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
       break;
 
     case T_UINT:
-      ret = debug_make_int_type (dhandle, 4, TRUE);
+      ret = debug_make_int_type (dhandle, types->intsize, TRUE);
       name = "unsigned int";
       break;
 
@@ -565,6 +568,8 @@ parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
 
     case C_WEAKEXT:
     case C_EXT:
+      /* AVR COFF abuses C_EXTDEF */
+    case C_EXTDEF:
       if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
 				   DEBUG_GLOBAL, bfd_asymbol_value (sym)))
 	return FALSE;
@@ -580,9 +585,9 @@ parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
       break;
 
     case C_REG:
-      /* FIXME: We may need to convert the register number.  */
       if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
-				   DEBUG_REGISTER, bfd_asymbol_value (sym)))
+				   DEBUG_REGISTER,
+				   coff_convert_register (abfd, bfd_asymbol_value (sym))))
 	return FALSE;
       break;
 
@@ -596,9 +601,9 @@ parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
       break;
 
     case C_REGPARM:
-      /* FIXME: We may need to convert the register number.  */
       if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
-				    DEBUG_PARM_REG, bfd_asymbol_value (sym)))
+				    DEBUG_PARM_REG,
+				    coff_convert_register (abfd, bfd_asymbol_value (sym))))
 	return FALSE;
       break;
 
@@ -648,6 +653,28 @@ external_coff_symbol_p (int sym_class)
   return FALSE;
 }
 
+static bfd_vma
+coff_convert_register (abfd, val)
+     bfd *abfd;
+     bfd_vma val;
+{
+
+  switch (bfd_get_arch (abfd))
+    {
+    case bfd_arch_avr:
+      /* AVR COFF wants to describe up to four registers by the four
+	 bytes of the 32-bit value.  Unused bytes are filled with
+	 0xff.  In theory, this would allow for non-contiguous
+	 register usage to hold a single value, but hopefully, no
+	 compiler is going to use that feature.  We could not handle
+	 it anyway. */
+      return val & 0xff;
+
+    default:
+      return val;
+    }
+}
+
 /* This is the main routine.  It looks through all the symbols and
    handles them.  */
 
@@ -674,6 +701,17 @@ parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
   types.slots = NULL;
   for (i = 0; i <= T_MAX; i++)
     types.basic[i] = DEBUG_TYPE_NULL;
+  switch (bfd_get_arch (abfd))
+    {
+    case bfd_arch_avr:
+      types.intsize = 2;
+      types.doublesize = 4;
+      break;
+
+    default:
+      types.intsize = 4;
+      types.doublesize = 8;
+    }
 
   next_c_file = -1;
   fnname = NULL;
@@ -734,7 +772,6 @@ parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
       switch (syment.n_sclass)
 	{
 	case C_EFCN:
-	case C_EXTDEF:
 	case C_ULABEL:
 	case C_USTATIC:
 	case C_LINE:
@@ -757,6 +794,8 @@ parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
 	  /* Fall through.  */
 	case C_WEAKEXT:
 	case C_EXT:
+	  /* AVR COFF abuses C_EXTDEF for C_EXT */
+	case C_EXTDEF:
 	  if (ISFCN (syment.n_type))
 	    {
 	      fnname = name;
diff --git a/binutils/wrcoff.c b/binutils/wrcoff.c
new file mode 100644
index 0000000..07cfbc8
--- /dev/null
+++ b/binutils/wrcoff.c
@@ -0,0 +1,3410 @@
+/* wrcoff.c -- Generate (AVR) COFF debugging information
+   Copyright 2003 Free Software Foundation, Inc.
+
+   Written by Joerg Wunsch.
+
+   This file is part of GNU Binutils.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
+
+/* This file contains code which writes out COFF debugging
+   information.  By now, this has only been tested on the AVR
+   platform, though any attempt has been made to keep the conversion
+   applicable to possible other COFF debugging consumers as well. */
+
+#include <stdio.h>
+#include <assert.h>
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "coff/internal.h"
+#include "bucomm.h"
+#include "libiberty.h"
+#include "safe-ctype.h"
+#include "debug.h"
+#include "budbg.h"
+
+/* Enabling COFF_DEBUG will trace the internal callback functions and
+   their parameters as debug_write() calls them. */
+//#define COFF_DEBUG 1
+
+#include "libcoff.h"
+
+#define N_TMASK (coff_data (info->abfd)->local_n_tmask)
+#define N_BTSHFT (coff_data (info->abfd)->local_n_btshft)
+#define N_BTMASK (coff_data (info->abfd)->local_n_btmask)
+#define N_TSHIFT (coff_data (info->abfd)->local_n_tshift)
+
+/* Structure of local symbols per compilation unit. */
+struct coff_compilation_unit
+{
+  const char *fname;
+  asymbol **syms;
+  long nsyms, totsyms;
+};
+
+enum ts_kind
+{
+  TS_EMPTY,
+  TS_VOID,
+  TS_INT,
+  TS_FLOAT,
+  TS_COMPLEX,
+  TS_ENUM,
+  TS_POINTER,
+  TS_FUNC,
+  TS_ARRAY,
+  TS_STRUCT,
+  TS_NONE = -1
+};
+
+/* Structure defining the pre-defined types. */
+struct coff_predef_type
+{
+  enum ts_kind kind;
+  unsigned int size;		/* in bytes */
+  bfd_boolean isunsigned;
+  int slot;
+};
+
+struct coff_type_stack;
+struct coff_hash_entry;
+
+struct coff_struct_fields
+{
+  const char *name;
+  bfd_vma bitpos;
+  bfd_vma bitsize;
+  enum debug_visibility visibility;
+  struct coff_type_stack *types;
+};
+
+/* Our type stack. */
+struct coff_type_stack
+{
+  struct coff_type_stack *next;
+  enum ts_kind tsk;
+  union
+  {
+    /* TS_INT */
+    struct
+    {
+      unsigned int size;
+      bfd_boolean isunsigned;
+    }
+    ts_int;
+
+    /* TS_FLOAT */
+    struct
+    {
+      unsigned int size;
+    }
+    ts_float;
+
+    /* TS_ENUM */
+    struct
+    {
+      union
+      {
+	const char *fixtag;
+	char *malloctag;
+      }
+      tag;
+      bfd_boolean tagismalloced;
+      const char **names;
+      bfd_signed_vma *vals;
+      struct coff_enum_hash_entry *ehash;
+    }
+    ts_enum;
+
+    /* TS_FUNC */
+    struct
+    {
+      struct coff_type_stack *savedts;
+    }
+    ts_func;
+
+    /* TS_ARRAY */
+    struct
+    {
+      bfd_signed_vma low;
+      bfd_signed_vma high;
+    }
+    ts_array;
+
+    /* TS_STRUCT */
+    struct
+    {
+      union
+      {
+	const char *fixtag;
+	char *malloctag;
+      }
+      tag;
+      bfd_boolean tagismalloced;
+      unsigned int id;
+      bfd_boolean isstruct;
+      unsigned int size;
+      long nfields;
+      struct coff_struct_fields *fields;
+      struct coff_type_stack *savedts;
+      struct coff_struct_hash_entry *shash;
+    }
+    ts_struct;
+  }
+  u;
+};
+
+struct coff_name_type_hash_table
+{
+  struct bfd_hash_table root;
+};
+
+struct coff_name_type_hash_entry
+{
+  struct bfd_hash_entry root;
+  /* Information for this name.  */
+  struct coff_type_stack *types;
+  bfd_boolean emitted;
+};
+
+struct coff_struct_hash_table
+{
+  struct bfd_hash_table root;
+};
+
+struct coff_struct_hash_entry
+{
+  struct bfd_hash_entry root;
+  /* Information for this name.  */
+  struct coff_type_stack *types;
+  bfd_boolean emitted;
+  combined_entry_type *native;
+  /* list of symbol indices that need fixing */
+  long *fixidxs;
+  unsigned nfixidxs;
+};
+
+struct coff_enum_hash_table
+{
+  struct bfd_hash_table root;
+};
+
+struct coff_enum_hash_entry
+{
+  struct bfd_hash_entry root;
+  /* Information for this name.  */
+  struct coff_type_stack *types;
+  bfd_boolean emitted;
+  combined_entry_type *native;
+  /* list of symbol indices that need fixing */
+  long *fixidxs;
+  unsigned nfixidxs;
+};
+
+/* COFF private symbol data.  Used as a cookie to pass data around
+   between various processing stages.  The generic COFF handling code
+   doesn't use any private data. */
+struct coff_private_symdata
+{
+  unsigned int size;		/* size of symbol, used in AVR register
+				   translation */
+  struct coff_struct_hash_entry *shash; /* TS_STRUCT hash for fixups */
+  struct coff_enum_hash_entry *ehash; /* TS_ENUM hash for fixups */
+};
+
+/* Stack of tags that need endndx fixing. */
+struct coff_fix_stack
+{
+  struct coff_fix_stack *next;
+  combined_entry_type *native;
+};
+
+/* This is the handle passed through debug_write.  */
+
+struct coff_write_handle
+{
+  /* The BFD.  */
+  bfd *abfd;
+  /* Pointers to .text and .data sections, can be used as defaults if
+     no other information is available. */
+  asection *textsect;
+  asection *datasect;
+  /* Some special flags. */
+  unsigned long flags;
+  /* Flags describing architecture options. */
+#define COFF_FL_AVR	0x0001	/* COFF is for AVR platform. */
+#define COFF_FL_EXT_AVR	0x0002	/* AVR "extended" COFF */
+  /* Flags describing internal status information. */
+#define COFF_FL_FIX_ENDNDX	0x10000	/* apply endndx fix at next symbol */
+#define COFF_FL_START_FCN	0x20000	/* begin of function pending */
+#define COFF_FL_FIX_BB		0x40000	/* fix last ".bb" symbol */
+  /* List of our compilation units, from input symbol table. */
+  struct coff_compilation_unit *units;
+  long nunits;
+  struct coff_compilation_unit *currentfile;
+  /* Global symbols from input symbol table. */
+  asymbol **globals;
+  long nglobals;
+  /* Section syms for named sections. */
+  coff_symbol_type **secsyms;
+  long nsecsyms;
+  /* Our COFF symbols. */
+  asymbol **syms;
+  long nsyms;
+  /* Total line number count. */
+  unsigned long totlnos;
+  /* Size of standard objects on this arch. */
+  unsigned int pointersize;
+  unsigned int enumsize;
+  /* Pending information when starting a function.  We have to defer
+     almost everything, some actions can be taken when seeing the
+     starting block of that function, some will even have to wait
+     until we see the end of the function. */
+  const char *funname;		/* name of function */
+  bfd_boolean funglobal;		/* global/local function? */
+  unsigned int lastlno;		/* last line number seen so far */
+  long funcindex;		/* index of ".func" symbol in syms */
+  unsigned int nlnos;		/* line numbers recorded for this function*/
+  bfd_vma endaddr;		/* last .eb address we have seen so far */
+  unsigned int funlno;		/* first line number in function */
+  coff_symbol_type **fargs;	/* function arguments */
+  unsigned int nfargs;
+  asection *funcsection;	/* section the current function is using */
+  /* Type information */
+  struct coff_type_stack *tstack;
+  struct coff_name_type_hash_table types;
+  struct coff_struct_hash_table structs;
+  struct coff_enum_hash_table enums;
+  unsigned nenums;		/* counter for anonymous enum tags */
+  /* Stack of pending endndx fixes, see coff_record_symbol(). */
+  struct coff_fix_stack *fixes;
+};
+
+/* Predefined types, default to usual 32-bit architectures.
+   Arch-dependant different byte sizes will be tuned upon entering
+   write_coff_debugging_info().  The table is looked up from front to
+   end, so we put `more popular' types that might have the same size
+   as other types first (e. g. "int" precedes "long" and "short"). */
+static struct coff_predef_type coff_predef_types[] =
+{
+  { TS_INT, 4, FALSE, 4 },	/* signed int */
+  { TS_INT, 1, FALSE, 2 },	/* signed char */
+  { TS_INT, 2, FALSE, 3 },	/* signed short */
+  { TS_INT, 4, FALSE, 5 },	/* long int */
+  { TS_FLOAT, 8, FALSE, 7 },	/* double */
+  { TS_FLOAT, 4, FALSE, 6 },	/* float */
+  { TS_INT, 4, TRUE, 14 },	/* unsigned int */
+  { TS_INT, 1, TRUE, 12 },	/* unsigned char */
+  { TS_INT, 2, TRUE, 13 },	/* unsigned short */
+  { TS_INT, 4, TRUE, 15 },	/* unsigned long */
+};
+
+static bfd_boolean coff_copy_symbols
+  PARAMS ((struct coff_write_handle *, long, asymbol **));
+static asymbol *coff_find_symbol
+  PARAMS ((struct coff_write_handle *, const char *, bfd_boolean, bfd_boolean));
+static void coff_record_symbol
+  PARAMS ((struct coff_write_handle *, coff_symbol_type *));
+static symvalue coff_fixup_avr_register PARAMS ((symvalue, int));
+static struct bfd_hash_entry *coff_name_type_newfunc
+  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+static bfd_boolean coff_free_type_info
+  PARAMS ((struct coff_name_type_hash_entry *, PTR));
+static struct bfd_hash_entry *coff_struct_newfunc
+  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+static bfd_boolean coff_free_struct_info
+  PARAMS ((struct coff_struct_hash_entry *, PTR));
+static struct bfd_hash_entry *coff_enum_newfunc
+  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+static bfd_boolean coff_free_enum_info
+  PARAMS ((struct coff_enum_hash_entry *, PTR));
+static unsigned int coff_get_fundamental_type
+  PARAMS ((struct coff_write_handle *, struct coff_type_stack *));
+static bfd_boolean coff_make_typed_symbol
+  PARAMS ((struct coff_write_handle *, coff_symbol_type **, enum ts_kind));
+static bfd_boolean coff_emit_struct
+  PARAMS ((struct coff_write_handle *, struct coff_type_stack *,
+	   struct coff_struct_hash_entry *));
+static bfd_boolean coff_emit_enum
+  PARAMS ((struct coff_write_handle *, struct coff_type_stack *,
+	   struct coff_enum_hash_entry *));
+static bfd_boolean coff_emit_ndebug_sym
+  PARAMS ((struct coff_write_handle *, asymbol *, bfd_boolean));
+
+static bfd_boolean coff_start_compilation_unit PARAMS ((PTR, const char *));
+static bfd_boolean coff_start_source PARAMS ((PTR, const char *));
+static bfd_boolean coff_empty_type PARAMS ((PTR));
+static bfd_boolean coff_void_type PARAMS ((PTR));
+static bfd_boolean coff_int_type PARAMS ((PTR, unsigned int, bfd_boolean));
+static bfd_boolean coff_float_type PARAMS ((PTR, unsigned int));
+static bfd_boolean coff_complex_type PARAMS ((PTR, unsigned int));
+static bfd_boolean coff_bool_type PARAMS ((PTR, unsigned int));
+static bfd_boolean coff_enum_type
+  PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
+static bfd_boolean coff_pointer_type PARAMS ((PTR));
+static bfd_boolean coff_function_type PARAMS ((PTR, int, bfd_boolean));
+static bfd_boolean coff_reference_type PARAMS ((PTR));
+static bfd_boolean coff_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
+static bfd_boolean coff_array_type
+  PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, bfd_boolean));
+static bfd_boolean coff_set_type PARAMS ((PTR, bfd_boolean));
+static bfd_boolean coff_offset_type PARAMS ((PTR));
+static bfd_boolean coff_method_type PARAMS ((PTR, bfd_boolean, int, bfd_boolean));
+static bfd_boolean coff_const_type PARAMS ((PTR));
+static bfd_boolean coff_volatile_type PARAMS ((PTR));
+static bfd_boolean coff_start_struct_type
+  PARAMS ((PTR, const char *, unsigned int, bfd_boolean, unsigned int));
+static bfd_boolean coff_struct_field
+  PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
+static bfd_boolean coff_end_struct_type PARAMS ((PTR));
+static bfd_boolean coff_start_class_type
+  PARAMS ((PTR, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
+	   bfd_boolean));
+static bfd_boolean coff_class_static_member
+  PARAMS ((PTR, const char *, const char *, enum debug_visibility));
+static bfd_boolean coff_class_baseclass
+  PARAMS ((PTR, bfd_vma, bfd_boolean, enum debug_visibility));
+static bfd_boolean coff_class_start_method PARAMS ((PTR, const char *));
+static bfd_boolean coff_class_method_variant
+  PARAMS ((PTR, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
+	   bfd_vma, bfd_boolean));
+static bfd_boolean coff_class_static_method_variant
+  PARAMS ((PTR, const char *, enum debug_visibility, bfd_boolean, bfd_boolean));
+static bfd_boolean coff_class_end_method PARAMS ((PTR));
+static bfd_boolean coff_end_class_type PARAMS ((PTR));
+static bfd_boolean coff_typedef_type PARAMS ((PTR, const char *));
+static bfd_boolean coff_tag_type
+  PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
+static bfd_boolean coff_typdef PARAMS ((PTR, const char *));
+static bfd_boolean coff_tag PARAMS ((PTR, const char *));
+static bfd_boolean coff_int_constant PARAMS ((PTR, const char *, bfd_vma));
+static bfd_boolean coff_float_constant PARAMS ((PTR, const char *, double));
+static bfd_boolean coff_typed_constant PARAMS ((PTR, const char *, bfd_vma));
+static bfd_boolean coff_variable
+  PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
+static bfd_boolean coff_start_function PARAMS ((PTR, const char *, bfd_boolean));
+static bfd_boolean coff_function_parameter
+  PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
+static bfd_boolean coff_start_block PARAMS ((PTR, bfd_vma));
+static bfd_boolean coff_end_block PARAMS ((PTR, bfd_vma));
+static bfd_boolean coff_end_function PARAMS ((PTR));
+static bfd_boolean coff_lineno
+  PARAMS ((PTR, const char *, unsigned long, bfd_vma));
+
+static const struct debug_write_fns coff_fns =
+{
+  coff_start_compilation_unit,
+  coff_start_source,
+  coff_empty_type,
+  coff_void_type,
+  coff_int_type,
+  coff_float_type,
+  coff_complex_type,
+  coff_bool_type,
+  coff_enum_type,
+  coff_pointer_type,
+  coff_function_type,
+  coff_reference_type,
+  coff_range_type,
+  coff_array_type,
+  coff_set_type,
+  coff_offset_type,
+  coff_method_type,
+  coff_const_type,
+  coff_volatile_type,
+  coff_start_struct_type,
+  coff_struct_field,
+  coff_end_struct_type,
+  coff_start_class_type,
+  coff_class_static_member,
+  coff_class_baseclass,
+  coff_class_start_method,
+  coff_class_method_variant,
+  coff_class_static_method_variant,
+  coff_class_end_method,
+  coff_end_class_type,
+  coff_typedef_type,
+  coff_tag_type,
+  coff_typdef,
+  coff_tag,
+  coff_int_constant,
+  coff_float_constant,
+  coff_typed_constant,
+  coff_variable,
+  coff_start_function,
+  coff_function_parameter,
+  coff_start_block,
+  coff_end_block,
+  coff_end_function,
+  coff_lineno
+};
+
+/*
+ * Copy our input (non-debugging) symbols.  Local symbols will be
+ * maintained in one bucket per each compilation unit, global (and
+ * weak) symbols will be kept in a simple array.
+ */
+static bfd_boolean
+coff_copy_symbols (info, count, sympp)
+     struct coff_write_handle *info;
+     long count;
+     asymbol **sympp;
+{
+  asymbol *osym;
+  long i;
+  struct coff_compilation_unit *up;
+
+  up = NULL;
+
+  for (i = 0; i < count; i++)
+    {
+      osym = sympp[i];
+
+      /* Try to figure out the .text and .data sections from our input
+	 symbols as we walk them.  Unfortunately, this ought to be the
+	 /input/ section pointers, so their ->output_section is
+	 non-NULL.  That's why we can't simply walk through all the
+	 sections of our abfd since this is describing the output
+	 only. */
+      if (info->textsect == NULL && osym->section->flags & SEC_CODE)
+	/* Assume this to be our .text section. */
+	info->textsect = osym->section;
+      else if (info->datasect == NULL && osym->section->flags & SEC_DATA)
+	/* Assume this to be our .data section. */
+	info->datasect = osym->section;
+
+      if (osym->flags & BSF_FILE)
+	{
+	  /* New file name. */
+	  long l;
+
+	  up = NULL;
+
+	  /* Well, maybe an old one actually?  If so, append it there.
+	     This can happen for files that contribute to multiple
+	     (input) sections that were concatenated by the linker
+	     (like crt1.S). */
+	  for (l = 0; l < info->nunits; l++)
+	    {
+	      if (strcmp (info->units[l].fname, osym->name) == 0)
+		{
+		  up = info->units + l;
+		  break;
+		}
+	    }
+
+	  if (up == NULL)
+	    {
+	      info->units = (struct coff_compilation_unit *)
+		xrealloc (info->units,
+			  ++info->nunits * sizeof(struct coff_compilation_unit));
+	      up = info->units + (info->nunits - 1);
+	      up->fname = osym->name;
+	      up->syms = NULL;
+	      up->nsyms = up->totsyms = 0;
+	    }
+	}
+      else if (osym->flags & (BSF_GLOBAL | BSF_WEAK))
+	{
+	  /* Global (or weak) symbols are recorded outside compilation
+	     units. */
+	  info->globals = (asymbol **)
+	    xrealloc (info->globals, ++info->nglobals * sizeof(asymbol *));
+	  info->globals[info->nglobals - 1] = osym;
+	  continue;
+	}
+      else if (!bfd_is_const_section(osym->section))
+	{
+	  if (osym->flags & BSF_SECTION_SYM)
+	    {
+	      coff_symbol_type *csymp;
+	      /* Just record them by now, they'll be fixed up later. */
+
+	      if (info->nsyms == 0 && (info->flags & COFF_FL_AVR) == 0)
+		{
+		  /* Very first symbol, fake a compilation unit name
+		     for it.  Historical precedence seems to dictate
+		     this, but AVR COFF does not use that. */
+		  csymp = (coff_symbol_type *)
+		    coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+		  if (csymp == NULL)
+		    return FALSE;
+
+		  csymp->symbol.name = xstrdup ("<fake>");
+		  csymp->symbol.value = 0;
+		  csymp->symbol.udata.p = NULL;
+		  csymp->native->u.syment.n_sclass = C_FILE;
+		  /* force filename into aux entry */
+		  csymp->native->u.syment.n_numaux = 1;
+		  coff_record_symbol (info, csymp);
+		}
+
+	      /* convert to COFF native section symbol */
+	      csymp = (coff_symbol_type *)
+		coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+	      if (csymp == NULL)
+		return FALSE;
+
+	      csymp->symbol.name = xstrdup (osym->section->name);
+	      csymp->symbol.value = osym->section->output_section->vma;
+	      csymp->symbol.flags = BSF_DEBUGGING | BSF_SECTION_SYM;
+	      csymp->symbol.section = osym->section;
+	      csymp->symbol.udata.p = NULL;
+	      csymp->native->fix_scnlen = 1;
+	      csymp->native->u.syment.n_sclass = C_STAT;
+	      csymp->native->u.syment.n_type = T_NULL;
+	      csymp->native->u.syment.n_numaux = 1;
+
+	      coff_record_symbol (info, csymp);
+
+	      info->secsyms = (coff_symbol_type **)
+		xrealloc (info->secsyms,
+			  ++info->nsecsyms * sizeof(coff_symbol_type *));
+	      info->secsyms[info->nsecsyms - 1] = csymp;
+	    }
+	  else
+	    {
+	      /* Local symbol in a named section, will be recorded
+		 within the respective compilation unit. */
+	      if (up == NULL)
+		{
+		  fprintf (stderr,
+			   _("Discarding local symbol outside any compilation unit"));
+		  if (osym->name)
+		    fprintf (stderr, ": %s", osym->name);
+		  putc ('\n', stderr);
+		}
+	      else
+		{
+		  up->syms = (asymbol **)
+		    xrealloc (up->syms, ++up->nsyms * sizeof(asymbol *));
+		  up->syms[up->nsyms - 1] = osym;
+		  up->totsyms = up->nsyms;
+		  continue;
+		}
+	    }
+	}
+    }
+
+  return TRUE;
+}
+
+/* Find a name in the symbol table.  If found, the respective entry in
+   the symbol vector is zeroed, so after processing all debugging
+   symbols, only non-debugging symbols will remain. */
+static asymbol *
+coff_find_symbol (info, name, isfunction, global)
+     struct coff_write_handle *info;
+     const char *name;
+     bfd_boolean isfunction;
+     bfd_boolean global;
+{
+  asymbol *symp;
+  long i;
+  size_t namelen;
+
+  if (global)
+    {
+      for (i = 0; i < info->nglobals; i++)
+	{
+	  symp = info->globals[i];
+	  if (symp == NULL)
+	    continue;
+	  if (strcmp (name, symp->name) == 0
+	      && ((symp->flags & BSF_FUNCTION) != 0) == (isfunction == TRUE))
+	    {
+	      info->globals[i] = NULL;
+	      return symp;
+	    }
+	}
+      return NULL;
+    }
+
+  if (info->currentfile == NULL)
+    return NULL;
+
+  /* For local symbols, the match optionally stops at a dot in the
+     symtab symbol's name; this is used by gcc to indicate
+     function-scope static symbols (e. g. symbol "foo" will become
+     "foo.1" in function scope). */
+  namelen = strlen (name);
+  for (i = 0; i < info->currentfile->nsyms; i++)
+    {
+      symp = info->currentfile->syms[i];
+      if (symp == NULL)
+	continue;
+      if (strncmp (name, symp->name, namelen) == 0
+	  && (symp->name[namelen] == '\0' || symp->name[namelen] == '.')
+	  && ((symp->flags & BSF_FUNCTION) != 0) == (isfunction == TRUE))
+	{
+	  info->currentfile->syms[i] = NULL;
+	  info->currentfile->totsyms--;
+	  return symp;
+	}
+    }
+  return NULL;
+}
+
+static void
+coff_record_symbol (info, csymp)
+     struct coff_write_handle *info;
+     coff_symbol_type *csymp;
+{
+  struct coff_private_symdata *priv;
+
+  info->syms = (asymbol **) xrealloc (info->syms,
+				      ++info->nsyms * sizeof (asymbol *));
+  info->syms[info->nsyms - 1] = (asymbol *)csymp;
+
+  if ((priv = csymp->symbol.udata.p) != NULL)
+    {
+      if (priv->shash != NULL)
+	{
+	  struct coff_struct_hash_entry *shash = priv->shash;
+	  shash->fixidxs = (long *)
+	    xrealloc (shash->fixidxs, ++shash->nfixidxs * sizeof (long));
+	  shash->fixidxs[shash->nfixidxs - 1] = info->nsyms - 1;
+	}
+      if (priv->ehash != NULL)
+	{
+	  struct coff_enum_hash_entry *ehash = priv->ehash;
+	  ehash->fixidxs = (long *)
+	    xrealloc (ehash->fixidxs, ++ehash->nfixidxs * sizeof (long));
+	  ehash->fixidxs[ehash->nfixidxs - 1] = info->nsyms - 1;
+	}
+      free (priv);
+      csymp->symbol.udata.p = NULL;
+    }
+
+  /* If there are any pending endndx fixes, pop the last element from
+     that stack, and record the current symbol for fixing.  We need to
+     do this here since we need to record our current csymp->native
+     (where that csymp is completely unrelated to whatever symbol was
+     previously generated that requested the fixup).  The stack of
+     pending fixes is required since several endndx fixes could be
+     nested, e. g. the start of a function has a pending fix that
+     needs to point to the first symbol after the function, but there
+     could be an anonymous struct definition inside that function's
+     local variables where the endndx needs to point after the last
+     symbol of this struct.  Also, structs and unions could be nested.
+
+     Each call to coff_record_symbol() can fix at most one endndx
+     (even if more are pending in the stack), but that's OK.
+
+     Note that bfd/coffgen.c converts that csymp->native into a
+     symtable slot number after coff_renumber_symbols() has been
+     run. */
+  if (info->flags & COFF_FL_FIX_ENDNDX)
+    {
+      struct coff_fix_stack *fsp, *ofsp;
+      union internal_auxent *aux;
+
+      assert (info->fixes != NULL);
+
+      fsp = info->fixes;
+      ofsp = NULL;
+      while (fsp->next != NULL)
+	{
+	  ofsp = fsp;
+	  fsp = fsp->next;
+	}
+      if (ofsp == NULL)
+	info->fixes = NULL;
+      else
+	ofsp->next = NULL;
+
+      aux = &(fsp->native->u.auxent);
+      fsp->native->fix_end = 1;
+      aux->x_sym.x_fcnary.x_fcn.x_endndx.p = csymp->native;
+      free (fsp);
+
+      info->flags &= ~COFF_FL_FIX_ENDNDX;
+    }
+}
+
+/* Fixup AVR COFF register handling: they don't only mention the
+   starting register number, but all registers, each within one byte
+   of the value.  Unused register positions are filled up with
+   0xff. */
+static symvalue
+coff_fixup_avr_register (val, size)
+     symvalue val;
+     int size;
+{
+  union
+  {
+    unsigned char c[4];
+    symvalue v;
+  } u;
+
+  u.c[1] = u.c[2] = u.c[3] = 0xff;
+  u.c[0] = val;
+  if (size > 8)
+    u.c[1] = val + 1;
+  if (size > 16)
+    {
+      u.c[2] = val + 2;
+      u.c[3] = val + 3;
+    }
+
+  return u.v;
+}
+
+/* Initialize an entry in the hash tables.  */
+
+static struct bfd_hash_entry *
+coff_name_type_newfunc (entry, table, string)
+     struct bfd_hash_entry *entry;
+     struct bfd_hash_table *table;
+     const char *string;
+{
+  struct coff_name_type_hash_entry *ret =
+    (struct coff_name_type_hash_entry *) entry;
+
+  /* Allocate the structure if it has not already been allocated by a
+     subclass.  */
+  if (ret == NULL)
+    ret = ((struct coff_name_type_hash_entry *)
+	   bfd_hash_allocate (table, sizeof *ret));
+  if (ret == NULL)
+    return NULL;
+
+  /* Call the allocation method of the superclass.  */
+  ret = ((struct coff_name_type_hash_entry *)
+	 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->types = NULL;
+      ret->emitted = FALSE;
+    }
+
+  return (struct bfd_hash_entry *) ret;
+}
+
+static struct bfd_hash_entry *
+coff_struct_newfunc (entry, table, string)
+     struct bfd_hash_entry *entry;
+     struct bfd_hash_table *table;
+     const char *string;
+{
+  struct coff_struct_hash_entry *ret =
+    (struct coff_struct_hash_entry *) entry;
+
+  /* Allocate the structure if it has not already been allocated by a
+     subclass.  */
+  if (ret == NULL)
+    ret = ((struct coff_struct_hash_entry *)
+	   bfd_hash_allocate (table, sizeof *ret));
+  if (ret == NULL)
+    return NULL;
+
+  /* Call the allocation method of the superclass.  */
+  ret = ((struct coff_struct_hash_entry *)
+	 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->types = NULL;
+      ret->emitted = FALSE;
+      ret->fixidxs = NULL;
+      ret->nfixidxs = 0;
+      ret->native = NULL;
+    }
+
+  return (struct bfd_hash_entry *) ret;
+}
+
+static struct bfd_hash_entry *
+coff_enum_newfunc (entry, table, string)
+     struct bfd_hash_entry *entry;
+     struct bfd_hash_table *table;
+     const char *string;
+{
+  struct coff_enum_hash_entry *ret =
+    (struct coff_enum_hash_entry *) entry;
+
+  /* Allocate the structure if it has not already been allocated by a
+     subclass.  */
+  if (ret == NULL)
+    ret = ((struct coff_enum_hash_entry *)
+	   bfd_hash_allocate (table, sizeof *ret));
+  if (ret == NULL)
+    return NULL;
+
+  /* Call the allocation method of the superclass.  */
+  ret = ((struct coff_enum_hash_entry *)
+	 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->types = NULL;
+      ret->emitted = FALSE;
+      ret->fixidxs = NULL;
+      ret->nfixidxs = 0;
+      ret->native = NULL;
+    }
+
+  return (struct bfd_hash_entry *) ret;
+}
+
+/* Look up an entry in the hash tables.  */
+
+#define coff_name_type_hash_lookup(table, string, create, copy) \
+  ((struct coff_name_type_hash_entry *) \
+   bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
+
+/* Traverse the hash table.  */
+
+#define coff_name_type_hash_traverse(table, func, info)			\
+  (bfd_hash_traverse							\
+   (&(table)->root,							\
+    (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func),	\
+    (info)))
+
+#define coff_struct_hash_lookup(table, string, create, copy) \
+  ((struct coff_struct_hash_entry *) \
+   bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
+
+/* Traverse the hash table.  */
+
+#define coff_struct_hash_traverse(table, func, info)			\
+  (bfd_hash_traverse							\
+   (&(table)->root,							\
+    (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func),	\
+    (info)))
+
+#define coff_enum_hash_lookup(table, string, create, copy) \
+  ((struct coff_enum_hash_entry *) \
+   bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
+
+/* Traverse the hash table.  */
+
+#define coff_enum_hash_traverse(table, func, info)			\
+  (bfd_hash_traverse							\
+   (&(table)->root,							\
+    (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func),	\
+    (info)))
+
+#define coff_push_type(kind) \
+  tst = (struct coff_type_stack *) xmalloc (sizeof (struct coff_type_stack)); \
+  memset (tst, 0, sizeof (*tst)); \
+  tst->next = info->tstack; \
+  tst->tsk = kind; \
+  info->tstack = tst
+
+#define coff_pop_type() \
+  tst = info->tstack; \
+  if (tst == NULL) { \
+    fprintf (stderr, _("empty type stack in coff_pop_type()\n")); \
+    return FALSE; \
+  } \
+  info->tstack = tst->next; \
+  tst->next = NULL
+
+#define coff_complain_unsupp(s) \
+  fprintf (stderr, _("%s type not supported in %s\n"), \
+	   s, info->abfd->xvec->name); \
+  return FALSE
+
+/* These function is called via the hash traverse routine when freeing
+   a hash table (at the end of a translation unit). */
+static bfd_boolean
+coff_free_type_info (h, p)
+     struct coff_name_type_hash_entry *h;
+     PTR p ATTRIBUTE_UNUSED;
+{
+  struct coff_type_stack *tst, *otst;
+
+  for (tst = h->types; tst != NULL;)
+    {
+      otst = tst;
+      tst = tst->next;
+      free (otst);
+    }
+  return TRUE;
+}
+
+static bfd_boolean
+coff_free_struct_info (h, p)
+     struct coff_struct_hash_entry *h;
+     PTR p ATTRIBUTE_UNUSED;
+{
+  struct coff_type_stack *tst, *otst, *xtst, *xotst;
+  struct coff_struct_fields *fp;
+  long i;
+
+  for (tst = h->types; tst != NULL;)
+    {
+      otst = tst;
+      if (tst->u.ts_struct.tagismalloced)
+	free (tst->u.ts_struct.tag.malloctag);
+      for (i = 0, fp = tst->u.ts_struct.fields;
+	   i < tst->u.ts_struct.nfields;
+	   i++, fp++)
+	{
+	  xtst = fp->types;
+	  while (xtst != NULL)
+	    {
+	      xotst = xtst->next;
+	      free (xtst);
+	      xtst = xotst;
+	    }
+	}
+      free (tst->u.ts_struct.fields);
+      tst = tst->next;
+      free (otst);
+    }
+  return TRUE;
+}
+
+static bfd_boolean
+coff_free_enum_info (h, p)
+     struct coff_enum_hash_entry *h;
+     PTR p ATTRIBUTE_UNUSED;
+{
+  struct coff_type_stack *tst, *otst;
+
+  for (tst = h->types; tst != NULL;)
+    {
+      otst = tst;
+      if (tst->u.ts_enum.tagismalloced)
+	free (tst->u.ts_enum.tag.malloctag);
+      tst = tst->next;
+      free (otst);
+    }
+  return TRUE;
+}
+
+static unsigned int
+coff_get_fundamental_type (info, tst)
+     struct coff_write_handle *info ATTRIBUTE_UNUSED;
+     struct coff_type_stack *tst;
+{
+  size_t i;
+
+  /* See if one of our predefined types will fit. */
+  if (tst->tsk == TS_INT)
+    {
+      for (i = 0;
+	   i < sizeof coff_predef_types / sizeof (struct coff_predef_type);
+	   i++)
+	{
+	  if (coff_predef_types[i].kind == TS_INT
+	      && coff_predef_types[i].size == tst->u.ts_int.size
+	      && coff_predef_types[i].isunsigned == tst->u.ts_int.isunsigned)
+	    return coff_predef_types[i].slot;
+	}
+      fprintf (stderr,
+	       _("%ssigned %d-bit integer type not available in COFF\n"),
+	       tst->u.ts_int.isunsigned? "un": "", tst->u.ts_int.size * 8);
+    }
+  else
+    {
+      for (i = 0;
+	   i < sizeof coff_predef_types / sizeof (struct coff_predef_type);
+	   i++)
+	{
+	  if (coff_predef_types[i].kind == TS_FLOAT
+	      && coff_predef_types[i].size == tst->u.ts_float.size)
+	    return coff_predef_types[i].slot;
+	}
+      fprintf (stderr, _("%d-bit float type not available in COFF\n"),
+	       tst->u.ts_float.size * 8);
+    }
+
+  return T_NULL;
+}
+
+static bfd_boolean
+coff_make_typed_symbol (info, csympp, stopat)
+     struct coff_write_handle *info;
+     coff_symbol_type **csympp;
+     enum ts_kind stopat;
+{
+  struct coff_type_stack *tst;
+  union internal_auxent *aux;
+  struct coff_struct_hash_entry *shash;
+  struct coff_enum_hash_entry *ehash;
+  struct coff_private_symdata *priv;
+  unsigned int type, numaux, arydim, size, i, nele, nderived;
+  const char *name;
+  bfd_boolean oldavrcoff = (info->flags & (COFF_FL_AVR | COFF_FL_EXT_AVR))
+    == COFF_FL_AVR;
+
+  /* Synthesize a new internal COFF symbol. */
+  *csympp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (*csympp == NULL)
+    return FALSE;
+
+  priv = (struct coff_private_symdata *) xmalloc (sizeof *priv);
+  memset (priv, 0, sizeof *priv);
+
+  type = arydim = size = nderived = 0;
+
+  aux = &(((*csympp)->native + 1)->u.auxent);
+
+  /* Now, walk the type stack, and see how we could convert the info
+     we've got to what COFF understands. */
+  for (;;)
+    {
+      if (info->tstack == NULL)
+	break;
+
+      /* If we have been advised to not pop the entire stack, stop
+	 here. */
+      if (info->tstack->tsk == stopat && info->tstack->next == NULL)
+	break;
+
+      coff_pop_type ();
+
+      switch (tst->tsk)
+	{
+	case TS_NONE:
+	  /* cannot happen */
+	  break;
+
+	case TS_EMPTY:
+	  if (info->tstack != NULL && info->tstack->tsk != stopat)
+	    fprintf (stderr, _("empty type not last on type stack\n"));
+	  /* type |= T_NULL; */
+	  break;
+
+	case TS_VOID:
+	  if (info->tstack != NULL && info->tstack->tsk != stopat)
+	    fprintf (stderr, _("void type not last on type stack\n"));
+	  type |= T_VOID;
+	  break;
+
+	case TS_INT:
+	  if (info->tstack != NULL && info->tstack->tsk != stopat)
+	    fprintf (stderr, _("int type not last on type stack\n"));
+	  type |= coff_get_fundamental_type (info, tst);
+	  if (size == 0)
+	    size = tst->u.ts_int.size;
+	  break;
+
+	case TS_FLOAT:
+	  if (info->tstack != NULL && info->tstack->tsk != stopat)
+	    fprintf (stderr, _("float type not last on type stack\n"));
+	  type |= coff_get_fundamental_type (info, tst);
+	  if (size == 0)
+	    size = tst->u.ts_float.size;
+	  break;
+
+	case TS_POINTER:
+	  nderived++;
+	  type = ((type & ~N_BTMASK) << N_TSHIFT) | (DT_PTR << N_BTSHFT);
+	  size = info->pointersize;
+	  break;
+
+	case TS_FUNC:
+	  nderived++;
+	  type = ((type & ~N_BTMASK) << N_TSHIFT) | (DT_FCN << N_BTSHFT);
+	  /* AUX entry for DT_FCN will be filled in elsewhere. */
+	  break;
+
+	case TS_ARRAY:
+	  /* We need to limit arydim so the assignment below won't
+	     overwrite random locations. */
+	  if (arydim >= DIMNUM)
+	    {
+	      fprintf (stderr,
+		       _("More than %d array dimensions, result is invalid.\n"),
+		       DIMNUM);
+	      arydim = DIMNUM - 1;
+	    }
+	  nderived++;
+	  type = ((type & ~N_BTMASK) << N_TSHIFT) | (DT_ARY << N_BTSHFT);
+	  aux->x_sym.x_fcnary.x_ary.x_dimen[arydim++] =
+	    tst->u.ts_array.high - tst->u.ts_array.low + 1;
+
+	  break;
+
+	case TS_COMPLEX:
+	  coff_complain_unsupp (_("complex"));
+
+	case TS_ENUM:
+	  type |= T_ENUM;
+	  if (size == 0)
+	    size = info->enumsize;
+
+	  if (tst->u.ts_enum.ehash != NULL)
+	    {
+	      /* enum tag will be fixed later. */
+	      priv->ehash = tst->u.ts_enum.ehash;
+	      break;
+	    }
+	  if (tst->u.ts_enum.tagismalloced)
+	    name = tst->u.ts_enum.tag.malloctag;
+	  else
+	    name = tst->u.ts_enum.tag.fixtag;
+	  ehash = coff_enum_hash_lookup (&info->enums, name,
+					 TRUE, tst->u.ts_enum.tagismalloced);
+	  if (ehash == NULL)
+	    return FALSE;
+	  if (!ehash->emitted)
+	    {
+	      if (ehash->types == NULL)
+		{
+		  ehash->types = (struct coff_type_stack *)
+		    xmalloc (sizeof (struct coff_type_stack));
+		  memcpy (ehash->types, tst, sizeof (struct coff_type_stack));
+		}
+	      ehash->emitted = TRUE;
+	      coff_emit_enum (info, tst, ehash);
+	      if (ehash->nfixidxs != 0)
+		{
+		  coff_symbol_type *symp;
+		  unsigned i;
+
+		  for (i = 0; i < ehash->nfixidxs; i++)
+		    {
+		      combined_entry_type *np;
+
+		      symp = (coff_symbol_type *) info->syms[ehash->fixidxs[i]];
+		      symp->native->u.syment.n_type &= ~N_BTMASK;
+		      symp->native->u.syment.n_type |= T_ENUM;
+
+		      if (oldavrcoff)
+			continue;
+
+		      np = symp->native + 1;
+		      np->fix_tag = 1;
+		      np->u.auxent.x_sym.x_tagndx.p = ehash->native;
+		      if (np->u.auxent.x_sym.x_misc.x_fsize == 0)
+			np->u.auxent.x_sym.x_misc.x_lnsz.x_size = size;
+		    }
+
+		  free (ehash->fixidxs);
+		  ehash->nfixidxs = 0;
+		}
+	    }
+	  if (!oldavrcoff)
+	    {
+	      ((*csympp)->native + 1)->fix_tag = 1;
+	      aux->x_sym.x_tagndx.p = ehash->native;
+	      if (aux->x_sym.x_misc.x_fsize == 0)
+		aux->x_sym.x_misc.x_lnsz.x_size = size;
+	    }
+	  break;
+
+	case TS_STRUCT:
+	  if (tst->u.ts_struct.isstruct)
+	    type |= T_STRUCT;
+	  else
+	    type |= T_UNION;
+	  if (size == 0)
+	    size = tst->u.ts_struct.size;
+
+	  if (tst->u.ts_struct.shash != NULL)
+	    {
+	      /* struct tag will be fixed later. */
+	      priv->shash = tst->u.ts_struct.shash;
+	      break;
+	    }
+	  if (tst->u.ts_struct.tagismalloced)
+	    name = tst->u.ts_struct.tag.malloctag;
+	  else
+	    name = tst->u.ts_struct.tag.fixtag;
+	  shash = coff_struct_hash_lookup (&info->structs, name,
+					   TRUE, tst->u.ts_struct.tagismalloced);
+	  if (shash == NULL)
+	    return FALSE;
+	  if (!shash->emitted)
+	    {
+	      if (shash->types == NULL)
+		{
+		  shash->types = (struct coff_type_stack *)
+		    xmalloc (sizeof (struct coff_type_stack));
+		  memcpy (shash->types, tst, sizeof (struct coff_type_stack));
+		}
+	      shash->emitted = TRUE;
+	      coff_emit_struct (info, tst, shash);
+	      if (shash->nfixidxs != 0)
+		{
+		  coff_symbol_type *symp;
+		  unsigned i;
+
+		  for (i = 0; i < shash->nfixidxs; i++)
+		    {
+		      combined_entry_type *np;
+
+		      symp = (coff_symbol_type *) info->syms[shash->fixidxs[i]];
+		      symp->native->u.syment.n_type &= ~N_BTMASK;
+		      if (tst->u.ts_struct.isstruct)
+			symp->native->u.syment.n_type |= T_STRUCT;
+		      else
+			symp->native->u.syment.n_type |= T_UNION;
+
+		      if (oldavrcoff)
+			continue;
+
+		      np = symp->native + 1;
+		      np->fix_tag = 1;
+		      np->u.auxent.x_sym.x_tagndx.p = shash->native;
+		      if (np->u.auxent.x_sym.x_misc.x_fsize == 0)
+			np->u.auxent.x_sym.x_misc.x_lnsz.x_size = size;
+		    }
+
+		  free (shash->fixidxs);
+		  shash->nfixidxs = 0;
+		}
+	    }
+	  if (!oldavrcoff)
+	    {
+	      ((*csympp)->native + 1)->fix_tag = 1;
+	      aux->x_sym.x_tagndx.p = shash->native;
+	      if (aux->x_sym.x_misc.x_fsize == 0)
+		aux->x_sym.x_misc.x_lnsz.x_size = size;
+	    }
+	  break;
+	}
+      free (tst);
+    }
+
+  if (nderived > 6)
+    fprintf (stderr,
+	     _("More than 6 derived type specifiers, result is invalid.\n"));
+
+  /* Our type computation so far used the reverse order for derived
+     type specifiers.  Fix this here if there was more than one
+     derived type specifier. */
+  if (nderived > 1)
+    {
+      unsigned int nty, bty;
+      bty = type & N_BTMASK;
+      type = type >> N_BTSHFT;
+      nty = 0;
+      while (nderived-- > 0)
+	{
+	  nty = (nty << N_TSHIFT) | (type & (N_TMASK >> N_BTSHFT));
+	  type >>= N_TSHIFT;
+	}
+      type = (nty << N_BTSHFT) | bty;
+    }
+
+  if (ISARY (type))
+    {
+      /* Compute size of entire array. */
+      for (i = 0, nele = 1; i < arydim; i++)
+	nele *= aux->x_sym.x_fcnary.x_ary.x_dimen[i];
+      aux->x_sym.x_misc.x_lnsz.x_size = size * nele;
+    }
+
+  numaux = 0;
+  if (ISARY (type) || ISFCN (type))
+    numaux++;
+  if ((BTYPE (type) == T_STRUCT || BTYPE (type) == T_UNION
+       || BTYPE (type) == T_ENUM)
+      && !oldavrcoff)
+    numaux++;
+  /* Only AVR COFF uses multiple AUX entries. */
+  if (numaux > 1 && (info->flags & COFF_FL_AVR) == 0)
+    numaux = 1;
+
+  priv->size = size;
+  (*csympp)->symbol.udata.p = priv;
+  (*csympp)->native->u.syment.n_type = type;
+  (*csympp)->native->u.syment.n_numaux = numaux;
+
+  /* If the fundamental type comes out as T_NULL, this means we don't
+     have any type information.  Just don't emit any aux entries in
+     that case, and drop any derived type information as well. */
+  if (BTYPE (type) == T_NULL)
+    {
+      printf ("coff_make_typed_symbol() -> T_NULL\n");
+      //(*csympp)->native->u.syment.n_type = T_NULL;
+      (*csympp)->native->u.syment.n_numaux = 0;
+    }
+
+  return TRUE;
+}
+
+static bfd_boolean coff_emit_struct (info, tst, shash)
+     struct coff_write_handle *info;
+     struct coff_type_stack *tst;
+     struct coff_struct_hash_entry *shash;
+{
+  coff_symbol_type *csymp, *scsymp, *ecsymp;
+  union internal_auxent *aux;
+  struct coff_fix_stack *fixp, *ofp;
+  bfd_boolean isstruct = tst->u.ts_struct.isstruct;
+  bfd_boolean isbitfield = FALSE;
+  struct coff_type_stack *savedtst;
+  struct coff_struct_fields *fp;
+  unsigned short sclass;
+  long i;
+
+  if ((info->flags & (COFF_FL_AVR | COFF_FL_EXT_AVR)) ==
+      COFF_FL_AVR)
+    /* old AVR COFF doesn't support struct debugging */
+    return TRUE;
+
+  /* Synthesize a new internal COFF symbol for the struct/union. */
+  scsymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (scsymp == NULL)
+    return FALSE;
+
+  if (tst->u.ts_struct.tagismalloced)
+    scsymp->symbol.name = xstrdup (tst->u.ts_struct.tag.malloctag);
+  else
+    scsymp->symbol.name = tst->u.ts_struct.tag.fixtag;
+  scsymp->symbol.flags = BSF_NOT_AT_END;
+  scsymp->symbol.section = bfd_und_section_ptr;
+  scsymp->native->u.syment.n_sclass = isstruct? C_STRTAG: C_UNTAG;
+  scsymp->native->u.syment.n_type = isstruct? T_STRUCT: T_UNION;
+  scsymp->native->u.syment.n_numaux = 1;
+  scsymp->symbol.udata.p = NULL;
+  scsymp->symbol.value = 0;
+
+  shash->native = scsymp->native;
+
+  /* Synthesize a new internal COFF symbol for the end of struct/union. */
+  ecsymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (ecsymp == NULL)
+    return FALSE;
+
+  ecsymp->symbol.name = ".eos";
+  ecsymp->symbol.flags = BSF_NOT_AT_END;
+  /* We need to use the com section here since bfd/coffgen.c
+     translates this into an N_UNDEF one without clobbering the
+     value. */
+  ecsymp->symbol.section = bfd_com_section_ptr;
+  ecsymp->native->u.syment.n_sclass = C_EOS;
+  ecsymp->symbol.udata.p = NULL;
+  ecsymp->symbol.value = tst->u.ts_struct.size;
+  ecsymp->native->u.syment.n_numaux = 1;
+  (ecsymp->native + 1)->fix_tag = 1;
+  aux = &((ecsymp->native + 1)->u.auxent);
+  aux->x_sym.x_tagndx.p = scsymp->native;
+  aux->x_sym.x_misc.x_lnsz.x_size = tst->u.ts_struct.size;
+
+  coff_record_symbol (info, scsymp);
+
+  savedtst = info->tstack;
+
+  if (isstruct)
+    {
+      /* First, make a quick walk along all the fields, and figure out
+       * whether we've got a genuine struct or a bitfield struct. */
+      for (i = 0, fp = tst->u.ts_struct.fields;
+	   i < tst->u.ts_struct.nfields;
+	   i++, fp++)
+	if (fp->bitsize % 8 != 0)
+	  {
+	    isbitfield = TRUE;
+	    break;
+	  }
+    }
+
+  sclass = isstruct? (isbitfield? C_FIELD: C_MOS): C_MOU;
+
+  for (i = 0, fp = tst->u.ts_struct.fields;
+       i < tst->u.ts_struct.nfields;
+       i++, fp++)
+    {
+      if (strlen (fp->name) == 0)
+	{
+	  /* empty name could happen inside bitfield */
+	  fp->types = NULL;
+	  continue;
+	}
+
+      info->tstack = fp->types;
+      if (!coff_make_typed_symbol (info, &csymp, TS_NONE))
+	return FALSE;
+
+      csymp->symbol.name = xstrdup (fp->name);
+      csymp->symbol.flags = BSF_NOT_AT_END;
+      csymp->symbol.section = bfd_com_section_ptr;
+      csymp->native->u.syment.n_sclass = sclass;
+      csymp->symbol.value = isbitfield? fp->bitpos: fp->bitpos / 8;
+      if (isbitfield)
+	{
+	  csymp->native->u.syment.n_numaux = 1;
+	  aux = &((csymp->native + 1)->u.auxent);
+	  aux->x_sym.x_misc.x_lnsz.x_size = fp->bitsize;
+	}
+
+      coff_record_symbol (info, csymp);
+
+      fp->types = NULL;
+    }
+
+  info->tstack = savedtst;
+
+  /* Record our endndx field for later fixing. */
+  fixp = (struct coff_fix_stack *) xmalloc (sizeof (struct coff_fix_stack));
+  fixp->native = scsymp->native + 1;	/* points to first AUX */
+  fixp->next = NULL;
+  if (info->fixes == NULL)
+    info->fixes = fixp;
+  else
+    {
+      for (ofp = info->fixes; ofp->next != NULL;)
+	ofp = ofp->next;
+      ofp->next = fixp;
+    }
+
+  coff_record_symbol (info, ecsymp);
+  info->flags |= COFF_FL_FIX_ENDNDX;
+
+  return TRUE;
+}
+
+static bfd_boolean coff_emit_enum (info, tst, ehash)
+     struct coff_write_handle *info;
+     struct coff_type_stack *tst;
+     struct coff_enum_hash_entry *ehash;
+{
+  coff_symbol_type *csymp, *scsymp, *ecsymp;
+  union internal_auxent *aux;
+  struct coff_fix_stack *fixp, *ofp;
+  int i;
+
+  if ((info->flags & (COFF_FL_AVR | COFF_FL_EXT_AVR)) ==
+      COFF_FL_AVR)
+    /* old AVR COFF doesn't support enum debugging */
+    return TRUE;
+
+  /* Synthesize a new internal COFF symbol for the enum. */
+  scsymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (scsymp == NULL)
+    return FALSE;
+
+  if (tst->u.ts_enum.tagismalloced)
+    scsymp->symbol.name = xstrdup (tst->u.ts_enum.tag.malloctag);
+  else
+    scsymp->symbol.name = tst->u.ts_enum.tag.fixtag;
+  scsymp->symbol.flags = BSF_NOT_AT_END;
+  scsymp->symbol.section = bfd_und_section_ptr;
+  scsymp->native->u.syment.n_sclass = C_ENTAG;
+  scsymp->native->u.syment.n_type = T_ENUM;
+  scsymp->native->u.syment.n_numaux = 1;
+  scsymp->symbol.udata.p = NULL;
+  scsymp->symbol.value = 0;
+
+  ehash->native = scsymp->native;
+
+  /* Synthesize a new internal COFF symbol for the end of struct/union. */
+  ecsymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (ecsymp == NULL)
+    return FALSE;
+
+  ecsymp->symbol.name = ".eos";
+  ecsymp->symbol.flags = BSF_NOT_AT_END;
+  /* We need to use the com section here since bfd/coffgen.c
+     translates this into an N_UNDEF one without clobbering the
+     value. */
+  ecsymp->symbol.section = bfd_com_section_ptr;
+  ecsymp->native->u.syment.n_sclass = C_EOS;
+  ecsymp->symbol.udata.p = NULL;
+  ecsymp->symbol.value = info->enumsize;
+  ecsymp->native->u.syment.n_numaux = 1;
+  (ecsymp->native + 1)->fix_tag = 1;
+  aux = &((ecsymp->native + 1)->u.auxent);
+  aux->x_sym.x_tagndx.p = scsymp->native;
+  aux->x_sym.x_misc.x_lnsz.x_size = info->enumsize;
+
+  coff_record_symbol (info, scsymp);
+
+  for (i = 0;; i++)
+    {
+      const char *name = tst->u.ts_enum.names[i];
+      if (name == NULL)
+	break;
+
+      /* Synthesize a new internal COFF symbol for the enum. */
+      csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+      if (csymp == NULL)
+	return FALSE;
+
+      csymp->symbol.name = xstrdup (name);
+      csymp->symbol.flags = BSF_NOT_AT_END;
+      csymp->symbol.section = bfd_com_section_ptr;
+      csymp->native->u.syment.n_sclass = C_MOE;
+      csymp->symbol.udata.p = NULL;
+      csymp->symbol.value = tst->u.ts_enum.vals[i];
+
+      coff_record_symbol (info, csymp);
+    }
+
+  /* Record our endndx field for later fixing. */
+  fixp = (struct coff_fix_stack *) xmalloc (sizeof (struct coff_fix_stack));
+  fixp->native = scsymp->native + 1;	/* points to first AUX */
+  fixp->next = NULL;
+  if (info->fixes == NULL)
+    info->fixes = fixp;
+  else
+    {
+      for (ofp = info->fixes; ofp->next != NULL;)
+	ofp = ofp->next;
+      ofp->next = fixp;
+    }
+
+  coff_record_symbol (info, ecsymp);
+  info->flags |= COFF_FL_FIX_ENDNDX;
+
+  return TRUE;
+}
+
+/* Emit a non-debugging symbol that came from the input symbol table,
+   and has not been claimed by one of the debugging symbols. */
+static bfd_boolean
+coff_emit_ndebug_sym (info, osymp, localp)
+     struct coff_write_handle *info;
+     asymbol *osymp;
+     bfd_boolean localp;
+{
+  coff_symbol_type *csymp;
+
+  /* Create new COFF symbol. */
+  csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (csymp == NULL)
+    return FALSE;
+
+  csymp->symbol.name = xstrdup (osymp->name);
+  csymp->symbol.value = osymp->value;
+  csymp->symbol.flags = localp? BSF_LOCAL: BSF_GLOBAL;
+  csymp->symbol.section = osymp->section;
+  csymp->symbol.udata.p = NULL;
+  csymp->native->u.syment.n_sclass = localp? C_STAT: C_EXT;
+  csymp->native->u.syment.n_type = T_NULL;
+
+  coff_record_symbol (info, csymp);
+
+  return TRUE;
+}
+
+/* The general routine to write out COFF debugging information.  This
+   synthesizes and accumulates the COFF symbols.  Actual symbol table
+   output is performed later on by the BFD functions.  ABFD is the BFD
+   and DHANDLE is the handle for the debugging information.  symcountp
+   and symppp point to the incoming (parsed) symbol list on entry, and
+   will be updated to point to the new symbol table's values upon
+   exit. */
+
+bfd_boolean
+write_coff_debugging_info (abfd, dhandle, symcountp, symppp)
+     bfd *abfd;
+     PTR dhandle;
+     long *symcountp;
+     asymbol ***symppp;
+{
+  struct coff_write_handle info;
+  long i, l;
+  asymbol *symp;
+  struct coff_compilation_unit *up;
+  coff_symbol_type *csymp;
+
+  memset ((void *)&info, 0, sizeof info);
+
+  info.abfd = abfd;
+
+  info.pointersize = info.enumsize = 4;
+
+  switch (bfd_get_arch (abfd))
+    {
+    case bfd_arch_avr:
+      info.flags |= COFF_FL_AVR;
+      if (strcmp (abfd->xvec->name, "coff-ext-avr") == 0)
+	info.flags |= COFF_FL_EXT_AVR;
+      /* Fix the builtin type sizes. */
+      coff_predef_types[0].size = 2;	/* sizeof(int) == 2 */
+      coff_predef_types[4].size = 4;	/* sizeof(double) == 4 */
+      coff_predef_types[6].size = 2;	/* sizeof(unsigned int) == 2 */
+      info.pointersize = info.enumsize = 2;
+      break;
+
+    default:
+      ;
+    }
+
+  coff_copy_symbols(&info, *symcountp, *symppp);
+
+  if (info.textsect == NULL)
+    {
+      fprintf (stderr, _("Warning: no \"text\" section found in output file\n"));
+      info.textsect = bfd_abs_section_ptr;
+    }
+  if (info.datasect == NULL)
+    {
+      fprintf (stderr, _("Warning: no \"data\" section found in output file\n"));
+      info.datasect = bfd_abs_section_ptr;
+    }
+
+  if (! bfd_hash_table_init (&info.types.root, coff_name_type_newfunc,
+			     sizeof(struct coff_name_type_hash_entry)))
+    return FALSE;
+
+  if (! bfd_hash_table_init (&info.structs.root, coff_struct_newfunc,
+			     sizeof(struct coff_struct_hash_entry)))
+    return FALSE;
+
+  if (! bfd_hash_table_init (&info.enums.root, coff_enum_newfunc,
+			     sizeof(struct coff_enum_hash_entry)))
+    return FALSE;
+
+  if (! debug_write (dhandle, &coff_fns, (PTR) &info))
+    return FALSE;
+
+  /* If there is an old compilation unit that has got any local
+     non-debugging symbols left over, send them out now. */
+  if (info.currentfile != NULL && info.currentfile->totsyms != 0)
+    for (i = 0; i < info.currentfile->nsyms; i++)
+      {
+	up = info.currentfile;
+
+	if (up->syms[i] != NULL)
+	  {
+	    coff_emit_ndebug_sym (&info, up->syms[i], TRUE);
+	    up->syms[i] = NULL;
+	    up->totsyms--;
+	  }
+      }
+
+  /* See whether there are any non-debugging symbols left from the
+     input symbol table.  First look at all local symbols which must
+     be from entire compilation units we didn't see yet in the
+     debugging information, because anything else has already been
+     handled at the end of each compilation unit (like in the loop
+     immediately above).  Any compilation unit that has already been
+     processed that way is supposed to have its "totsyms" counted down
+     to 0 now, so we can skip them.
+
+     Finally, put out all remaining global non-debugging symbols. */
+  for (l = 0; l < info.nunits; l++)
+    {
+      const char *bn;
+
+      up = info.units + l;
+      if (up->totsyms == 0)
+	continue;
+
+      /* Create COFF symbol for this compilation unit. */
+      csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info.abfd, 0, 0);
+      if (csymp == NULL)
+	return FALSE;
+
+      bn = bu_basename (up->fname);
+
+      if (bfd_coff_long_filenames (info.abfd))
+	csymp->symbol.name = up->fname;
+      else
+	csymp->symbol.name = bn;
+
+      csymp->symbol.value = 0;
+      csymp->symbol.udata.p = NULL;
+      csymp->native->u.syment.n_sclass = C_FILE;
+      csymp->native->u.syment.n_numaux = 1; /* force filename into aux entry */
+      coff_record_symbol (&info, csymp);
+
+      for (i = 0; i < up->nsyms; i++)
+	{
+	  symp = up->syms[i];
+	  if (symp == NULL)
+	    continue;
+
+	  coff_emit_ndebug_sym (&info, symp, TRUE);
+	}
+    }
+
+  for (i = 0; i < info.nglobals; i++)
+    {
+      symp = info.globals[i];
+      if (symp == NULL)
+	continue;
+
+      coff_emit_ndebug_sym (&info, symp, FALSE);
+    }
+
+  /* Fixup the AUX entries for the section symbols we have emitted
+     earlier (so they are guaranteed to be at the beginning of the
+     symbol table).  In particular, the line number count (which we
+     only have for the text section) is known right now. */
+  for (i = 0; i < info.nsecsyms; i++)
+    {
+      union internal_auxent *aux;
+
+      csymp = info.secsyms[i];
+
+      aux = &((csymp->native + 1)->u.auxent);
+      aux->x_scn.x_scnlen = csymp->symbol.section->output_section->rawsize;
+      aux->x_scn.x_nreloc = csymp->symbol.section->reloc_count;
+      if (csymp->symbol.section == info.textsect)
+	aux->x_scn.x_nlinno = info.totlnos;
+    }
+  free (info.secsyms);
+
+  coff_name_type_hash_traverse (&info.types, coff_free_type_info, NULL);
+  bfd_hash_table_free (&info.types.root);
+
+  coff_struct_hash_traverse (&info.structs, coff_free_struct_info, NULL);
+  bfd_hash_table_free (&info.structs.root);
+
+  coff_enum_hash_traverse (&info.enums, coff_free_enum_info, NULL);
+  bfd_hash_table_free (&info.enums.root);
+
+  /* FIXME: free all the other stuff remembered in "info". */
+
+  free (*symppp);
+
+  *symcountp = info.nsyms;
+  *symppp = (asymbol **)info.syms;
+
+  return TRUE;
+}
+
+/* Start writing out information for a compilation unit.  */
+
+static bfd_boolean
+coff_start_compilation_unit (p, filename)
+     PTR p;
+     const char *filename;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  long i;
+  const char *bn;
+  bfd_boolean found;
+  coff_symbol_type *csymp;
+
+#if COFF_DEBUG
+  printf ("coff_start_compilation_unit(%s)\n", filename);
+#endif
+
+  /* If there is an old compilation unit that has got any local
+     non-debugging symbols left over, send them out now. */
+  if (info->currentfile != NULL && info->currentfile->totsyms != 0)
+    for (i = 0; i < info->currentfile->nsyms; i++)
+      {
+	struct coff_compilation_unit *up = info->currentfile;
+
+	if (up->syms[i] != NULL)
+	  {
+	    coff_emit_ndebug_sym (info, up->syms[i], TRUE);
+	    up->syms[i] = NULL;
+	    up->totsyms--;
+	  }
+      }
+
+  /* symtab (and thus COFF debugging) symbols can only transfer the
+     basename of the file, so strip the dirname */
+  bn = bu_basename (filename);
+
+  for (i = 0, found = FALSE; i < info->nunits; i++)
+    {
+      if (strcmp (info->units[i].fname, bn) == 0)
+	{
+	  info->currentfile = info->units + i;
+	  found = TRUE;
+	  break;
+	}
+    }
+  if (!found)
+    {
+      fprintf(stderr,
+	      _("Warning: file %s not found in symbol table, ignoring\n"),
+	      filename);
+      info->currentfile = NULL;
+      return TRUE;
+    }
+
+  /* Synthesize a new internal COFF symbol. */
+  csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (csymp == NULL)
+    return FALSE;
+
+  /* Note that coff_fix_symbol_name() [coffgen.c] will fix this for
+     us: the symbol name will be replaced by ".file", and the filename
+     will be moved to the aux entries.  We use the long name obtained
+     from the debugging information (that includes the full path) if
+     our COFF format supports long filenames, otherwise we only use
+     the basename of the file. */
+  if (bfd_coff_long_filenames (info->abfd))
+    csymp->symbol.name = filename;
+  else
+    csymp->symbol.name = bn;
+  csymp->symbol.value = 0;
+  csymp->symbol.udata.p = NULL;
+  csymp->native->u.syment.n_sclass = C_FILE;
+  csymp->native->u.syment.n_numaux = 1;	/* force filename into aux entry */
+  coff_record_symbol (info, csymp);
+
+  return TRUE;
+}
+
+/* Start writing out information for a particular source file.  */
+
+static bfd_boolean
+coff_start_source (p, filename)
+     PTR p ATTRIBUTE_UNUSED;
+     const char *filename ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_start_source(%s)\n", filename);
+#endif
+
+  /* COFF cannot handle include filenames. */
+
+  return TRUE;
+}
+
+/* Push an empty type.  This shouldn't normally happen.  */
+
+static bfd_boolean
+coff_empty_type (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_empty_type()\n");
+#endif
+
+  coff_push_type (TS_EMPTY);
+
+  return TRUE;
+}
+
+/* Push a void type.  */
+
+static bfd_boolean
+coff_void_type (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_void_type()\n");
+#endif
+
+  coff_push_type (TS_VOID);
+
+  return TRUE;
+}
+
+/* Push an integer type.  */
+
+static bfd_boolean
+coff_int_type (p, size, unsignedp)
+     PTR p;
+     unsigned int size;
+     bfd_boolean unsignedp;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_int_type(%d, %d)\n", size, unsignedp);
+#endif
+
+  coff_push_type (TS_INT);
+  tst->u.ts_int.size = size;
+  tst->u.ts_int.isunsigned = unsignedp;
+
+  return TRUE;
+}
+
+/* Push a floating point type.  */
+
+static bfd_boolean
+coff_float_type (p, size)
+     PTR p;
+     unsigned int size;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_float_type(%d)\n", size);
+#endif
+
+  coff_push_type (TS_FLOAT);
+  tst->u.ts_float.size = size;
+
+  return TRUE;
+}
+
+/* Push a complex type.  */
+
+static bfd_boolean
+coff_complex_type (p, size)
+     PTR p;
+     unsigned int size ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_complex_type(%d)\n", size);
+#endif
+
+  coff_push_type (TS_COMPLEX);
+
+  return TRUE;
+}
+
+/* Push a bfd_boolean type. */
+
+static bfd_boolean
+coff_bool_type (p, size)
+     PTR p;
+     unsigned int size;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_bool_type(%d)\n", size);
+#endif
+
+  coff_push_type (TS_INT);
+  tst->u.ts_int.size = size;
+  tst->u.ts_int.isunsigned = TRUE;
+
+  return TRUE;
+}
+
+/* Push an enum type.  */
+
+static bfd_boolean
+coff_enum_type (p, tag, names, vals)
+     PTR p;
+     const char *tag;
+     const char **names;
+     bfd_signed_vma *vals;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+  char buf[20];
+
+#if COFF_DEBUG
+  int idx;
+  printf ("coff_enum_type(%s [", tag);
+  for (idx = 0; names[idx] != NULL; idx++)
+    printf ("%s -> %d, ", names[idx], (int)vals[idx]);
+  printf ("])\n");
+#endif
+
+  coff_push_type (TS_ENUM);
+
+  if (tag == NULL)
+    {
+      sprintf(buf, ".%dfake", info->nenums++);
+      tst->u.ts_enum.tag.malloctag = xstrdup (buf);
+      tst->u.ts_enum.tagismalloced = TRUE;
+    }
+  else
+    tst->u.ts_enum.tag.fixtag = tag;
+  tst->u.ts_enum.names = names;
+  tst->u.ts_enum.vals = vals;
+
+  return TRUE;
+}
+
+/* Push a pointer type.  */
+
+static bfd_boolean
+coff_pointer_type (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_pointer_type()\n");
+#endif
+
+  coff_push_type (TS_POINTER);
+
+  return TRUE;
+}
+
+/* Push a function type.  */
+
+static bfd_boolean
+coff_function_type (p, argcount, varargs)
+     PTR p;
+     int argcount;
+     bfd_boolean varargs ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_function_type(%d, %d)\n", argcount, varargs);
+#endif
+
+  coff_push_type (TS_FUNC);
+
+  /* FIXME should properly discard function arguments */
+  if (argcount > -1)
+    {
+      fprintf (stderr,
+	       _("coff_function_type() called with positive argcount\n"));
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+/* Push a reference type.  */
+
+static bfd_boolean
+coff_reference_type (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_reference_type()\n");
+#endif
+
+  coff_complain_unsupp (_("reference"));
+
+  return TRUE;
+}
+
+/* Push a range type.  */
+
+static bfd_boolean
+coff_range_type (p, low, high)
+     PTR p;
+     bfd_signed_vma low ATTRIBUTE_UNUSED;
+     bfd_signed_vma high ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_range_type([%d..%d)\n", (int)low, (int)high);
+#endif
+
+  coff_complain_unsupp (_("range"));
+
+  return TRUE;
+}
+
+/* Push an array type.  */
+
+static bfd_boolean
+coff_array_type (p, low, high, stringp)
+     PTR p;
+     bfd_signed_vma low;
+     bfd_signed_vma high;
+     bfd_boolean stringp;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst;
+
+#if COFF_DEBUG
+  printf ("coff_array_type([%d..%d], %d)\n",
+	  (int)low, (int)high, stringp);
+#endif
+
+  /* Pop the range type, but ignore it.  COFF doesn't use it. */
+  coff_pop_type ();
+
+  /* FIXME  What to do here? */
+  if (stringp)
+    {
+      fprintf(stderr, _("coff_array_type(): stringp == TRUE\n"));
+      return FALSE;
+    }
+
+  coff_push_type (TS_ARRAY);
+  tst->u.ts_array.low = low;
+  tst->u.ts_array.high = high;
+
+  return TRUE;
+}
+
+/* Push a set type.  */
+
+static bfd_boolean
+coff_set_type (p, bitstringp)
+     PTR p;
+     bfd_boolean bitstringp ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_set_type(%d)\n", bitstringp);
+#endif
+
+  coff_complain_unsupp (_("set"));
+
+  return TRUE;
+}
+
+/* Push an offset type.  */
+
+static bfd_boolean
+coff_offset_type (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_offset_type()\n");
+#endif
+
+  coff_complain_unsupp (_("offset"));
+
+  return TRUE;
+}
+
+/* Push a method type.  */
+
+static bfd_boolean
+coff_method_type (p, domainp, argcount, varargs)
+     PTR p;
+     bfd_boolean domainp ATTRIBUTE_UNUSED;
+     int argcount ATTRIBUTE_UNUSED;
+     bfd_boolean varargs ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_method_type(%d, %d, %d)\n",
+	  domainp, argcount, varargs);
+#endif
+
+  coff_complain_unsupp (_("method"));
+
+  return TRUE;
+}
+
+/* Push a const version of a type.  */
+
+static bfd_boolean
+coff_const_type (p)
+     PTR p ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_const_type()\n");
+#endif
+
+  /* const modifier is ignored by COFF */
+
+  return TRUE;
+}
+
+/* Push a volatile version of a type.  */
+
+static bfd_boolean
+coff_volatile_type (p)
+     PTR p ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_volatile_type()\n");
+#endif
+
+  /* volatile modifier is ignored by COFF */
+
+  return TRUE;
+}
+
+/* Start outputting a struct.  */
+
+static bfd_boolean
+coff_start_struct_type (p, tag, id, structp, size)
+     PTR p;
+     const char *tag;
+     unsigned int id;
+     bfd_boolean structp;
+     unsigned int size;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst, *savedts;
+  struct coff_struct_hash_entry *shash;
+  char buf[20];
+  const char *name;
+
+#if COFF_DEBUG
+  printf ("coff_start_struct_type(%s, %d, %d, %d)\n",
+	  tag, id, structp, size);
+#endif
+
+  savedts = info->tstack;
+  info->tstack = NULL;
+
+  coff_push_type (TS_STRUCT);
+
+  if (tag == NULL)
+    {
+      sprintf(buf, ".%dfake", id);
+      name = tst->u.ts_struct.tag.malloctag = xstrdup (buf);
+      tst->u.ts_struct.tagismalloced = TRUE;
+    }
+  else
+    name = tst->u.ts_struct.tag.fixtag = tag;
+  tst->u.ts_struct.id = id;
+  tst->u.ts_struct.isstruct = structp;
+  tst->u.ts_struct.size = size;
+  tst->u.ts_struct.savedts = savedts;
+
+  shash = coff_struct_hash_lookup (&info->structs, name, FALSE, FALSE);
+  if (shash != NULL && shash->types != NULL)
+    {
+#if COFF_DEBUG
+      printf ("new %s definition for %s\n",
+	      tst->u.ts_struct.isstruct? "struct": "union", name);
+#endif
+      coff_free_struct_info (shash, NULL);
+      shash->types = NULL;
+      shash->emitted = FALSE;
+    }
+  else
+    (void)coff_struct_hash_lookup (&info->structs, name,
+			     TRUE, tst->u.ts_struct.tagismalloced);
+
+  return TRUE;
+}
+
+/* Add a field to a struct.  */
+
+static bfd_boolean
+coff_struct_field (p, name, bitpos, bitsize, visibility)
+     PTR p;
+     const char *name;
+     bfd_vma bitpos;
+     bfd_vma bitsize;
+     enum debug_visibility visibility;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst, *otst;
+  struct coff_struct_fields *fp;
+  struct coff_struct_hash_entry *shash;
+  struct coff_enum_hash_entry *ehash;
+  const char *tag;
+
+#if COFF_DEBUG
+  printf ("coff_struct_field(%s, %d, %d, %d)\n",
+	  name, (int)bitpos, (int)bitsize, (int)visibility);
+#endif
+
+  /* Find the last element on the type stack. */
+  assert (info->tstack != NULL);
+  for (tst = info->tstack, otst = NULL; tst->next != NULL;)
+    {
+      otst = tst;
+      tst = tst->next;
+    }
+  if (otst != NULL)
+    otst->next = NULL;
+
+  if (tst->tsk != TS_STRUCT)
+    {
+      fprintf (stderr, "coff_struct_field() not within structure definition\n");
+      return FALSE;
+    }
+  tst->u.ts_struct.fields = (struct coff_struct_fields *)
+    xrealloc (tst->u.ts_struct.fields,
+	      ++tst->u.ts_struct.nfields * sizeof (struct coff_struct_fields));
+  fp = tst->u.ts_struct.fields + (tst->u.ts_struct.nfields - 1);
+  fp->name = name;
+  fp->bitpos = bitpos;
+  fp->bitsize = bitsize;
+  fp->visibility = visibility;
+  otst = fp->types = info->tstack;
+  while (otst->next != NULL)
+    otst = otst->next;
+  if (otst->tsk == TS_STRUCT && otst->u.ts_struct.shash == NULL)
+    {
+      if (otst->u.ts_struct.tagismalloced)
+	tag = otst->u.ts_struct.tag.malloctag;
+      else
+	tag = otst->u.ts_struct.tag.fixtag;
+      shash = coff_struct_hash_lookup (&info->structs, tag, FALSE, FALSE);
+      assert (shash != NULL);
+      if (!shash->emitted)
+	{
+	  if (shash->types == NULL)
+	    {
+	      shash->types = (struct coff_type_stack *)
+		xmalloc (sizeof (struct coff_type_stack));
+	      memcpy (shash->types, otst, sizeof (struct coff_type_stack));
+	    }
+	  shash->emitted = TRUE;
+	  coff_emit_struct (info, otst, shash);
+	}
+    }
+  else if (otst->tsk == TS_ENUM)
+    {
+      if (otst->u.ts_enum.tagismalloced)
+	tag = otst->u.ts_enum.tag.malloctag;
+      else
+	tag = otst->u.ts_enum.tag.fixtag;
+      ehash = coff_enum_hash_lookup (&info->enums, tag, TRUE, FALSE);
+      assert (ehash != NULL);
+      if (!ehash->emitted)
+	{
+	  if (ehash->types == NULL)
+	    {
+	      ehash->types = (struct coff_type_stack *)
+		xmalloc (sizeof (struct coff_type_stack));
+	      memcpy (ehash->types, otst, sizeof (struct coff_type_stack));
+	    }
+	  ehash->emitted = TRUE;
+	  coff_emit_enum (info, otst, ehash);
+	}
+    }
+
+  info->tstack = tst;
+
+  return TRUE;
+}
+
+/* Finish up a struct.  */
+
+static bfd_boolean
+coff_end_struct_type (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst, *savedts;
+
+#if COFF_DEBUG
+  printf ("coff_end_struct_type()\n");
+#endif
+
+  /* Our struct definition should be the only type stack element by
+     now. */
+  assert (info->tstack != NULL);
+  tst = info->tstack;
+  if (tst->tsk != TS_STRUCT || tst->next != NULL)
+    {
+      fprintf (stderr, "coff_struct_field() not within structure definition\n");
+      return FALSE;
+    }
+
+  /* Restore saved type stack, and push our now complete struct
+     definition on top. */
+  savedts = tst->u.ts_struct.savedts;
+  tst->u.ts_struct.savedts = info->tstack;
+  info->tstack = savedts;
+  tst->next = info->tstack;
+  info->tstack = tst;
+
+  return TRUE;
+}
+
+/* Start outputting a class.  */
+
+static bfd_boolean
+coff_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
+     PTR p;
+     const char *tag ATTRIBUTE_UNUSED;
+     unsigned int id ATTRIBUTE_UNUSED;
+     bfd_boolean structp ATTRIBUTE_UNUSED;
+     unsigned int size ATTRIBUTE_UNUSED;
+     bfd_boolean vptr ATTRIBUTE_UNUSED;
+     bfd_boolean ownvptr ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_start_class_type(%s, %d, %d, %d, %d, %d)\n",
+	  tag, id, structp, size, vptr, ownvptr);
+#endif
+
+  coff_complain_unsupp (_("class"));
+
+  return TRUE;
+}
+
+/* Add a static member to the class on the type stack.  */
+
+static bfd_boolean
+coff_class_static_member (p, name, physname, visibility)
+     PTR p ATTRIBUTE_UNUSED;
+     const char *name ATTRIBUTE_UNUSED;
+     const char *physname ATTRIBUTE_UNUSED;
+     enum debug_visibility visibility ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_class_static_member(%s, %s, %d)\n",
+	  name, physname, (int)visibility);
+#endif
+
+  return TRUE;
+}
+
+/* Add a base class to the class on the type stack.  */
+
+static bfd_boolean
+coff_class_baseclass (p, bitpos, virtual, visibility)
+     PTR p ATTRIBUTE_UNUSED;
+     bfd_vma bitpos ATTRIBUTE_UNUSED;
+     bfd_boolean virtual ATTRIBUTE_UNUSED;
+     enum debug_visibility visibility ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_class_baseclass(%d, %d, %d)\n",
+	  (int)bitpos, virtual, (int)visibility);
+#endif
+
+  return TRUE;
+}
+
+/* Start adding a method to the class on the type stack.  */
+
+static bfd_boolean
+coff_class_start_method (p, name)
+     PTR p ATTRIBUTE_UNUSED;
+     const char *name ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_class_start_method(%s)\n", name);
+#endif
+
+  return TRUE;
+}
+
+/* Add a variant to the current method.  */
+
+static bfd_boolean
+coff_class_method_variant (p, physname, visibility, constp, volatilep,
+			   voffset, contextp)
+     PTR p ATTRIBUTE_UNUSED;
+     const char *physname ATTRIBUTE_UNUSED;
+     enum debug_visibility visibility ATTRIBUTE_UNUSED;
+     bfd_boolean constp ATTRIBUTE_UNUSED;
+     bfd_boolean volatilep ATTRIBUTE_UNUSED;
+     bfd_vma voffset ATTRIBUTE_UNUSED;
+     bfd_boolean contextp ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_class_method_variant(%s, %d, %d, %d, %d, %d)\n",
+	  physname, (int)visibility, constp, volatilep,
+	  (int)voffset, contextp);
+#endif
+
+  return TRUE;
+}
+
+/* Add a static variant to the current method.  */
+
+static bfd_boolean
+coff_class_static_method_variant (p, physname, visibility, constp, volatilep)
+     PTR p ATTRIBUTE_UNUSED;
+     const char *physname ATTRIBUTE_UNUSED;
+     enum debug_visibility visibility ATTRIBUTE_UNUSED;
+     bfd_boolean constp ATTRIBUTE_UNUSED;
+     bfd_boolean volatilep ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_class_static_method_variant(%s, %d, %d, %d)\n",
+	  physname, (int)visibility, constp, volatilep);
+#endif
+
+  return TRUE;
+}
+
+/* Finish up a method.  */
+
+static bfd_boolean
+coff_class_end_method (p)
+     PTR p ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_class_end_method()\n");
+#endif
+
+  return TRUE;
+}
+
+/* Finish up a class.  */
+
+static bfd_boolean
+coff_end_class_type (p)
+     PTR p ATTRIBUTE_UNUSED;
+{
+
+#if COFF_DEBUG
+  printf ("coff_end_class_type()\n");
+#endif
+
+  return TRUE;
+}
+
+/* Push a typedef which was previously defined.  */
+
+static bfd_boolean
+coff_typedef_type (p, name)
+     PTR p;
+     const char *name;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_name_type_hash_entry *nthash;
+  struct coff_type_stack *tst, *newchain, *newst, *temp;
+
+#if COFF_DEBUG
+  printf ("coff_typedef_type(%s)\n", name);
+#endif
+
+  nthash = coff_name_type_hash_lookup (&info->types, name, FALSE, FALSE);
+
+  /* nthash should never be NULL, since that would imply that the
+     generic debugging code has asked for a typedef which it has not
+     yet defined.  */
+  assert (nthash != NULL);
+
+  /* Just push the entire type stack snapshot we've got on top of the
+     existing typestack.  See coff_typdef() below for how this
+     works.  We need to copy over each element however, since anybody
+     popping elements off the typestack is supposed to free() each of
+     them. */
+
+  for (tst = nthash->types, temp = newst = newchain = NULL; tst != NULL;)
+    {
+      temp = newst;
+      newst = (struct coff_type_stack *) xmalloc (sizeof (*newst));
+      if (newchain == NULL)
+	newchain = newst;
+      memcpy (newst, tst, sizeof (*newst));
+      if (temp != NULL)
+	temp->next = newst;
+
+      tst = tst->next;
+    }
+  newst->next = info->tstack;
+  info->tstack = newchain;
+
+  return TRUE;
+}
+
+/* Push a struct, union or class tag.  */
+
+static bfd_boolean
+coff_tag_type (p, name, id, kind)
+     PTR p;
+     const char *name;
+     unsigned int id ATTRIBUTE_UNUSED;
+     enum debug_type_kind kind;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst, *newchain, *newst, *temp;
+  struct coff_struct_hash_entry *shash;
+  struct coff_enum_hash_entry *ehash;
+  char buf[20];
+  bfd_boolean needcopy = FALSE;
+  bfd_boolean isstruct = TRUE;
+
+#if COFF_DEBUG
+  printf ("coff_tag_type(%s, %d, %d)\n",
+	  name, id, kind);
+#endif
+
+  if (name == NULL)
+    {
+      sprintf(buf, ".%dfake", id);
+      needcopy = TRUE;
+    }
+
+  switch (kind)
+    {
+    case DEBUG_KIND_UNION:
+    case DEBUG_KIND_UNION_CLASS:
+      isstruct = FALSE;
+      /* FALLTHROUGH */
+    case DEBUG_KIND_STRUCT:
+    case DEBUG_KIND_CLASS:
+      shash = coff_struct_hash_lookup (&info->structs,
+				       name == NULL? buf: name, TRUE, needcopy);
+      assert (shash != NULL);
+      tst = shash->types;
+      if (tst == NULL)
+	{
+	  /* This is a reference to a tag that has not yet been
+	     defined (i. e., a forward reference).  Synthesize a
+	     ts_struct entry by now, and mark it for later fixup. */
+	  tst = (struct coff_type_stack *) xmalloc (sizeof *tst);
+	  memset (tst, 0, sizeof *tst);
+	  tst->tsk = TS_STRUCT;
+	  tst->u.ts_struct.isstruct = isstruct;
+	  tst->u.ts_struct.shash = shash;
+	}
+    docopystack:
+      /* Just push the entire type stack snapshot we've got on top of the
+	 existing typestack.  See coff_typdef() below for how this
+	 works.  We need to copy over each element however, since anybody
+	 popping elements off the typestack is supposed to free() each of
+	 them. */
+      for (temp = newst = newchain = NULL; tst != NULL;)
+	{
+	  temp = newst;
+	  newst = (struct coff_type_stack *) xmalloc (sizeof (*newst));
+	  if (newchain == NULL)
+	    newchain = newst;
+	  memcpy (newst, tst, sizeof (*newst));
+	  if (temp != NULL)
+	    temp->next = newst;
+
+	  tst = tst->next;
+	}
+      if (newst)
+	{
+	  newst->next = info->tstack;
+	  info->tstack = newchain;
+	}
+      break;
+
+    case DEBUG_KIND_ENUM:
+      ehash = coff_enum_hash_lookup (&info->enums,
+				     name == NULL? buf: name, TRUE, needcopy);
+      assert (ehash != NULL);
+      tst = ehash->types;
+      if (tst == NULL)
+	{
+	  /* This is a reference to a tag that has not yet been
+	     defined (i. e., a forward reference).  Synthesize a
+	     ts_enum entry by now, and mark it for later fixup. */
+	  tst = (struct coff_type_stack *) xmalloc (sizeof *tst);
+	  memset (tst, 0, sizeof *tst);
+	  tst->tsk = TS_ENUM;
+	  tst->u.ts_enum.ehash = ehash;
+	}
+      goto docopystack;
+
+    default:
+      fprintf (stderr, _("illegal kind %d in coff_tag_type()\n"),
+	       (int)kind);
+      return FALSE;
+    }
+  return TRUE;
+}
+
+/* Define a typedef.  */
+
+static bfd_boolean
+coff_typdef (p, name)
+     PTR p;
+     const char *name;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_name_type_hash_entry *nthash;
+
+#if COFF_DEBUG
+  printf ("coff_typdef(%s)\n", name);
+#endif
+
+  /* COFF cannot really handle typedefs.  While there is the option to
+     mark a symbol using the storage class C_TPDEF (so the COFF reader
+     will know that name), there is no way to place a reference to
+     that typedef into the just 16 bits COFF reserves for all of its
+     type information.  Thus, any use of the typedef must always fully
+     dereference the typedef again.  We do this by "snapshotting" the
+     current type stack under the name of our typedef, and later on,
+     when BFD debugging tells us to make use of the typedef (in
+     coff_typedef_type()), we just look it up, and push all we've got
+     completely onto the type stack again. */
+
+  if (info->tstack == NULL)
+    {
+      fprintf (stderr, _("coff_typdef() on an empty type stack\n"));
+      return FALSE;
+    }
+
+  nthash = coff_name_type_hash_lookup (&info->types, name, FALSE, FALSE);
+  if (nthash != NULL)
+    {
+#if COFF_DEBUG
+      printf ("new typedef for %s\n", name);
+#endif
+      coff_free_type_info (nthash, NULL);
+    }
+  else
+    nthash = coff_name_type_hash_lookup (&info->types, name, TRUE, FALSE);
+  if (nthash == NULL)
+    return FALSE;
+  nthash->types = info->tstack;
+
+  /* If the typestack is "sufficiently complex", emit a C_TPDEF symbol
+     for it.  We assume it to be sufficiently complex if there are
+     either at least two derived types, or one derived type where the
+     base type is not a simple scalar one. */
+  if (!nthash->emitted
+      && info->tstack->next != NULL
+      && (info->tstack->next->next != NULL || info->tstack->next->tsk >= TS_ENUM))
+    {
+      struct coff_type_stack *newchain, *otst, *tst, *ntst;
+      coff_symbol_type *csymp;
+
+      nthash->emitted = TRUE;
+
+      for (tst = info->tstack, newchain = otst = NULL;
+	   tst != NULL;
+	   tst = tst->next)
+	{
+	  ntst = (struct coff_type_stack *)
+	    xmalloc (sizeof (struct coff_type_stack));
+	  memcpy (ntst, tst, sizeof (struct coff_type_stack));
+	  if (otst == NULL)
+	    newchain = ntst;
+	  else
+	    otst->next = ntst;
+	  otst = ntst;
+	}
+      info->tstack = newchain;
+      if (!coff_make_typed_symbol (info, &csymp, TS_NONE))
+	return FALSE;
+
+      csymp->symbol.name = xstrdup (name);
+      csymp->symbol.flags = BSF_NOT_AT_END;
+      csymp->symbol.section = bfd_com_section_ptr;
+      csymp->native->u.syment.n_sclass = C_TPDEF;
+      csymp->symbol.value = 0;
+
+      coff_record_symbol (info, csymp);
+    }
+  info->tstack = NULL;
+
+  return TRUE;
+}
+
+/* Define a tag.  */
+
+static bfd_boolean
+coff_tag (p, tag)
+     PTR p;
+     const char *tag;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst = NULL;
+  struct coff_struct_hash_entry *shash;
+  struct coff_enum_hash_entry *ehash;
+
+
+#if COFF_DEBUG
+  printf ("coff_tag(%s)\n", tag);
+#endif
+
+  if (info->tstack == NULL)
+    {
+      fprintf (stderr, _("coff_tag() called on an empty typestack\n"));
+      return FALSE;
+    }
+
+  switch (info->tstack->tsk)
+    {
+    case TS_STRUCT:
+      shash = coff_struct_hash_lookup (&info->structs, tag, FALSE, FALSE);
+      assert (shash != NULL);
+      shash->types = info->tstack;
+      info->tstack = NULL;
+      break;
+
+    case TS_ENUM:
+      ehash = coff_enum_hash_lookup (&info->enums, tag, FALSE, FALSE);
+      if (ehash != NULL && ehash->types != NULL)
+	{
+#if COFF_DEBUG
+	  printf ("new enum definition for %s\n", tag);
+#endif
+	  coff_free_enum_info (ehash, NULL);
+	}
+      else
+	ehash = coff_enum_hash_lookup (&info->enums, tag, TRUE, FALSE);
+      if (ehash == NULL)
+	return FALSE;
+      ehash->types = info->tstack;
+      info->tstack = NULL;
+      break;
+
+    default:
+      fprintf (stderr, _("Illegal typestack (%d) in coff_tag()\n"), tst->tsk);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+/* Define an integer constant.  */
+
+static bfd_boolean
+coff_int_constant (p, name, val)
+     PTR p;
+     const char *name ATTRIBUTE_UNUSED;
+     bfd_vma val ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_int_constant(%s, %d)\n", name, (int)val);
+#endif
+
+  coff_complain_unsupp (_("int constant"));
+
+  return TRUE;
+}
+
+/* Define a floating point constant.  */
+
+static bfd_boolean
+coff_float_constant (p, name, val)
+     PTR p;
+     const char *name ATTRIBUTE_UNUSED;
+     double val ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_float_constant(%s, %g)\n", name, val);
+#endif
+
+  coff_complain_unsupp (_("float constant"));
+
+  return TRUE;
+}
+
+/* Define a typed constant.  */
+
+static bfd_boolean
+coff_typed_constant (p, name, val)
+     PTR p;
+     const char *name ATTRIBUTE_UNUSED;
+     bfd_vma val ATTRIBUTE_UNUSED;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+
+#if COFF_DEBUG
+  printf ("coff_typed_constant(%s, %d)\n", name, (int)val);
+#endif
+
+  coff_complain_unsupp (_("typed constant"));
+
+  return TRUE;
+}
+
+/* Record a variable.  */
+
+static bfd_boolean
+coff_variable (p, name, kind, val)
+     PTR p;
+     const char *name;
+     enum debug_var_kind kind;
+     bfd_vma val;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  unsigned char class;
+  asymbol *symp = NULL;
+  coff_symbol_type *csymp;
+  bfd_boolean global = FALSE;
+  flagword flags = BSF_LOCAL;
+  bfd_vma vmadiff = 0;
+
+#if COFF_DEBUG
+  printf ("coff_variable(%s, %d, %d)\n",
+	  name, (int)kind, (int)val);
+#endif
+
+  switch (kind)
+    {
+    default:
+      abort ();
+
+    case DEBUG_GLOBAL:
+      flags = BSF_GLOBAL;
+      global = TRUE;
+      /* AVR COFF historically used C_EXTDEF for global variables, and
+	 C_EXT for global functions.  Since some AVR COFF consumers
+	 apparently depend on this, we mimic this behaviour as
+	 well. */
+      class = info->flags & COFF_FL_AVR? C_EXTDEF: C_EXT;
+      break;
+
+    case DEBUG_STATIC:
+    case DEBUG_LOCAL_STATIC:
+      class = C_STAT;
+      break;
+
+    case DEBUG_LOCAL:
+      class = C_AUTO;
+      break;
+
+    case DEBUG_REGISTER:
+      class = C_REG;
+      break;
+    }
+
+  if (!coff_make_typed_symbol (info, &csymp, TS_NONE))
+    return FALSE;
+
+  if (class == C_REG && (info->flags & COFF_FL_AVR) != 0)
+    {
+      struct coff_private_symdata *priv = (struct coff_private_symdata *)
+	csymp->symbol.udata.p;
+      val = coff_fixup_avr_register (val, priv->size * 8);
+    }
+
+  csymp->symbol.name = name;
+  csymp->symbol.flags = flags;	/* Note: this clears BSF_DEBUGGING. */
+
+  /* Match the debugging symbol against the input symtab symbols.  If
+     we found one, use the section information from it.  Otherwise, we
+     are lost here and just use the absolute section that was
+     predeclared by coff_bfd_make_debug_symbol().  C_REG and C_AUTO
+     symbols (which we do not attempt to lookup in the symtab symbols
+     at all) go into the ABS section anyway. */
+  if (class != C_REG && class != C_AUTO)
+    {
+      symp = coff_find_symbol (info, name, FALSE, global);
+      if (symp)
+	{
+	  csymp->symbol.section = symp->section;
+	  vmadiff = symp->section->vma;
+	}
+    }
+
+  /* Symbols are relative to section vma. */
+  csymp->symbol.value = val - vmadiff;
+  csymp->native->u.syment.n_sclass = class;
+  coff_record_symbol (info, csymp);
+
+  return TRUE;
+}
+
+/* Start outputting a function.  */
+
+static bfd_boolean
+coff_start_function (p, name, globalp)
+     PTR p;
+     const char *name;
+     bfd_boolean globalp;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst, *savedts;
+
+#if COFF_DEBUG
+  printf ("coff_start_function(%s, %d)\n",
+	  name, globalp);
+#endif
+
+  savedts = info->tstack;
+  info->tstack = NULL;
+
+  coff_push_type (TS_FUNC);
+
+  if (info->funname != NULL)
+    {
+      fprintf (stderr,
+	       _("coff_start_function() called twice, pending %s, new %s\n"),
+	       info->funname, name);
+      return FALSE;
+    }
+  info->funname = name;
+  info->funglobal = globalp;
+  info->flags |= COFF_FL_START_FCN;
+  tst->u.ts_func.savedts = savedts;
+
+  return TRUE;
+}
+
+/* Output a function parameter.  */
+
+static bfd_boolean
+coff_function_parameter (p, name, kind, val)
+     PTR p;
+     const char *name;
+     enum debug_parm_kind kind;
+     bfd_vma val;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  coff_symbol_type *csymp;
+  unsigned char class;
+
+#if COFF_DEBUG
+  printf ("coff_function_parameter(%s, %d, %d)\n",
+	  name, (int)kind, (int)val);
+#endif
+
+  switch (kind)
+    {
+    default:
+      abort ();
+
+    case DEBUG_PARM_STACK:
+      class = C_ARG;
+      break;
+
+    case DEBUG_PARM_REG:
+      class = C_REGPARM;
+      break;
+
+    case DEBUG_PARM_REFERENCE:
+    case DEBUG_PARM_REF_REG:
+      fprintf (stderr, _("Reference parameters not available in COFF\n"));
+      return TRUE;
+    }
+
+  if (!coff_make_typed_symbol (info, &csymp, TS_FUNC))
+    return FALSE;
+
+  if (class == C_REGPARM && (info->flags & COFF_FL_AVR) != 0)
+    {
+      struct coff_private_symdata *priv = (struct coff_private_symdata *)
+	csymp->symbol.udata.p;
+      val = coff_fixup_avr_register (val, priv->size * 8);
+    }
+
+  csymp->symbol.name = name;
+  csymp->symbol.value = val;
+  csymp->symbol.flags |= BSF_LOCAL;
+  csymp->native->u.syment.n_sclass = class;
+
+  /* Since function parameters precede the actual function definition,
+     defer their output until the function has been created. */
+  info->fargs = (coff_symbol_type **)
+    xrealloc (info->fargs, ++info->nfargs * sizeof (coff_symbol_type *));
+  info->fargs[info->nfargs - 1] = csymp;
+
+  return TRUE;
+}
+
+/* Start a block.  */
+
+static bfd_boolean
+coff_start_block (p, addr)
+     PTR p;
+     bfd_vma addr;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  struct coff_type_stack *tst, *otst;
+  struct coff_fix_stack *fixp, *ofp;
+  asymbol *symp;
+  coff_symbol_type *csymp;
+  unsigned int i;
+  bfd_boolean is_start_fcn;
+
+#if COFF_DEBUG
+  printf ("coff_start_block(%#x)\n", (int)addr);
+#endif
+
+  is_start_fcn = info->flags & COFF_FL_START_FCN;
+
+  if (is_start_fcn)
+    {
+      /* This is the starting block of a function.  We are going to
+         write three symbols here, one for the function itself, one
+         ".bf" symbol to indicate the begin of the function, and
+         finally one ".bb" for the first block inside the function. */
+      info->flags &= ~COFF_FL_START_FCN;
+
+      /* Our function definition should be the only type stack element
+	 by now. */
+      assert (info->tstack != NULL);
+      tst = info->tstack;
+      if (tst->tsk != TS_FUNC || tst->next != NULL)
+	{
+	  fprintf (stderr,
+		   _("coff_start_block() not within function definition\n"));
+	  return FALSE;
+	}
+
+      /* Restore saved type stack, and push our now complete function
+	 definition on top. */
+      info->tstack = tst->u.ts_func.savedts;
+      tst->next = info->tstack;
+      info->tstack = tst;
+
+      if (info->currentfile == NULL)
+	{
+	  fprintf (stderr,
+		   _("Warning: ignoring function %s() outside any compilation unit\n"),
+		   info->funname);
+	  for (tst = info->tstack, otst = NULL; tst != NULL;)
+	    {
+	      otst = tst;
+	      tst = otst->next;
+	      if (otst->tsk == TS_ENUM &&
+		  otst->u.ts_enum.tagismalloced)
+		free (otst->u.ts_enum.tag.malloctag);
+	      else if (otst->tsk == TS_STRUCT &&
+		       otst->u.ts_struct.tagismalloced)
+		free (otst->u.ts_struct.tag.malloctag);
+	      free (otst);
+	    }
+	  info->tstack = NULL;
+	  info->funname = NULL;
+
+	  return TRUE;
+	}
+
+      if (!coff_make_typed_symbol (info, &csymp, TS_NONE))
+	return FALSE;
+
+      csymp->symbol.name = info->funname;
+      csymp->symbol.flags = BSF_FUNCTION |
+	(info->funglobal? BSF_GLOBAL: BSF_LOCAL);
+      symp = coff_find_symbol (info, info->funname, TRUE, info->funglobal);
+      if (symp == NULL)
+	{
+	  fprintf (stderr,
+		   _("function %s not found in symbol table, defaulting to \"text\" section\n"),
+		   info->funname);
+	  csymp->symbol.section = info->funcsection = info->textsect;
+	}
+      else
+	csymp->symbol.section = info->funcsection = symp->section;
+
+      /* Symbol addresses are relative to section vma. */
+      csymp->symbol.value = addr - info->funcsection->vma;
+      csymp->native->u.syment.n_sclass = info->funglobal? C_EXT: C_STAT;
+      /* Create two initial line number entries.  The first one holds
+	 the function symbol, the second one is the trailing record
+	 that is required by coffgen.c::coff_write_native_symbol() to
+	 have a line number of zero. */
+      csymp->lineno = (alent *) xmalloc (2 * sizeof (alent));
+      memset (csymp->lineno, 0, 2 * sizeof (alent));
+      info->nlnos = 2;
+      info->totlnos++;
+      csymp->lineno[0].u.sym = (asymbol *)csymp;
+      coff_record_symbol (info, csymp);
+      info->funcindex = info->nsyms - 1; /* remember for later */
+      /* Record our endndx field for later fixing. */
+      fixp = (struct coff_fix_stack *) xmalloc (sizeof (struct coff_fix_stack));
+      fixp->native = csymp->native + 1;	/* points to first AUX */
+      fixp->next = NULL;
+      if (info->fixes == NULL)
+	info->fixes = fixp;
+      else
+	{
+	  for (ofp = info->fixes; ofp->next != NULL;)
+	    ofp = ofp->next;
+	  ofp->next = fixp;
+	}
+
+      csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+      if (csymp == NULL)
+	return FALSE;
+
+      csymp->symbol.name = ".bf";
+      csymp->native->u.syment.n_sclass = C_FCN;
+      csymp->native->u.syment.n_numaux = 1;
+      csymp->symbol.value = addr - info->funcsection->vma;
+      csymp->symbol.section = info->funcsection;
+      csymp->symbol.udata.p = NULL;
+      coff_record_symbol (info, csymp);
+    }
+
+  if (info->funname == NULL)
+    return TRUE;
+
+  csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (csymp == NULL)
+    return FALSE;
+
+  csymp->symbol.name = ".bb";
+  csymp->native->u.syment.n_sclass = C_BLOCK;
+  csymp->native->u.syment.n_numaux = 1;
+  csymp->symbol.value = addr - info->funcsection->vma;
+  csymp->symbol.section = info->funcsection;
+  csymp->symbol.udata.p = NULL;
+  coff_record_symbol (info, csymp);
+
+  info->flags |= COFF_FL_FIX_BB;
+
+  /* Output any pending function parameters, if any. */
+  if (is_start_fcn && info->nfargs)
+    {
+      for (i = 0; i < info->nfargs; i++)
+	coff_record_symbol (info, info->fargs[i]);
+
+      free (info->fargs);
+      info->fargs = NULL;
+      info->nfargs = 0;
+    }
+
+  return TRUE;
+}
+
+/* End a block.  */
+
+static bfd_boolean
+coff_end_block (p, addr)
+     PTR p;
+     bfd_vma addr;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  coff_symbol_type *csymp;
+  union internal_auxent *aux;
+
+#if COFF_DEBUG
+  printf ("coff_end_block(%#x)\n", (int)addr);
+#endif
+
+  if (info->funname == NULL)
+    return TRUE;
+
+  csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (csymp == NULL)
+    return FALSE;
+
+  csymp->symbol.name = ".eb";
+  csymp->symbol.value = addr - info->funcsection->vma;
+  csymp->native->u.syment.n_sclass = C_BLOCK;
+  csymp->native->u.syment.n_numaux = 1;
+  csymp->symbol.udata.p = NULL;
+  csymp->symbol.section = info->funcsection;
+  aux = &((csymp->native + 1)->u.auxent);
+  aux->x_sym.x_misc.x_lnsz.x_lnno = info->lastlno;
+  coff_record_symbol (info, csymp);
+
+  info->endaddr = addr;
+
+  return TRUE;
+}
+
+/* End a function.  */
+
+static bfd_boolean
+coff_end_function (p)
+     PTR p;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  coff_symbol_type *csymp;
+  union internal_auxent *aux;
+
+#if COFF_DEBUG
+  printf ("coff_end_function()\n");
+#endif
+
+  if (info->funname == NULL)
+    return TRUE;
+
+  csymp = (coff_symbol_type *) coff_bfd_make_debug_symbol (info->abfd, 0, 0);
+  if (csymp == NULL)
+    return FALSE;
+
+  csymp->symbol.name = ".ef";
+  csymp->symbol.value = info->endaddr - info->funcsection->vma;
+  csymp->native->u.syment.n_sclass = C_FCN;
+  csymp->native->u.syment.n_numaux = 1;
+  csymp->symbol.udata.p = NULL;
+  csymp->symbol.section = info->funcsection;
+  aux = &((csymp->native + 1)->u.auxent);
+  aux->x_sym.x_misc.x_lnsz.x_lnno = info->lastlno;
+
+  coff_record_symbol (info, csymp);
+
+  csymp = (coff_symbol_type *) info->syms[info->funcindex];
+  aux = &((csymp->native + 1)->u.auxent);
+  aux->x_sym.x_misc.x_fsize = info->endaddr - csymp->symbol.value;
+
+  info->flags |= COFF_FL_FIX_ENDNDX;
+  info->funname = NULL;
+
+  return TRUE;
+}
+
+/* Output a line number.  */
+
+static bfd_boolean
+coff_lineno (p, file, lineno, addr)
+     PTR p;
+     const char *file ATTRIBUTE_UNUSED;
+     unsigned long lineno;
+     bfd_vma addr;
+{
+  struct coff_write_handle *info = (struct coff_write_handle *) p;
+  coff_symbol_type *csymp;
+  union internal_auxent *aux;
+  long i;
+
+#if COFF_DEBUG
+  printf ("coff_lineno(%s, %ld, %d)\n",
+	  file, lineno, (int)addr);
+#endif
+
+  /* COFF can inherently only handle line numbers inside of functions.
+     If we are not inside a function, punt. */
+  if (info->funname == NULL)
+    return TRUE;
+
+  if (info->nlnos == 2)
+    {
+      /* This is the first line number of this function.  Fix the line
+	 number for the .bf symbol immediately following the start of
+	 function.  We also have to remember the starting line number
+	 of our function since all line number entries are relative to
+	 it in COFF.  Since regular line numbers must always be
+	 non-zero, we artificially force the function to start one
+	 line earlier. */
+      csymp = (coff_symbol_type *) info->syms[info->funcindex + 1];
+      aux = &((csymp->native + 1)->u.auxent);
+      aux->x_sym.x_misc.x_lnsz.x_lnno = lineno;
+      info->funlno = lineno - 1;
+    }
+
+  if (info->flags & COFF_FL_FIX_BB)
+    {
+      /* This is the first line number after one (or more) .bb
+	 symbols.  Fix them.  In order to cope with multiple blocks
+	 starting at the same line number, we walk back the list of
+	 symbols until we find a C_BLOCK one that had already been
+	 fixed, or until we find a C_FCN symbol (presumably, the start
+	 of our current function). */
+      info->flags &= ~COFF_FL_FIX_BB;
+
+      for (i = info->nsyms - 1; i >= 0; i--)
+	{
+	  csymp = (coff_symbol_type *) info->syms[i];
+	  if (csymp->native->u.syment.n_sclass == C_FCN)
+	    break;
+	  if (csymp->native->u.syment.n_sclass == C_BLOCK)
+	    {
+	      aux = &((csymp->native + 1)->u.auxent);
+	      if (aux->x_sym.x_misc.x_lnsz.x_lnno != 0)
+		/* already set up properly */
+		break;
+	      aux->x_sym.x_misc.x_lnsz.x_lnno = lineno;
+	    }
+	}
+    }
+
+  csymp = (coff_symbol_type *) info->syms[info->funcindex];
+  csymp->lineno = (alent *) xrealloc (csymp->lineno,
+				      ++info->nlnos * sizeof (alent));
+  memset (csymp->lineno + info->nlnos - 1, 0, sizeof (alent));
+  if (lineno > info->funlno)
+    csymp->lineno[info->nlnos - 2].line_number = lineno - info->funlno;
+  else
+    /* Line number unreasonable.  Can e. g. happen for a line number
+       from an include file, which we cannot process in COFF.  Just
+       set it to the first line, to avoid generating a large unsigned
+       short (~ 65000) line number. */
+    csymp->lineno[info->nlnos - 2].line_number = 1;
+  csymp->lineno[info->nlnos - 2].u.offset = addr;
+
+  info->lastlno = lineno;
+  info->totlnos++;
+
+  return TRUE;
+}
diff --git a/include/coff/avr.h b/include/coff/avr.h
new file mode 100644
index 0000000..1895bdf
--- /dev/null
+++ b/include/coff/avr.h
@@ -0,0 +1,110 @@
+/* coff information for Atmel AVR.
+
+   Copyright 2001 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* This file was hacked from i860.h */
+
+#define L_LNNO_SIZE 2
+#include "coff/external.h"
+
+/* Bits for f_flags:
+	F_RELFLG	relocation info stripped from file
+	F_EXEC		file is executable (no unresolved external references)
+	F_LNNO		line numbers stripped from file
+	F_LSYMS		local symbols stripped from file  */
+
+#define F_RELFLG	(0x0001)
+#define F_EXEC		(0x0002)
+#define F_LNNO		(0x0004)
+#define F_LSYMS		(0x0008)
+/* Upper nibble of flags always needs to be set.  This used to be
+ * undocumented, recent information from Atmel says that bit 7 used to
+ * differentiate between an old vendor-specific deviation of the
+ * format and the current format. */
+#define F_JUNK		(0x00f0)
+#define F_UNUSED	(0xff00)
+
+#define	AVRMAGIC	0xa12
+
+#undef AOUTSZ
+#ifdef AVR_EXT_COFF
+
+/* AVR "extended" COFF format.  This uses the optional header ("a.out"
+   header) to inform the consumer about some additional features that
+   are supported. */
+#define COFF_LONG_FILENAMES yes	/* long filenames supported in consecutive aux entries */
+#define AOUTSZ		28	/* size of optional header in "extended" COFF */
+
+/* Flags in the optional header; they are stored in the vstamp field. */
+#define F_FULLPATHS	0x0001	/* long filenames supported */
+#define F_STRUCTINFO	0x0002	/* structure information contained */
+#define F_PTRINFO	0x0004	/* inter-segment pointers supported */
+
+#else /* old AVR COFF */
+
+#define AOUTSZ		0	/* no a.out for AVR */
+#endif
+
+/* #define AVRAOUTMAGIC	0x406 */ /* "general" magic number of optional header */
+/*
+ * The following magic number causes AVR Studio 4.x to recognize
+ * avr-gcc/GNU binutils produced AVR extended COFF files.  By now,
+ * the only special treatment for them is that the contents of .data
+ * will be appended after .text in the simulator flash.
+ *
+ * 0x9cc has been chosen since it resembles "gcc". ;-)
+ */
+#define AVRAOUTMAGIC	0x9cc	/* "gcc" magic number */
+
+/* By matching not only the magic number, but also the size of the
+   optional a.out header, we can differentiate between both
+   formats. */
+#define AVRBADMAG(x)   ((x).f_magic != AVRMAGIC || (x).f_opthdr != AOUTSZ)
+
+/* AVR COFF has several anomalities in the way the handle the derived
+   type information, and AUX entries, mainly because they apparently
+   didn't bother to learn how COFF is supposed to work before they
+   started.  We fix many of them at the export/import boundary, so all
+   the internal generic COFF handling will work mostly as designed. */
+
+/* NB: these functions are only defined in bfd/coff-avr.c, but also
+   used in coff-ext-avr.c, so the latter can only be configured if the
+   former is also present.  This is certainly always the case
+   anyway. */
+extern void avr_coff_adjust_sym_in_post
+  PARAMS((bfd *, PTR, PTR));
+
+extern void avr_coff_adjust_sym_out_post
+  PARAMS((bfd *, PTR, PTR));
+
+#define COFF_ADJUST_SYM_IN_POST(ABFD, EXT, INT) \
+	avr_coff_adjust_sym_in_post (ABFD, EXT, INT)
+
+#define COFF_ADJUST_SYM_OUT_POST(ABFD, INT, EXT) \
+	avr_coff_adjust_sym_out_post (ABFD, INT, EXT)
+
+/********************** RELOCATION DIRECTIVES **********************/
+
+struct external_reloc
+{
+  char r_vaddr[4];
+  char r_symndx[4];
+  char r_type[2];
+};
+
+#define RELOC struct external_reloc
+#define RELSZ 10
diff --git a/include/coff/internal.h b/include/coff/internal.h
index 4ac96c3..150b603 100644
--- a/include/coff/internal.h
+++ b/include/coff/internal.h
@@ -646,6 +646,8 @@ union internal_auxent
 
 };
 
+#define NAUXENTS 10		/* number of pre-allocated aux entries */
+
 /********************** RELOCATION DIRECTIVES **********************/
 
 struct internal_reloc
-- 
1.6.0.4