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
|
diff -urN linux-source-2.6.16.orig/arch/i386/boot/compressed/Makefile linux-source-2.6.16/arch/i386/boot/compressed/Makefile
--- linux-source-2.6.16.orig/arch/i386/boot/compressed/Makefile 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/i386/boot/compressed/Makefile 2006-04-24 10:57:30.000000000 +0100
@@ -7,6 +7,7 @@
targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
EXTRA_AFLAGS := -traditional
+CFLAGS := $(CFLAGS_NOGCOV)
LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32
$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
diff -urN linux-source-2.6.16.orig/arch/i386/Kconfig linux-source-2.6.16/arch/i386/Kconfig
--- linux-source-2.6.16.orig/arch/i386/Kconfig 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/i386/Kconfig 2006-04-24 10:57:30.000000000 +0100
@@ -751,6 +751,7 @@
endmenu
+source "drivers/gcov/Kconfig"
menu "Power management options (ACPI, APM)"
depends on !X86_VOYAGER
diff -urN linux-source-2.6.16.orig/arch/i386/kernel/head.S linux-source-2.6.16/arch/i386/kernel/head.S
--- linux-source-2.6.16.orig/arch/i386/kernel/head.S 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/i386/kernel/head.S 2006-04-24 10:57:30.000000000 +0100
@@ -534,3 +534,24 @@
.quad 0x0000000000000000 /* 0xf0 - unused */
.quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
+
+#ifdef CONFIG_GCOV_PROFILE
+/*
+ * The .ctors-section contains a list of pointers to constructor
+ * functions which are used to initialize gcov structures.
+ *
+ * Because there is no NULL at the end of the constructor list
+ * in the kernel we need the addresses of both the constructor
+ * as well as the destructor list which are supposed to be
+ * adjacent.
+ */
+
+.section ".ctors","aw"
+.globl __CTOR_LIST__
+.type __CTOR_LIST__,@object
+__CTOR_LIST__:
+.section ".dtors","aw"
+.globl __DTOR_LIST__
+.type __DTOR_LIST__,@object
+__DTOR_LIST__:
+#endif
diff -urN linux-source-2.6.16.orig/arch/ia64/Kconfig linux-source-2.6.16/arch/ia64/Kconfig
--- linux-source-2.6.16.orig/arch/ia64/Kconfig 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ia64/Kconfig 2006-04-24 10:57:30.000000000 +0100
@@ -462,6 +462,8 @@
If in doubt, say "N".
endmenu
+source "drivers/gcov/Kconfig"
+
source "arch/ia64/Kconfig.debug"
source "security/Kconfig"
diff -urN linux-source-2.6.16.orig/arch/ia64/kernel/head.S linux-source-2.6.16/arch/ia64/kernel/head.S
--- linux-source-2.6.16.orig/arch/ia64/kernel/head.S 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ia64/kernel/head.S 2006-04-24 10:57:30.000000000 +0100
@@ -1219,3 +1219,24 @@
#endif /* CONFIG_HOTPLUG_CPU */
#endif /* CONFIG_SMP */
+
+#ifdef CONFIG_GCOV_PROFILE
+/*
+ * The .ctors-section contains a list of pointers to constructor
+ * functions which are used to initialize gcov structures.
+ *
+ * Because there is no NULL at the end of the constructor list
+ * in the kernel we need the addresses of both the constructor
+ * as well as the destructor list which are supposed to be
+ * adjacent.
+ */
+
+.section ".ctors","aw"
+.globl __CTOR_LIST__
+.type __CTOR_LIST__,@object
+__CTOR_LIST__:
+.section ".dtors","aw"
+.globl __DTOR_LIST__
+.type __DTOR_LIST__,@object
+__DTOR_LIST__:
+#endif
diff -urN linux-source-2.6.16.orig/arch/powerpc/Kconfig linux-source-2.6.16/arch/powerpc/Kconfig
--- linux-source-2.6.16.orig/arch/powerpc/Kconfig 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/powerpc/Kconfig 2006-04-24 10:59:59.000000000 +0100
@@ -961,6 +961,8 @@
source "arch/powerpc/oprofile/Kconfig"
+source "drivers/gcov/Kconfig"
+
config KPROBES
bool "Kprobes (EXPERIMENTAL)"
depends on PPC64 && EXPERIMENTAL && MODULES
diff -urN linux-source-2.6.16.orig/arch/ppc/boot/openfirmware/common.c linux-source-2.6.16/arch/ppc/boot/openfirmware/common.c
--- linux-source-2.6.16.orig/arch/ppc/boot/openfirmware/common.c 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ppc/boot/openfirmware/common.c 2006-04-24 10:57:30.000000000 +0100
@@ -29,6 +29,10 @@
static struct memchunk *freechunks;
+#ifdef CONFIG_GCOV_PROFILE
+void __bb_init_func (void *ptr /* struct bb *blocks */) { }
+#endif
+
static void *zalloc(unsigned size)
{
void *p;
diff -urN linux-source-2.6.16.orig/arch/ppc/boot/simple/misc-prep.c linux-source-2.6.16/arch/ppc/boot/simple/misc-prep.c
--- linux-source-2.6.16.orig/arch/ppc/boot/simple/misc-prep.c 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ppc/boot/simple/misc-prep.c 2006-04-24 10:57:30.000000000 +0100
@@ -37,6 +37,10 @@
extern void disable_6xx_mmu(void);
extern unsigned long mpc10x_get_mem_size(void);
+#ifdef CONFIG_GCOV_PROFILE
+void __bb_init_func (void *ptr /* struct bb *blocks */) { }
+#endif
+
static void
writel(unsigned int val, unsigned int address)
{
diff -urN linux-source-2.6.16.orig/arch/ppc/Kconfig linux-source-2.6.16/arch/ppc/Kconfig
--- linux-source-2.6.16.orig/arch/ppc/Kconfig 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ppc/Kconfig 2006-04-24 10:57:30.000000000 +0100
@@ -1368,6 +1368,7 @@
source "arch/ppc/8260_io/Kconfig"
+source "drivers/gcov/Kconfig"
menu "IBM 40x options"
depends on 40x
diff -urN linux-source-2.6.16.orig/arch/ppc/kernel/head.S linux-source-2.6.16/arch/ppc/kernel/head.S
--- linux-source-2.6.16.orig/arch/ppc/kernel/head.S 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ppc/kernel/head.S 2006-04-24 10:57:30.000000000 +0100
@@ -1538,3 +1538,25 @@
*/
abatron_pteptrs:
.space 8
+
+#ifdef CONFIG_GCOV_PROFILE
+/*
+ * The .ctors-section contains a list of pointers to constructor
+ * functions which are used to initialize gcov structures.
+ *
+ * Because there is no NULL at the end of the constructor list
+ * in the kernel we need the addresses of both the constructor
+ * as well as the destructor list which are supposed to be
+ * adjacent.
+ */
+
+.section ".ctors","aw"
+.globl __CTOR_LIST__
+.type __CTOR_LIST__,@object
+__CTOR_LIST__:
+.section ".dtors","aw"
+.globl __DTOR_LIST__
+.type __DTOR_LIST__,@object
+__DTOR_LIST__:
+#endif
+
diff -urN linux-source-2.6.16.orig/arch/ppc/syslib/prom_init.c linux-source-2.6.16/arch/ppc/syslib/prom_init.c
--- linux-source-2.6.16.orig/arch/ppc/syslib/prom_init.c 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/ppc/syslib/prom_init.c 2006-04-24 10:57:30.000000000 +0100
@@ -765,7 +765,11 @@
* Actually OF has bugs so we just arbitrarily
* use memory at the 6MB point.
*/
+#ifdef CONFIG_GCOV_PROFILE
+ rtas_data = 0x990000;
+#else
rtas_data = 6 << 20;
+#endif
prom_print(" at ");
prom_print_hex(rtas_data);
}
diff -urN linux-source-2.6.16.orig/arch/s390/Kconfig linux-source-2.6.16/arch/s390/Kconfig
--- linux-source-2.6.16.orig/arch/s390/Kconfig 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/s390/Kconfig 2006-04-24 10:58:00.000000000 +0100
@@ -476,4 +476,6 @@
source "crypto/Kconfig"
+source "drivers/gcov/Kconfig"
+
source "lib/Kconfig"
diff -urN linux-source-2.6.16.orig/arch/s390/kernel/head31.S linux-source-2.6.16/arch/s390/kernel/head31.S
--- linux-source-2.6.16.orig/arch/s390/kernel/head31.S 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/s390/kernel/head31.S 2006-04-24 11:05:12.000000000 +0100
@@ -334,3 +334,25 @@
.Linittu:.long init_thread_union
.Lstart:.long start_kernel
.Laregs:.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+
+#ifdef CONFIG_GCOV_PROFILE
+ /*
+ * The .ctors-section contains a list of pointers to constructor
+ * functions which are used to initialize gcov structures.
+ *
+ * Because there is no NULL at the end of the constructor list
+ * in the kernel we need the addresses of both the constructor
+ * as well as the destructor list which are supposed to be
+ * adjacent.
+ */
+
+.section ".ctors","aw"
+.globl __CTOR_LIST__
+.type __CTOR_LIST__,@object
+__CTOR_LIST__:
+.section ".dtors","aw"
+.globl __DTOR_LIST__
+.type __DTOR_LIST__,@object
+__DTOR_LIST__:
+#endif
+
diff -urN linux-source-2.6.16.orig/arch/s390/kernel/head64.S linux-source-2.6.16/arch/s390/kernel/head64.S
--- linux-source-2.6.16.orig/arch/s390/kernel/head64.S 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/s390/kernel/head64.S 2006-04-24 10:58:01.000000000 +0100
@@ -327,3 +327,23 @@
.Ldw: .quad 0x0002000180000000,0x0000000000000000
.Laregs: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+#ifdef CONFIG_GCOV_PROFILE
+/*
+ * The .ctors-section contains a list of pointers to constructor
+ * functions which are used to initialize gcov structures.
+ *
+ * Because there is no NULL at the end of the constructor list
+ * in the kernel we need the addresses of both the constructor
+ * as well as the destructor list which are supposed to be
+ * adjacent.
+ */
+
+.section ".ctors","aw"
+.globl __CTOR_LIST__
+.type __CTOR_LIST__,@object
+__CTOR_LIST__:
+.section ".dtors","aw"
+.globl __DTOR_LIST__
+.type __DTOR_LIST__,@object
+__DTOR_LIST__:
+#endif
diff -urN linux-source-2.6.16.orig/arch/x86_64/Kconfig linux-source-2.6.16/arch/x86_64/Kconfig
--- linux-source-2.6.16.orig/arch/x86_64/Kconfig 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/x86_64/Kconfig 2006-04-24 10:58:01.000000000 +0100
@@ -586,6 +586,8 @@
If in doubt, say "N".
endmenu
+source "drivers/gcov/Kconfig"
+
source "arch/x86_64/Kconfig.debug"
source "security/Kconfig"
diff -urN linux-source-2.6.16.orig/arch/x86_64/kernel/head.S linux-source-2.6.16/arch/x86_64/kernel/head.S
--- linux-source-2.6.16.orig/arch/x86_64/kernel/head.S 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/arch/x86_64/kernel/head.S 2006-04-24 10:58:01.000000000 +0100
@@ -384,3 +384,23 @@
.quad 0
.endr
+#ifdef CONFIG_GCOV_PROFILE
+/*
+ * The .ctors-section contains a list of pointers to constructor
+ * functions which are used to initialize gcov structures.
+ *
+ * Because there is no NULL at the end of the constructor list
+ * in the kernel we need the addresses of both the constructor
+ * as well as the destructor list which are supposed to be
+ * adjacent.
+ */
+
+.section ".ctors","aw"
+.globl __CTOR_LIST__
+.type __CTOR_LIST__,@object
+__CTOR_LIST__:
+.section ".dtors","aw"
+.globl __DTOR_LIST__
+.type __DTOR_LIST__,@object
+__DTOR_LIST__:
+#endif
diff -urN linux-source-2.6.16.orig/drivers/gcov/gcov-core.c linux-source-2.6.16/drivers/gcov/gcov-core.c
--- linux-source-2.6.16.orig/drivers/gcov/gcov-core.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-source-2.6.16/drivers/gcov/gcov-core.c 2006-04-24 10:58:01.000000000 +0100
@@ -0,0 +1,246 @@
+/*
+ * drivers/gcov/gcov-core.c
+ *
+ * Core functionality for GCOV kernel profiling.
+ *
+ * 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.
+ *
+ * Copyright (c) International Business Machines Corp., 2002-2003
+ *
+ * Author: Hubertus Franke <frankeh@us.ibm.com>
+ * Rajan Ravindran <rajancr@us.ibm.com>
+ * Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/gcov.h>
+
+
+#define GCOV_CORE_HEADER "gcov-core: "
+
+/* This structure is used to keep track of all struct bbs associated with a
+ * module. */
+struct gcov_context
+{
+ struct list_head list;
+ struct module *module;
+ unsigned long count;
+ struct bb **bb;
+};
+
+/* Start of global constructor list. Has to be declared in arch/kernel/head.S */
+extern char __CTOR_LIST__;
+
+/* End of global constructor list. Has to be declared in arch/kernel/head.S */
+extern char __DTOR_LIST__;
+
+/* Linked list for registered struct bbs. */
+struct bb *bb_head;
+
+/* Callback informed of struct bb addition and removal. */
+void (*gcov_callback)(enum gcov_cmd, struct bb *bbptr) = NULL;
+
+/* Path to kernel files. */
+const char *gcov_sourcepath = GCOV_SRC_PATH;
+const char *gcov_objectpath = GCOV_OBJ_PATH;
+
+/* List of contexts for registered bb entries. */
+static LIST_HEAD(context_list);
+
+/* Context into which blocks are inserted during initialization. */
+static struct gcov_context *current_context;
+
+/* Protect global variables from concurrent access. */
+spinlock_t gcov_core_lock = SPIN_LOCK_UNLOCKED;
+
+#if GCC_VERSION_LOWER(3, 4)
+/* Register supplied struct BB. Called by each object code constructor. */
+void
+__bb_init_func(struct bb *bb)
+{
+ if (bb->zero_word)
+ return;
+ /* Set up linked list */
+ bb->zero_word = 1;
+ bb->next = bb_head;
+ bb_head = bb;
+ /* Associate with module context */
+ if (current_context)
+ current_context->bb[current_context->count++] = bb;
+ /* Notify callback */
+ if (gcov_callback != NULL)
+ (*gcov_callback)(gcov_add, bb);
+}
+
+
+/* Unused functions needed to prevent linker errors. */
+void __bb_fork_func(void) {}
+
+EXPORT_SYMBOL_NOVERS(__bb_init_func);
+EXPORT_SYMBOL_NOVERS(__bb_fork_func);
+#else
+gcov_unsigned_t gcov_version = 0;
+
+/* Register supplied struct BB. Called by each object code constructor. */
+void
+__gcov_init(struct bb *bb)
+{
+ if (!bb->version)
+ return;
+ /* Check for compatible gcc version */
+ if (gcov_version == 0)
+ gcov_version = bb->version;
+ else if (bb->version != gcov_version) {
+ printk(KERN_WARNING GCOV_CORE_HEADER "gcc version mismatch in "
+ " file '%s'!\n", bb->filename);
+ return;
+ }
+ /* Set up linked list */
+ bb->version = 0;
+ bb->next = bb_head;
+ bb_head = bb;
+ /* Associate with module context */
+ if (current_context)
+ current_context->bb[current_context->count++] = bb;
+ /* Notify callback */
+ if (gcov_callback != NULL)
+ (*gcov_callback)(gcov_add, bb);
+}
+
+
+/* Unused functions needed to prevent linker errors. */
+void __gcov_flush(void) {}
+void __gcov_merge_add(gcov_type *counters, unsigned int n_counters) {}
+void __gcov_merge_single(gcov_type *counters, unsigned int n_counters) {}
+void __gcov_merge_delta(gcov_type *counters, unsigned int n_counters) {}
+
+EXPORT_SYMBOL_NOVERS(gcov_version);
+EXPORT_SYMBOL_NOVERS(__gcov_init);
+EXPORT_SYMBOL_NOVERS(__gcov_flush);
+EXPORT_SYMBOL_NOVERS(__gcov_merge_add);
+EXPORT_SYMBOL_NOVERS(__gcov_merge_single);
+EXPORT_SYMBOL_NOVERS(__gcov_merge_delta);
+#endif /* GCC_VERSION_LOWER */
+
+
+/* Call all constructor function pointers stored between CTORS_START and
+ * CTORS_END. If specified, associate resulting bb data with MODULE. */
+void
+do_global_ctors(const char *ctors_start, const char *ctors_end,
+ struct module *module)
+{
+ typedef void (*func_ptr)(void);
+ func_ptr *func;
+ unsigned long count;
+
+ spin_lock(&gcov_core_lock);
+ if (module) {
+ /* Create a context to associate struct bbs with this MODULE */
+ count = ((unsigned long) (ctors_end - ctors_start)) /
+ sizeof(func_ptr);
+ current_context = (struct gcov_context*) kmalloc(
+ sizeof(struct gcov_context) +
+ count * sizeof(struct bb *),
+ GFP_KERNEL);
+ if (!current_context) {
+ printk(KERN_WARNING GCOV_CORE_HEADER "not enough memory"
+ " for coverage data!\n");
+ spin_unlock(&gcov_core_lock);
+ return;
+ }
+ current_context->module = module;
+ current_context->count = 0;
+ current_context->bb = (struct bb **) (current_context + 1);
+ list_add(¤t_context->list, &context_list);
+ }
+ /* Call constructors */
+ for (func = (func_ptr *) ctors_start;
+ *func && (func != (func_ptr *) ctors_end); func++)
+ (*func)();
+ current_context = NULL;
+ spin_unlock(&gcov_core_lock);
+}
+
+
+/* Remove data associated with MODULE. */
+void
+remove_bb_link(struct module *module)
+{
+ struct gcov_context* context;
+ struct gcov_context* tmp;
+ struct bb *bb;
+ struct bb *prev;
+ unsigned long i;
+
+ spin_lock(&gcov_core_lock);
+ /* Get associated context */
+ context = NULL;
+ list_for_each_entry(tmp, &context_list, list) {
+ if (tmp->module == module) {
+ context = tmp;
+ break;
+ }
+ }
+ if (!context) {
+ spin_unlock(&gcov_core_lock);
+ return;
+ }
+ /* Remove all bb entries belonging to this module */
+ prev = NULL;
+ for (bb = bb_head; bb ; bb = bb->next) {
+ for (i = 0; i < context->count; i++) {
+ if (context->bb[i] == bb) {
+ /* Detach bb from list. */
+ if (prev)
+ prev->next = bb->next;
+ else
+ bb_head = bb->next;
+ /* Notify callback */
+ if (gcov_callback)
+ (*gcov_callback)(gcov_remove, bb);
+ break;
+ }
+ }
+ if (i == context->count)
+ prev = bb;
+ }
+ list_del(&context->list);
+ kfree(context);
+ spin_unlock(&gcov_core_lock);
+}
+
+
+static int __init
+gcov_core_init(void)
+{
+ printk(KERN_INFO GCOV_CORE_HEADER "core init\n");
+ do_global_ctors(&__CTOR_LIST__, &__DTOR_LIST__, NULL);
+ return 0;
+}
+
+module_init(gcov_core_init);
+
+
+EXPORT_SYMBOL_NOVERS(bb_head);
+EXPORT_SYMBOL_NOVERS(gcov_sourcepath);
+EXPORT_SYMBOL_NOVERS(gcov_objectpath);
+EXPORT_SYMBOL_NOVERS(gcov_callback);
+EXPORT_SYMBOL_NOVERS(gcov_core_lock);
+EXPORT_SYMBOL_NOVERS(do_global_ctors);
diff -urN linux-source-2.6.16.orig/drivers/gcov/gcov-proc.c linux-source-2.6.16/drivers/gcov/gcov-proc.c
--- linux-source-2.6.16.orig/drivers/gcov/gcov-proc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-source-2.6.16/drivers/gcov/gcov-proc.c 2006-04-24 10:58:01.000000000 +0100
@@ -0,0 +1,1592 @@
+/*
+ * drivers/gcov/gcov-proc.c
+ *
+ * Provides proc filesystem entry for GCOV kernel profiling.
+ *
+ * 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.
+ *
+ * Copyright (c) International Business Machines Corp., 2002-2003
+ *
+ * Author: Hubertus Franke <frankeh@us.ibm.com>
+ * Rajan Ravindran <rajancr@us.ibm.com>
+ * Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
+ * Paul Larson
+ */
+
+#include <linux/config.h>
+#if CONFIG_MODVERSIONS==1
+#define MODVERSIONS
+#include <linux/modversions.h>
+#endif
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/version.h>
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/proc_fs.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <asm/uaccess.h>
+#include <linux/gcov.h>
+
+
+MODULE_LICENSE("GPL");
+
+#define GCOV_PROC_HEADER "gcov-proc: "
+#define GCOV_PROC_ROOT "gcov"
+#define GCOV_PROC_MODULE "module"
+#define GCOV_PROC_VMLINUX "vmlinux"
+#define PAD8(x) (((x) + 7) & ~7)
+#define PAD4(x) (((x) + 3) & ~3)
+
+typedef enum {
+ status_normal, /* Normal status */
+ status_ghost /* Module associated with this node has been unloaded
+ * but data was saved. */
+} node_status;
+
+/* Data structure used to manage proc filesystem entries. */
+struct gcov_ftree_node
+{
+ char *fname; /* Hierarchy-relative name */
+ struct gcov_ftree_node *sibling; /* First sibling of this node */
+ struct gcov_ftree_node *files; /* First child of this node */
+ struct gcov_ftree_node *parent; /* Parent of this node */
+ struct proc_dir_entry *proc[4]; /* Entries for .da, .bb, .bbg, .c */
+ struct bb *bb; /* Associated struct bb */
+ loff_t offset; /* Offset in vmlinux file */
+ size_t da_size; /* Size of associated .da file */
+ size_t header_size; /* Size of associated file header */
+ struct gcov_ftree_node *next; /* Next leaf node */
+ node_status status; /* Status of this node */
+};
+
+
+/* If set to non-zero, keep gcov data for modules after unload. */
+static int gcov_persist = 0;
+
+/* If set to non-zero, create links to additional files in proc filesystem
+ * entries. */
+static int gcov_link = 1;
+
+/* Protect global variables from concurrent access. */
+static DECLARE_MUTEX_LOCKED(gcov_lock);
+
+/* Length of kernel source path string. */
+static int sourcepath_len;
+
+/* Length of kernel object path string. */
+static int objectpath_len;
+
+/* Filesystem entry for /proc/vmlinux */
+static struct proc_dir_entry *proc_vmlinux = NULL;
+
+/* First leaf node. */
+static struct gcov_ftree_node *leaf_nodes = NULL;
+
+/* Cached node used to speed up sequential reads in /proc/vmlinux. */
+static struct gcov_ftree_node *cached_node = NULL;
+
+/* Root node for internal data tree. */
+static struct gcov_ftree_node tree_root;
+
+#if GCC_VERSION_LOWER(3,4)
+/* Filename extension for data files. */
+static const char *da_ending = "da";
+
+/* Array of filename endings to use when creating links. */
+static const char *endings[] = { "bb", "bbg", "c" };
+#else
+/* Filename extension for data files. */
+static const char *da_ending = "gcda";
+
+/* Array of filename endings to use when creating links. */
+static const char *endings[] = { "gcno", "c" };
+#endif /* GCC_VERSION_LOWER */
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) && \
+ (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,4)) || \
+ (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23))
+/* Retrieve proc_dir_entry associated with INODE. */
+static inline struct proc_dir_entry *
+PDE(const struct inode *inode)
+{
+ return ((struct proc_dir_entry *) inode->u.generic_ip);
+}
+#endif
+
+
+#ifdef MODULE
+/* Parameter handling. */
+MODULE_PARM(gcov_persist, "i");
+MODULE_PARM_DESC(gcov_persist, "If set to non-zero, keep gcov data for modules "
+ "after unload");
+MODULE_PARM(gcov_link, "i");
+MODULE_PARM_DESC(gcov_link, "If set to non-zero, create links to additional "
+ "files in proc filesystem entries");
+
+#else
+
+/* Called when 'gcov_persist' is specified on the kernel command line. */
+static int __init
+gcov_persist_setup(char *str)
+{
+ gcov_persist = (int) simple_strtol(str, NULL, 10);
+ return 1;
+}
+
+__setup("gcov_persist=", gcov_persist_setup);
+
+
+/* Called when 'gcov_link' is specified on the kernel command line. */
+static int __init
+gcov_link_setup(char *str)
+{
+ gcov_link = (int) simple_strtol(str, NULL, 10);
+ return 1;
+}
+
+__setup("gcov_link=", gcov_link_setup);
+#endif /* MODULE */
+
+
+/* Store a portable representation of VALUE in DEST using BYTES*8-1 bits.
+ * Return a non-zero value if VALUE requires more than BYTES*8-1 bits
+ * to store (adapted from gcc/gcov-io.h). */
+static int
+store_gcov_type(gcov_type value, char *dest, size_t bytes)
+{
+ int upper_bit = (value < 0 ? 128 : 0);
+ size_t i;
+
+ if (value < 0) {
+ gcov_type oldvalue = value;
+ value = -value;
+ if (oldvalue != -value)
+ return 1;
+ }
+
+ for (i = 0 ; i < (sizeof(value) < bytes ? sizeof(value) : bytes) ;
+ i++) {
+ dest[i] = value & (i == (bytes - 1) ? 127 : 255);
+ value = value / 256;
+ }
+
+ if (value && value != -1)
+ return 1;
+
+ for(; i < bytes ; i++)
+ dest[i] = 0;
+ dest[bytes - 1] |= upper_bit;
+ return 0;
+}
+
+
+/* Return size of header which precedes .da file entry associated with BB
+ * in the vmlinux file. */
+static inline size_t
+sizeof_vmlinux_header(struct bb *bb)
+{
+ return 8 + PAD8(strlen(bb->filename) + 1);
+}
+
+
+/* Store data of header which precedes .da file entry associated with NODE
+ * in the vmlinux file to userspace memory at BUF. OFFSET specifies the offset
+ * inside the header file. COUNT is the maximum number of bytes to store.
+ * Return the number of bytes stored, zero for EOF or a negative number in
+ * case of error. */
+static ssize_t
+store_vmlinux_header(struct gcov_ftree_node *node, char *buf, size_t count,
+ loff_t offset)
+{
+ char data[8];
+ char *from;
+ size_t namelen;
+ ssize_t stored;
+ size_t len;
+
+ namelen = strlen(node->bb->filename);
+ stored = 0;
+ while (count > 0) {
+ if (offset < 8) {
+ /* Filename length */
+ if (store_gcov_type(PAD8(namelen + 1), data, 8))
+ return -EINVAL;
+ from = data + offset;
+ len = 8 - offset;
+ } else if (offset < 8 + namelen) {
+ /* Filename */
+ from = (char *) node->bb->filename + offset - 8;
+ len = namelen - (offset - 8);
+ } else if (offset < node->header_size) {
+ /* Nil byte padding */
+ memset(data, 0, 8);
+ from = data;
+ len = PAD8(namelen + 1) - (offset - 8);
+ } else
+ break;
+ if (len > count)
+ len = count;
+ if (copy_to_user(buf, from, len))
+ return -EFAULT;
+ stored += len;
+ count -= len;
+ offset += len;
+ buf += len;
+ }
+
+ return stored;
+}
+
+
+#if GCC_VERSION_LOWER(3, 3)
+/*
+ * pre-gcc 3.3 functions
+ */
+
+
+/* Return size of .da file associated with BB. */
+static inline size_t
+sizeof_da_file(struct bb *bb)
+{
+ return (bb->ncounts + 1) * 8;
+}
+
+
+/* Store data of .da file associated with NODE to userspace memory at BUF.
+ * OFFSET specifies the offset inside the .da file. COUNT is the maximum
+ * number of bytes to store. Return the number of bytes stored, zero for
+ * EOF or a negative number in case of error. */
+static ssize_t
+store_da_file(struct gcov_ftree_node *node, char *buf, size_t count,
+ loff_t offset)
+{
+ char data[8];
+ char *from;
+ ssize_t stored;
+ size_t len;
+
+ stored = 0;
+ while (count > 0) {
+ if (offset < 8) {
+ /* Number of counts */
+ if (store_gcov_type(node->bb->ncounts, data, 8))
+ return -EINVAL;
+ from = data + offset;
+ len = 8 - offset;
+ } else if (offset < node->da_size) {
+ /* Count data */
+ if (store_gcov_type(node->bb->counts[(offset - 8) / 8],
+ data, 8))
+ return -EINVAL;
+ from = data + offset % 8;
+ len = 8 - offset % 8;
+ } else
+ break;
+ if (len > count)
+ len = count;
+ if (copy_to_user(buf, from, len))
+ return -EFAULT;
+ stored += len;
+ count -= len;
+ offset += len;
+ buf += len;
+ }
+ return stored;
+}
+
+#elif GCC_VERSION_LOWER(3, 4)
+/*
+ * gcc 3.3 specific functions
+ */
+
+
+/* Return size of .da file section associated with function data FUNC. */
+static inline size_t
+sizeof_func_info(struct bb_function_info *func)
+{
+ return (size_t)
+ (/* delim */ 4 + /* strlen */ 4 + PAD4(strlen(func->name) + 1) +
+ /* delim */ 4 + /* checksum */ 4 + /* arc_count */ 4 +
+ /* count values */ func->arc_count * 8);
+}
+
+
+/* Return size of .da file associated with BB. */
+static inline size_t
+sizeof_da_file(struct bb *bb)
+{
+ struct bb_function_info *func;
+ size_t size;
+
+ size = ( /* magic */ 4 + /* num_func */ 4 + /* num_extra */ 4);
+ for (func = bb->function_infos; func->arc_count != -1; func++)
+ size += sizeof_func_info(func);
+ return size;
+}
+
+
+/* Return the number of functions associated with BB. */
+static inline gcov_type
+count_functions(struct bb *bb)
+{
+ gcov_type result;
+
+ for (result = 0; bb->function_infos[result].arc_count != -1;
+ result++);
+ return result;
+}
+
+
+/* Return non-zero if OFFSET is within the range START <= OFFSET < START + SIZE,
+ * zero otherwise. Update REL_OFF to contain the relative offset inside the
+ * range, SIZE_VAR to contain the range size and START to point to the next
+ * range after this one. */
+static inline int in_range(loff_t offset, size_t size, loff_t *rel_off,
+ loff_t *start, size_t *size_var)
+{
+ int result;
+
+ result = (offset >= *start) && (offset < *start + size);
+ *rel_off = offset - *start;
+ *start += size;
+ *size_var = size;
+ return result;
+}
+
+
+/* Store data of .da file associated with NODE to userspace memory at BUF.
+ * OFFSET specifies the offset inside the .da file. COUNT is the maximum
+ * number of bytes to store. Return the number of bytes stored, zero for
+ * EOF or a negative number in case of error. */
+static ssize_t
+store_da_file(struct gcov_ftree_node *node, char *buf, size_t count,
+ loff_t offset)
+{
+ struct bb_function_info *func;
+ gcov_type *count_ptr;
+ char data[8];
+ char *from;
+ ssize_t stored;
+ size_t len;
+ size_t size;
+ size_t func_off;
+ size_t next_off;
+ loff_t rel_off;
+ loff_t start;
+
+ func_off = 0;
+ func = NULL;
+ count_ptr = NULL;
+ stored = 0;
+ while (count > 0) {
+ start = 0;
+ if (in_range(offset, 4, &rel_off, &start, &size)) {
+ /* Magic */
+ if (store_gcov_type(-123, data, 4))
+ return -EINVAL;
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset, 4, &rel_off, &start, &size)) {
+ /* Number of functions */
+ if (store_gcov_type(count_functions(node->bb),
+ data, 4))
+ return -EINVAL;
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset, 4, &rel_off, &start, &size)) {
+ /* Size of extra data */
+ store_gcov_type(0, data, 4);
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (offset < node->da_size) {
+ /* Function data */
+ rel_off = offset - 12;
+ /* Try to minimize search effort */
+ if (!(func && (func_off <= rel_off))) {
+ func = node->bb->function_infos;
+ func_off = 0;
+ count_ptr = node->bb->counts;
+ }
+ /* Find function which is hit by offset */
+ for (; func->arc_count != -1; func++) {
+ next_off = func_off + sizeof_func_info(func);
+ if (next_off > rel_off)
+ break;
+ func_off = next_off;
+ count_ptr += func->arc_count;
+ }
+ start = 0;
+ if (in_range(offset - func_off - 12, 4, &rel_off,
+ &start, &size)) {
+ /* String delimiter */
+ store_gcov_type(-1, data, 4);
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12, 4, &rel_off,
+ &start, &size)) {
+ /* String length */
+ if (store_gcov_type(strlen(func->name),
+ data, 4))
+ return -EINVAL;
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12,
+ strlen(func->name), &rel_off, &start,
+ &size)) {
+ /* Function name */
+ from = (char *) func->name + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12,
+ PAD4(strlen(func->name) + 1) -
+ strlen(func->name), &rel_off, &start,
+ &size)) {
+ /* Nil byte padding */
+ memset(data, 0, size);
+ from = data;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12, 4, &rel_off,
+ &start, &size)) {
+ /* String delimiter */
+ store_gcov_type(-1, data, size);
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12, 4, &rel_off,
+ &start, &size)) {
+ /* Checksum */
+ store_gcov_type(func->checksum, data, 4);
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12, 4, &rel_off,
+ &start, &size)) {
+ /* Number of arcs */
+ if (store_gcov_type(func->arc_count, data, 4))
+ return -EINVAL;
+ from = data + rel_off;
+ len = size - rel_off;
+ } else if (in_range(offset - func_off - 12,
+ func->arc_count * 8, &rel_off, &start,
+ &size)) {
+ /* Counts */
+ if (store_gcov_type(count_ptr[rel_off / 8],
+ data, 8))
+ return -EINVAL;
+ from = data + rel_off % 8;
+ len = 8 - rel_off % 8;
+ } else {
+ break;
+ }
+ } else
+ break;
+ if (len > count)
+ len = count;
+ if (copy_to_user(buf, from, len))
+ return -EFAULT;
+ stored += len;
+ count -= len;
+ offset += len;
+ buf += len;
+ }
+ return stored;
+}
+#else
+/*
+ * gcc 3.4 functions
+ */
+
+/* Determine whether counter TYPE is active in BB. */
+static inline int
+counter_active(struct bb *bb, unsigned int type)
+{
+ return (1 << type) & bb->ctr_mask;
+}
+
+
+/* Return the number of active counter types for BB. */
+static inline unsigned int
+num_counter_active(struct bb *bb)
+{
+ unsigned int i;
+ unsigned int result;
+
+ result = 0;
+ for (i=0; i < GCOV_COUNTERS; i++)
+ if (counter_active(bb, i))
+ result++;
+ return result;
+}
+
+
+/* Get number of bytes used for one entry in the gcov_fn_info array pointed to
+ * by BB->functions. */
+static inline unsigned int
+get_fn_stride(struct bb *bb)
+{
+ unsigned int stride;
+
+ stride = sizeof(struct gcov_fn_info) + num_counter_active(bb) *
+ sizeof(unsigned int);
+ if (__alignof__(struct gcov_fn_info) > sizeof(unsigned int)) {
+ stride += __alignof__(struct gcov_fn_info) - 1;
+ stride &= ~(__alignof__(struct gcov_fn_info) - 1);
+ }
+ return stride;
+}
+
+
+/* Get the address of gcov_fn_info for function FUNC of BB. */
+static inline struct gcov_fn_info *
+get_fn_info(struct bb *bb, unsigned int func)
+{
+ return (struct gcov_fn_info *)
+ ((char *) bb->functions + func * get_fn_stride(bb));
+}
+
+
+/* Return size of .gcda counter section. */
+static inline size_t
+sizeof_counter_data(struct bb *bb, struct gcov_fn_info *func, unsigned int type)
+{
+ if (counter_active(bb, type)) {
+ return /* tag */ 4 + /* length */ 4 +
+ /* counters */ func->n_ctrs[type] * 8;
+ } else
+ return 0;
+}
+
+
+/* Return size of .gcda data section associated with FUNC. */
+static inline size_t
+sizeof_func_data(struct bb *bb, struct gcov_fn_info *func)
+{
+ size_t result;
+ unsigned int type;
+
+ result = /* tag */ 4 + /* length */ 4 + /* ident */ 4+
+ /* checksum */ 4;
+ for (type=0; type < GCOV_COUNTERS; type++)
+ result += sizeof_counter_data(bb, func, type);
+ return result;
+}
+
+
+/* Get size of .gcda file associated with BB. */
+static inline size_t
+sizeof_da_file(struct bb *bb)
+{
+ size_t result;
+ unsigned int i;
+
+ result = /* magic */ 4 + /* version */ 4 + /* stamp */ 4;
+ for (i=0; i < bb->n_functions; i++)
+ result += sizeof_func_data(bb, get_fn_info(bb, i));
+ return result;
+}
+
+
+/* Store a 32 bit unsigned integer value in GCOV format to memory at address
+ * BUF. */
+static inline void
+store_int32(uint32_t i, char *buf)
+{
+ uint32_t *p;
+
+ p = (int *) buf;
+ *p = i;
+}
+
+
+/* Store a 64 bit unsigned integer value in GCOV format to memory at address
+ * BUF. */
+static inline void
+store_int64(uint64_t i, char *buf)
+{
+ store_int32((uint32_t) (i & 0xffff), buf);
+ store_int32((uint32_t) (i >> 32), buf + 4);
+}
+
+
+/* Store a gcov counter in GCOV format to memory at address BUF. The counter is
+ * identified by BB, FUNC, TYPE and COUNTER. */
+static inline void
+store_counter(struct bb *bb, unsigned int func, unsigned int type,
+ unsigned int counter, char *buf)
+{
+ unsigned int counter_off;
+ unsigned int type_off;
+ unsigned int i;
+
+ /* Get offset into counts array */
+ type_off = 0;
+ for (i=0; i < type; i++)
+ if (counter_active(bb, i))
+ type_off++;
+ /* Get offset into values array. */
+ counter_off = counter;
+ for (i=0; i < func; i++)
+ counter_off += get_fn_info(bb, i)->n_ctrs[type];
+ /* Create in temporary storage */
+ store_int64(bb->counts[type_off].values[counter_off], buf);
+}
+
+
+/* Store a counter section in userspace memory. The counter section is
+ * identified by BB, FUNC and TYPE. The destination address is BUF. Store at
+ * most COUNT bytes beginning at OFFSET. Return the number of bytes stored or a
+ * negative value on error. */
+static inline ssize_t
+store_counter_data(struct bb *bb, unsigned int func, unsigned int type,
+ char *buf, size_t count, loff_t offset)
+{
+ struct gcov_fn_info *func_ptr;
+ char data[8];
+ char *from;
+ size_t len;
+ ssize_t result;
+ unsigned int i;
+
+ result = 0;
+ func_ptr = get_fn_info(bb, func);
+ while (count > 0) {
+ if (offset < 4) {
+ /* Tag ID */
+ store_int32((uint32_t) GCOV_TAG_FOR_COUNTER(type),
+ data);
+ len = 4 - offset;
+ from = data + offset;
+ } else if (offset < 8) {
+ /* Tag length in groups of 4 bytes */
+ store_int32((uint32_t)
+ func_ptr->n_ctrs[type] * 2, data);
+ len = 4 - (offset - 4);
+ from = data + (offset - 4);
+ } else {
+ /* Actual counter data */
+ i = (offset - 8) / 8;
+ /* Check for EOF */
+ if (i >= func_ptr->n_ctrs[type])
+ break;
+ store_counter(bb, func, type, i, data);
+ len = 8 - (offset - 8) % 8;
+ from = data + (offset - 8) % 8;
+ }
+ if (len > count)
+ len = count;
+ if (copy_to_user(buf, from, len))
+ return -EFAULT;
+ count -= len;
+ buf += len;
+ offset += len;
+ result += len;
+ }
+ return result;
+}
+
+
+/* Store a function section and associated counter sections in userspace memory.
+ * The function section is identified by BB and FUNC. The destination address is
+ * BUF. Store at most COUNT bytes beginning at OFFSET. Return the number of
+ * bytes stored or a negative value on error. */
+static inline ssize_t
+store_func_data(struct bb *bb, unsigned int func, char *buf,
+ size_t count, loff_t offset)
+{
+ struct gcov_fn_info *func_ptr;
+ char data[4];
+ char *from;
+ size_t len;
+ unsigned int i;
+ loff_t off;
+ size_t size;
+ ssize_t result;
+ ssize_t rc;
+
+ func_ptr = get_fn_info(bb, func);
+ result = 0;
+ while (count > 0) {
+ if (offset < 16) {
+ if (offset < 4) {
+ /* Tag ID */
+ store_int32((uint32_t) GCOV_TAG_FUNCTION, data);
+ len = 4 - offset;
+ from = data + offset;
+ } else if (offset < 8) {
+ /* Tag length */
+ store_int32(2, data);
+ len = 4 - (offset - 4);
+ from = data + (offset - 4);
+ } else if (offset < 12) {
+ /* Function ident */
+ store_int32((uint32_t) func_ptr->ident, data);
+ len = 4 - (offset - 8);
+ from = data + (offset - 8);
+ } else {
+ /* Function checksum */
+ store_int32((uint32_t) func_ptr->checksum,
+ data);
+ len = 4 - (offset - 12);
+ from = data + (offset - 12);
+ }
+ /* Do the actual store */
+ if (len > count)
+ len = count;
+ if (copy_to_user(buf, from, len))
+ return -EFAULT;
+ } else {
+ off = 16;
+ len = 0;
+ for (i=0; i < GCOV_COUNTERS; i++) {
+ size = sizeof_counter_data(bb, func_ptr, i);
+ if (offset < off + size) {
+ rc = store_counter_data(bb, func, i,
+ buf, count,
+ offset - off);
+ if (rc < 0)
+ return rc;
+ len = rc;
+ break;
+ }
+ off += size;
+ }
+ /* Check for EOF */
+ if (i == GCOV_COUNTERS)
+ break;
+ }
+ count -= len;
+ buf += len;
+ offset += len;
+ result += len;
+ }
+ return result;
+}
+
+
+/* Store data of .gcda file associated with NODE to userspace memory at BUF.
+ * OFFSET specifies the offset inside the .da file. COUNT is the maximum
+ * number of bytes to store. Return the number of bytes stored, zero for
+ * EOF or a negative number in case of error. */
+static ssize_t
+store_da_file(struct gcov_ftree_node *node, char *buf, size_t count,
+ loff_t offset)
+{
+ struct bb *bb;
+ char data[4];
+ char *from;
+ size_t len;
+ unsigned int i;
+ loff_t off;
+ size_t size;
+ ssize_t result;
+ ssize_t rc;
+
+ bb = node->bb;
+ result = 0;
+ while (count > 0) {
+ if (offset < 12) {
+ if (offset < 4) {
+ /* File magic */
+ store_int32((uint32_t) GCOV_DATA_MAGIC, data);
+ len = 4 - offset;
+ from = data + offset;
+ } else if (offset < 8) {
+ /* File format/GCC version */
+ store_int32(gcov_version, data);
+ len = 4 - (offset - 4);
+ from = data + (offset - 4);
+ } else {
+ /* Time stamp */
+ store_int32((uint32_t) bb->stamp, data);
+ len = 4 - (offset - 8);
+ from = data + (offset - 8);
+ }
+ /* Do the actual store */
+ if (len > count)
+ len = count;
+ if (copy_to_user(buf, from, len))
+ return -EFAULT;
+ } else {
+ off = 12;
+ len = 0;
+ for (i=0; i < bb->n_functions; i++) {
+ size = sizeof_func_data(bb, get_fn_info(bb, i));
+ if (offset < off + size) {
+ rc = store_func_data(bb, i, buf, count,
+ offset - off);
+ if (rc < 0)
+ return rc;
+ len = rc;
+ break;
+ }
+ off += size;
+ }
+ /* Check for EOF */
+ if (i == bb->n_functions)
+ break;
+ }
+ count -= len;
+ buf += len;
+ offset += len;
+ result += len;
+ }
+ return result;
+}
+#endif /* if GCC_VERSION_LOWER */
+
+
+/* Update data related to vmlinux file. */
+static void
+update_vmlinux_data(void)
+{
+ struct gcov_ftree_node *node;
+ loff_t offset;
+
+ offset = 0;
+ for (node = leaf_nodes; node; node = node->next) {
+ node->offset = offset;
+ node->da_size = sizeof_da_file(node->bb);
+ node->header_size = sizeof_vmlinux_header(node->bb);
+ offset += node->header_size + node->da_size;
+ }
+ proc_vmlinux->size = offset;
+ cached_node = NULL;
+}
+
+
+/* Read .da or vmlinux file. */
+static ssize_t
+read_gcov(struct file *file, char *buf, size_t count, loff_t *pos)
+{
+ struct gcov_ftree_node *node;
+ struct proc_dir_entry *dir_entry;
+ ssize_t rc;
+
+ down(&gcov_lock);
+ dir_entry = PDE(file->f_dentry->d_inode);
+ rc = 0;
+ if (dir_entry == proc_vmlinux) {
+ /* Are we in a sequential read? */
+ if (cached_node && (*pos >= cached_node->offset))
+ node = cached_node;
+ else
+ node = leaf_nodes;
+ /* Find node corresponding to offset */
+ while (node && node->next && (*pos >= node->next->offset))
+ node = node->next;
+ cached_node = node;
+ if (node) {
+ if (*pos - node->offset < node->header_size)
+ rc = store_vmlinux_header(node, buf, count,
+ *pos - node->offset);
+ else
+ rc = store_da_file(node, buf, count,
+ *pos - node->offset -
+ node->header_size);
+ }
+ } else {
+ node = (struct gcov_ftree_node *) dir_entry->data;
+ if (node)
+ rc = store_da_file(node, buf, count, *pos);
+ }
+ if (rc > 0)
+ *pos += rc;
+ up(&gcov_lock);
+ return rc;
+}
+
+
+static inline void
+reset_bb(struct bb* bb)
+{
+#if GCC_VERSION_LOWER(3, 4)
+ memset(bb->counts, 0, bb->ncounts * sizeof(gcov_type));
+#else
+ const struct gcov_ctr_info *ctr;
+ unsigned int i;
+
+ ctr = bb->counts;
+ for (i=0; i < GCOV_COUNTERS; i++)
+ if (counter_active(bb, i)) {
+ memset(ctr->values, 0, ctr->num * sizeof(gcov_type));
+ ctr++;
+ }
+#endif /* GCC_VERSION_LOWER */
+}
+
+
+static void cleanup_node_and_path(struct gcov_ftree_node *node);
+
+/* Reset counters on write request. */
+static ssize_t
+write_gcov(struct file *file, const char *buf, size_t count, loff_t *ppos)
+{
+ struct gcov_ftree_node *node;
+ struct gcov_ftree_node *next;
+ struct proc_dir_entry *dir_entry;
+
+ down(&gcov_lock);
+ dir_entry = PDE(file->f_dentry->d_inode);
+ if (dir_entry == proc_vmlinux) {
+ /* Reset all nodes */
+ node = leaf_nodes;
+ while (node) {
+ next = node->next;
+ /* Delete ghosted nodes */
+ if (node->status == status_ghost)
+ cleanup_node_and_path(node);
+ else
+ reset_bb(node->bb);
+ node = next;
+ }
+ /* Nodes may have been deleted - update data */
+ if (gcov_persist)
+ update_vmlinux_data();
+ } else {
+ node = (struct gcov_ftree_node *) dir_entry->data;
+ reset_bb(node->bb);
+ }
+ up(&gcov_lock);
+ return count;
+}
+
+
+/* Return a newly allocated copy of STRING. */
+static inline char *
+strdup(const char *string)
+{
+ char *result;
+
+ result = (char *) kmalloc(strlen(string) + 1, GFP_KERNEL);
+ if (result)
+ strcpy(result, string);
+ return result;
+}
+
+
+/* Allocate a new node and fill in NAME and BB. */
+static struct gcov_ftree_node *
+alloc_node(const char *name, struct bb *bb)
+{
+ struct gcov_ftree_node *node;
+
+ node = (struct gcov_ftree_node *)
+ kmalloc(sizeof(struct gcov_ftree_node), GFP_KERNEL);
+ if (!node)
+ return NULL;
+ memset(node, 0, sizeof(struct gcov_ftree_node));
+ node->fname = strdup(name);
+ if (!node->fname) {
+ kfree(node);
+ return NULL;
+ }
+ node->bb = bb;
+ node->status = status_normal;
+ return node;
+}
+
+
+/* Free memory allocated for BB. */
+static void
+free_bb(struct bb *bb)
+{
+#if GCC_VERSION_LOWER(3,4)
+ kfree(bb);
+#else
+ kfree(bb->functions);
+ kfree(bb);
+#endif /* GCC_VERSION_LOWER */
+}
+
+
+/* Free memory allocated for NODE. */
+static void
+free_node(struct gcov_ftree_node *node)
+{
+ if (node == &tree_root)
+ return;
+ if (node->fname)
+ kfree(node->fname);
+ if (node->status == status_ghost)
+ free_bb(node->bb);
+ kfree(node);
+}
+
+
+/* Remove proc filesystem entries associated with NODE. */
+static void
+delete_from_proc(struct gcov_ftree_node *node)
+{
+ struct proc_dir_entry *parent;
+ int i;
+
+ if (node->parent)
+ parent = node->parent->proc[0];
+ else
+ parent = &proc_root;
+ for (i = 0; i < sizeof(node->proc) / sizeof(node->proc[0]); i++)
+ if (node->proc[i])
+ remove_proc_entry(node->proc[i]->name, parent);
+}
+
+
+/* Release all resources associated with NODE. If NODE is a directory node,
+ * also clean up all children. */
+static void
+cleanup_node(struct gcov_ftree_node *node)
+{
+ struct gcov_ftree_node *curr;
+ struct gcov_ftree_node *next;
+ struct gcov_ftree_node *prev;
+
+ next = node;
+ do {
+ /* Depth first traversal of all children */
+ curr = next;
+ while (curr->files)
+ curr = curr->files;
+ if (curr->sibling)
+ next = curr->sibling;
+ else
+ next = curr->parent;
+ /* Remove from tree */
+ if (curr->parent) {
+ if (curr->parent->files == curr)
+ curr->parent->files = curr->sibling;
+ else {
+ for (prev = curr->parent->files;
+ prev->sibling != curr;
+ prev = prev->sibling);
+ prev->sibling = curr->sibling;
+ }
+ }
+ /* Remove from leaf node list if necessary */
+ if (curr->bb) {
+ if (leaf_nodes == curr)
+ leaf_nodes = curr->next;
+ else {
+ for (prev = leaf_nodes;
+ prev && (prev->next != curr);
+ prev = prev->next);
+ if (prev)
+ prev->next = curr->next;
+ }
+ }
+ /* Delete node */
+ delete_from_proc(curr);
+ free_node(curr);
+ } while (node != curr);
+}
+
+
+/* Clean up NODE and containing path in case it would be left empty. */
+static void
+cleanup_node_and_path(struct gcov_ftree_node *node)
+{
+ while (node->parent &&
+ !node->parent->files->sibling)
+ node = node->parent;
+ cleanup_node(node);
+}
+
+
+/* Create a new directory node named NAME under PARENT. Upon success return
+ * zero and update RESULT to point to the newly created node. Return non-zero
+ * otherwise. */
+static int
+create_dir_node(struct gcov_ftree_node *parent, char *name,
+ struct gcov_ftree_node **result)
+{
+ struct gcov_ftree_node *node;
+
+ /* Initialize new node */
+ node = alloc_node(name, NULL);
+ if (!node)
+ return -ENOMEM;
+ /* Create proc filesystem entry */
+ node->proc[0] = proc_mkdir(name, parent->proc[0]);
+ if (!node->proc[0]) {
+ free_node(node);
+ return -EIO;
+ }
+ /* Insert node into tree */
+ node->parent = parent;
+ node->sibling = parent->files;
+ parent->files = node;
+ *result = node;
+ return 0;
+}
+
+
+static struct file_operations proc_gcov_operations = {
+ read: read_gcov,
+ write: write_gcov,
+ owner: THIS_MODULE
+};
+
+/* Create a new file node named NAME under PARENT. Associate node with BB.
+ * Return zero upon success, non-zero otherwise. */
+static int
+create_file_node(struct gcov_ftree_node *parent, char *name, struct bb *bb)
+{
+ struct gcov_ftree_node *node;
+ char *link_target;
+ char *link_name;
+ int i;
+
+ /* Initialize new node */
+ node = alloc_node(name, bb);
+ if (!node)
+ return -ENOMEM;
+ /* Create proc filesystem entry */
+ node->proc[0] = create_proc_entry(name, S_IWUSR | S_IRUGO,
+ parent->proc[0]);
+ if (!node->proc[0]) {
+ free_node(node);
+ return -EIO;
+ }
+ node->proc[0]->data = node;
+ node->proc[0]->proc_fops = &proc_gcov_operations;
+ node->proc[0]->size = sizeof_da_file(bb);
+ /* Create symbolic links */
+ if (gcov_link) {
+ /* Note: temp string length is calculated as upper limit */
+ link_target = (char *) kmalloc(strlen(bb->filename) +
+ strlen(da_ending) +
+ strlen(gcov_sourcepath),
+ GFP_KERNEL);
+ if (!link_target) {
+ delete_from_proc(node);
+ free_node(node);
+ return -ENOMEM;
+ }
+ for (i = 0; i < sizeof(endings) / sizeof(endings[0]); i++) {
+ if ((strcmp(endings[i], "c") == 0) &&
+ (strcmp(gcov_sourcepath, gcov_objectpath) != 0) &&
+ (strncmp(bb->filename, gcov_objectpath,
+ objectpath_len) == 0)) {
+ strcpy(link_target, gcov_sourcepath);
+ strcat(link_target,
+ bb->filename + objectpath_len);
+ } else {
+ strcpy(link_target, bb->filename);
+ }
+ link_target[strlen(link_target) -
+ strlen(da_ending)] = 0;
+ strcat(link_target, endings[i]);
+ link_name = strrchr(link_target, '/') + 1;
+ node->proc[i + 1] = proc_symlink(link_name,
+ parent->proc[0],
+ link_target);
+ if (!node->proc[i + 1]) {
+ kfree(link_target);
+ delete_from_proc(node);
+ free_node(node);
+ return -EIO;
+ }
+ }
+ kfree(link_target);
+ }
+ /* Insert node into tree */
+ node->parent = parent;
+ node->sibling = parent->files;
+ parent->files = node;
+ node->next = leaf_nodes;
+ leaf_nodes = node;
+ return 0;
+}
+
+
+/* Return proc filesystem entry name for FILENAME. */
+static char *
+get_proc_filename(const char *filename)
+{
+ char *result;
+
+ /* Is this file located in the kernel source directory? */
+ if (strncmp(filename, gcov_objectpath, objectpath_len) == 0) {
+ /* Use relative path */
+ result = strdup(filename + objectpath_len + 1);
+ } else {
+ /* Use full path in module subdirectory */
+ result = (char *) kmalloc(strlen(GCOV_PROC_MODULE) +
+ strlen(filename) + 1, GFP_KERNEL);
+ if (result) {
+ strcpy(result, GCOV_PROC_MODULE);
+ strcat(result, filename);
+ }
+ }
+ return result;
+}
+
+
+/* Create tree node and proc filesystem entry for BB. Create subdirectories as
+ * necessary. Return zero upon success, non-zero otherwise. */
+static int
+create_node(struct bb *bb)
+{
+ struct gcov_ftree_node *parent;
+ struct gcov_ftree_node *node;
+ char *filename;
+ char *curr;
+ char *next;
+ int rc;
+
+ filename = get_proc_filename(bb->filename);
+ if (!filename)
+ return -ENOMEM;
+ /* Recreate directory path in proc filesystem */
+ parent = &tree_root;
+ curr = filename;
+ while ((next = strchr(curr, '/'))) {
+ *next = 0;
+ /* Check whether directory already exists */
+ for (node = parent->files;
+ node && (strcmp(node->fname, curr) != 0);
+ node = node->sibling);
+ if (!node) {
+ /* Create directory node */
+ rc = create_dir_node(parent, curr, &node);
+ if (rc) {
+ if (parent != &tree_root)
+ cleanup_node_and_path(parent);
+ kfree(filename);
+ return rc;
+ }
+ }
+ parent = node;
+ curr = next + 1;
+ }
+ rc = create_file_node(parent, curr, bb);
+ kfree(filename);
+ return rc;
+}
+
+
+/* Return a copy of BB which contains only data relevant to this module. */
+static struct bb *
+clone_bb(struct bb *bb)
+{
+ struct bb *result;
+ size_t len;
+
+#if GCC_VERSION_LOWER(3, 3)
+ /* Allocate memory */
+ len = sizeof(struct bb) + bb->ncounts * sizeof(gcov_type) +
+ strlen(bb->filename) + 1;
+ result = (struct bb *) kmalloc(len, GFP_KERNEL);
+ if (!result)
+ return NULL;
+ memset(result, 0, len);
+ /* Copy count data */
+ result->counts = (gcov_type *) (result + 1);
+ result->ncounts = bb->ncounts;
+ memcpy(result->counts, bb->counts, result->ncounts * sizeof(gcov_type));
+ /* Copy filename */
+ result->filename = (const char *) &result->counts[result->ncounts];
+ strcpy((char *) result->filename, bb->filename);
+#elif GCC_VERSION_LOWER(3, 4)
+ unsigned int i;
+ char *name;
+
+ /* Allocate memory */
+ len = sizeof(struct bb) + bb->ncounts * sizeof(gcov_type) +
+ strlen(bb->filename) + 1 + sizeof(struct bb_function_info);
+ for (i = 0; bb->function_infos[i].arc_count != -1; i++)
+ len += sizeof(struct bb_function_info) +
+ strlen(bb->function_infos[i].name) + 1;
+ result = (struct bb *) kmalloc(len, GFP_KERNEL);
+ if (!result)
+ return NULL;
+ memset(result, 0, len);
+ /* Copy count data */
+ result->counts = (gcov_type *) (result + 1);
+ result->ncounts = bb->ncounts;
+ memcpy(result->counts, bb->counts, result->ncounts * sizeof(gcov_type));
+ /* Prepare copy of function infos */
+ result->function_infos = (struct bb_function_info *)
+ &result->counts[result->ncounts];
+ /* Copy filename */
+ result->filename = (const char *) &result->function_infos[i + 1];
+ strcpy((char *) result->filename, bb->filename);
+ /* Copy function infos */
+ name = (char *) result->filename + strlen(result->filename) + 1;
+ for (i = 0; bb->function_infos[i].arc_count != -1; i++) {
+ result->function_infos[i].checksum =
+ bb->function_infos[i].checksum;
+ result->function_infos[i].arc_count =
+ bb->function_infos[i].arc_count;
+ strcpy(name, bb->function_infos[i].name);
+ result->function_infos[i].name = name;
+ name += strlen(name) + 1;
+ }
+ result->function_infos[i].arc_count = -1;
+ result->sizeof_bb = bb->sizeof_bb;
+#else
+ unsigned int active;
+ unsigned int i;
+ char *name;
+ struct gcov_fn_info *func;
+
+ /* Allocate memory for struct bb */
+ active = num_counter_active(bb);
+ len = sizeof(struct bb) +
+ sizeof(struct gcov_ctr_info) * active +
+ strlen(bb->filename) + 1;
+ for (i=0; i < active; i++)
+ len += sizeof(gcov_type) * bb->counts[i].num;
+ result = (struct bb *) kmalloc(len, GFP_KERNEL);
+ if (!result)
+ return NULL;
+ memset(result, 0, len);
+ /* Allocate memory for array of struct gcov_fn_info */
+ len = bb->n_functions * get_fn_stride(bb);
+ func = (struct gcov_fn_info *) kmalloc(len, GFP_KERNEL);
+ if (!func) {
+ kfree(result);
+ return NULL;
+ }
+ /* Copy function data */
+ memcpy(func, bb->functions, len);
+ result->functions = func;
+ /* Copy counts */
+ for (i=0; i < active; i++) {
+ result->counts[i].num = bb->counts[i].num;
+ result->counts[i].merge = bb->counts[i].merge;
+ if (i == 0) {
+ result->counts[i].values =
+ (gcov_type *) &result->counts[active];
+ } else {
+ result->counts[i].values =
+ result->counts[i - 1].values +
+ result->counts[i - 1].num;
+ }
+ memcpy(result->counts[i].values, bb->counts[i].values,
+ sizeof(gcov_type) * result->counts[i].num);
+ }
+ /* Copy rest */
+ result->stamp = bb->stamp;
+ name = (char *) (result->counts[active - 1].values +
+ result->counts[active - 1].num);
+ strcpy(name, bb->filename);
+ result->filename = name;
+ result->n_functions = bb->n_functions;
+ result->ctr_mask = bb->ctr_mask;
+#endif /* GCC_VERSION_LOWER */
+ return result;
+}
+
+
+/* Return non-zero if BB1 and BB2 are compatible, zero otherwise. */
+static int
+is_compatible(struct bb *bb1, struct bb *bb2)
+{
+#if GCC_VERSION_LOWER(3, 3)
+ return (bb1->ncounts == bb2->ncounts);
+#elif GCC_VERSION_LOWER(3, 4)
+ int i;
+
+ if ((bb1->ncounts != bb2->ncounts) ||
+ (bb1->sizeof_bb != bb2->sizeof_bb))
+ return 0;
+ for (i = 0; (bb1->function_infos[i].arc_count != -1) &&
+ (bb2->function_infos[i].arc_count != -1); i++)
+ if (bb1->function_infos[i].checksum !=
+ bb2->function_infos[i].checksum)
+ return 0;
+ return (bb1->function_infos[i].arc_count == -1) &&
+ (bb2->function_infos[i].arc_count == -1);
+#else
+ return (bb1->stamp == bb2->stamp);
+#endif /* GCC_VERSION_LOWER */
+}
+
+
+/* Add count data from SOURCE to DEST. */
+static void
+merge_bb(struct bb *dest, struct bb *source)
+{
+#if GCC_VERSION_LOWER(3, 4)
+ long i;
+
+ for (i = 0; i < dest->ncounts; i++)
+ dest->counts[i] += source->counts[i];
+#else
+ unsigned int i;
+ unsigned int j;
+
+ for (i=0; i < num_counter_active(dest); i++)
+ for (j=0; j < dest->counts[i].num; j++)
+ dest->counts[i].values[j] +=
+ source->counts[i].values[j];
+#endif /* GCC_VERSION_LOWER */
+}
+
+
+/* If there is a ghosted node for BB, merge old and current data, set status
+ * to normal and return zero. Return non-zero otherwise. */
+static int
+revive_node(struct bb *bb)
+{
+ struct gcov_ftree_node *node;
+
+ /* Check for a ghosted node */
+ for (node = leaf_nodes; node &&
+ (strcmp(node->bb->filename, bb->filename) != 0);
+ node=node->next);
+ if (!node)
+ return -ENOENT;
+ /* Check for compatible data */
+ if (!is_compatible(bb, node->bb)) {
+ printk(KERN_WARNING GCOV_PROC_HEADER "discarding saved data "
+ "for %s due to incompatibilities\n", bb->filename);
+ cleanup_node_and_path(node);
+ update_vmlinux_data();
+ return -EINVAL;
+ }
+ /* Revive */
+ merge_bb(bb, node->bb);
+ kfree(node->bb);
+ node->bb = bb;
+ node->status = status_normal;
+ return 0;
+}
+
+
+/* Make a copy of the struct bb associated with node and set node status to
+ * ghost. Return zero on success, non-zero otherwise. */
+static int
+ghost_node(struct gcov_ftree_node *node)
+{
+ struct bb *bb;
+
+ /* Ghost node instead of removing it */
+ bb = clone_bb(node->bb);
+ if (!bb) {
+ printk(KERN_ERR GCOV_PROC_HEADER "not enough memory to save "
+ "data for %s", node->bb->filename);
+ return -ENOMEM;
+ }
+ node->bb = bb;
+ node->status = status_ghost;
+ return 0;
+}
+
+
+/* Callback used to keep track of changes in the bb list. */
+static void
+gcov_proc_callback(enum gcov_cmd cmd, struct bb *bb)
+{
+ struct gcov_ftree_node *node;
+ int rc;
+
+ down(&gcov_lock);
+ switch (cmd) {
+ case gcov_add:
+ if (gcov_persist && (revive_node(bb) == 0))
+ break;
+ /* Insert node */
+ rc = create_node(bb);
+ if (rc) {
+ printk(KERN_ERR GCOV_PROC_HEADER "add failed: could "
+ "not create node for %s (err=%d)\n",
+ bb->filename, rc);
+ }
+ update_vmlinux_data();
+ break;
+ case gcov_remove:
+ /* Find node to remove */
+ for (node = leaf_nodes; node && (node->bb != bb);
+ node=node->next);
+ if (!node)
+ break;
+ if (gcov_persist && (ghost_node(node) == 0))
+ break;
+ /* Remove node and empty path */
+ cleanup_node_and_path(node);
+ update_vmlinux_data();
+ break;
+ }
+ up(&gcov_lock);
+}
+
+
+/* Initialize module. */
+static int __init
+gcov_init_module(void)
+{
+ struct bb *bb;
+ int rc;
+
+ printk(KERN_INFO GCOV_PROC_HEADER "proc init (persist=%d link=%d)\n",
+ gcov_persist, gcov_link);
+ sourcepath_len = strlen(gcov_sourcepath);
+ objectpath_len = strlen(gcov_objectpath);
+ /* Initialize root node and /proc/gcov entry */
+ tree_root.fname = GCOV_PROC_ROOT;
+ tree_root.proc[0] = proc_mkdir(tree_root.fname, NULL);
+ if (!tree_root.proc[0]) {
+ printk(KERN_ERR GCOV_PROC_HEADER "init failed: could not "
+ "create root proc filesystem entry\n");
+ return -EIO;
+ }
+ /* Create /proc/gcov/vmlinux entry */
+ proc_vmlinux = create_proc_entry(GCOV_PROC_VMLINUX, S_IWUSR | S_IRUGO,
+ tree_root.proc[0]);
+ if (!proc_vmlinux) {
+ printk(KERN_ERR GCOV_PROC_HEADER "init failed: could not "
+ "create proc filesystem entry %s\n", GCOV_PROC_VMLINUX);
+ cleanup_node(&tree_root);
+ return -EIO;
+ }
+ proc_vmlinux->proc_fops = &proc_gcov_operations;
+ /* Initialize /proc/gcov tree */
+ spin_lock(&gcov_core_lock);
+ for (bb = bb_head; bb ; bb = bb->next) {
+ rc = create_node(bb);
+ if (rc) {
+ printk(KERN_ERR GCOV_PROC_HEADER "init failed: could "
+ "not create node for %s (err=%d)\n",
+ bb->filename, rc);
+ remove_proc_entry(proc_vmlinux->name,
+ tree_root.proc[0]);
+ cleanup_node(&tree_root);
+ return rc;
+ }
+ }
+ gcov_callback = gcov_proc_callback;
+ update_vmlinux_data();
+ spin_unlock(&gcov_core_lock);
+ up(&gcov_lock);
+ return 0;
+}
+
+
+/* Clean up module data. */
+static void __exit
+gcov_cleanup_module(void)
+{
+ down(&gcov_lock);
+ gcov_callback = NULL;
+ remove_proc_entry(proc_vmlinux->name, tree_root.proc[0]);
+ cleanup_node(&tree_root);
+ printk(KERN_INFO GCOV_PROC_HEADER "proc unloaded\n");
+}
+
+
+module_init(gcov_init_module);
+module_exit(gcov_cleanup_module);
diff -urN linux-source-2.6.16.orig/drivers/gcov/Kconfig linux-source-2.6.16/drivers/gcov/Kconfig
--- linux-source-2.6.16.orig/drivers/gcov/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-source-2.6.16/drivers/gcov/Kconfig 2006-04-24 10:58:01.000000000 +0100
@@ -0,0 +1,42 @@
+#
+# GCOV coverage profiling
+#
+
+menu "GCOV coverage profiling"
+
+config GCOV_PROFILE
+ bool "Include GCOV coverage profiling"
+ ---help---
+ Provide infrastructure for GCOV kernel coverage support.
+
+ Enable GCOV_ALL to get coverage data for the entire kernel
+ source.
+
+ To get coverage data for only specific files or directories,
+ add the following line to the respective Makefile:
+
+ EXTRA_CFLAGS += $(GCOV_FLAGS)
+
+ Note that GCOV_PROC has to be enabled to access GCOV kernel
+ coverage data.
+
+config GCOV_ALL
+ bool "Profile entire Kernel"
+ depends on GCOV_PROFILE
+ ---help---
+ If you say Y here, it will compile the entire kernel with coverage
+ option enabled.
+
+config GCOV_PROC
+ tristate "Provide GCOV proc file system entry"
+ depends on GCOV_PROFILE && PROC_FS
+ ---help---
+ Install a proc file system entry at /proc/gcov which provides
+ access to the current coverage state of the kernel code.
+
+ This option is also available as a module called gcov-proc.o.
+ It can be loaded using:
+
+ modprobe gcov-proc
+
+endmenu
diff -urN linux-source-2.6.16.orig/drivers/gcov/Makefile linux-source-2.6.16/drivers/gcov/Makefile
--- linux-source-2.6.16.orig/drivers/gcov/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-source-2.6.16/drivers/gcov/Makefile 2006-04-24 10:58:01.000000000 +0100
@@ -0,0 +1,9 @@
+#
+# Makefile for GCOV profiling kernel module
+#
+
+obj-$(CONFIG_GCOV_PROFILE) += gcov-core.o
+obj-$(CONFIG_GCOV_PROC) += gcov-proc.o
+
+CFLAGS_gcov-core.o := -DGCOV_SRC_PATH='"$(srctree)"' -DGCOV_OBJ_PATH='"$(objtree)"'
+
diff -urN linux-source-2.6.16.orig/drivers/Makefile linux-source-2.6.16/drivers/Makefile
--- linux-source-2.6.16.orig/drivers/Makefile 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/drivers/Makefile 2006-04-24 10:58:01.000000000 +0100
@@ -67,6 +67,7 @@
obj-$(CONFIG_MCA) += mca/
obj-$(CONFIG_EISA) += eisa/
obj-$(CONFIG_CPU_FREQ) += cpufreq/
+obj-$(CONFIG_GCOV_PROFILE) += gcov/
obj-$(CONFIG_MMC) += mmc/
obj-$(CONFIG_INFINIBAND) += infiniband/
obj-$(CONFIG_SGI_SN) += sn/
diff -urN linux-source-2.6.16.orig/include/linux/gcov.h linux-source-2.6.16/include/linux/gcov.h
--- linux-source-2.6.16.orig/include/linux/gcov.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-source-2.6.16/include/linux/gcov.h 2006-04-24 10:58:01.000000000 +0100
@@ -0,0 +1,184 @@
+/*
+ * include/linux/gcov.h
+ *
+ * Type declarations and macros used by GCOV kernel profiling.
+ *
+ * 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.
+ *
+ * Copyright (c) International Business Machines Corp., 2002-2003
+ *
+ * Author: Hubertus Franke <frankeh@us.ibm.com>
+ * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
+ */
+
+#ifndef GCOV_H
+#define GCOV_H GCOV_H
+
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <asm/types.h>
+
+#define GCC_VERSION_LOWER(major, minor) ((__GNUC__ < major) || \
+ (__GNUC__ == major) && \
+ (__GNUC_MINOR__ < minor))
+
+#if GCC_VERSION_LOWER(3, 1)
+/*
+ * Profiling types for GCC prior to version 3.1
+ */
+
+typedef long gcov_type;
+
+/* Same as gcc/libgcc2.c */
+struct bb
+{
+ long zero_word;
+ const char *filename;
+ long *counts;
+ long ncounts;
+ struct bb *next;
+ const unsigned long *addresses;
+ long nwords;
+ const char **functions;
+ const long *line_nums;
+ const char **filenames;
+ char *flags;
+};
+
+#elif GCC_VERSION_LOWER(3, 3)
+/*
+ * Profiling types for GCC 3.1 to 3.2
+ */
+
+#if BITS_PER_LONG >= 64
+typedef long gcov_type;
+#else
+typedef long long gcov_type;
+#endif
+
+/* Same as gcc/libgcc2.c */
+struct bb
+{
+ long zero_word;
+ const char *filename;
+ gcov_type *counts;
+ long ncounts;
+ struct bb *next;
+ const unsigned long *addresses;
+ long nwords;
+ const char **functions;
+ const long *line_nums;
+ const char **filenames;
+ char *flags;
+};
+
+#elif GCC_VERSION_LOWER(3, 4)
+/*
+ * Profiling types for GCC 3.3
+ */
+
+typedef long long gcov_type;
+
+/* Same as gcc/libgcc2.c */
+struct bb_function_info
+{
+ long checksum;
+ int arc_count;
+ const char *name;
+};
+
+struct bb
+{
+ long zero_word;
+ const char *filename;
+ gcov_type *counts;
+ long ncounts;
+ struct bb *next;
+ long sizeof_bb;
+ struct bb_function_info *function_infos;
+};
+
+#else
+/*
+ * Profiling types for GCC 3.4 and above (see gcc-3.4/gcc/gcov-io.h)
+ */
+
+#define GCOV_COUNTERS 5
+#define GCOV_DATA_MAGIC ((gcov_unsigned_t) 0x67636461)
+#define GCOV_TAG_FUNCTION ((gcov_unsigned_t) 0x01000000)
+#define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t) 0x01a10000)
+#define GCOV_TAG_FOR_COUNTER(COUNT) \
+ (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t) (COUNT) << 17))
+
+#if BITS_PER_LONG >= 64
+typedef long gcov_type;
+#else
+typedef long long gcov_type;
+#endif
+
+typedef unsigned int gcov_unsigned_t;
+typedef unsigned int gcov_position_t;
+
+typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
+
+struct gcov_fn_info
+{
+ gcov_unsigned_t ident;
+ gcov_unsigned_t checksum;
+ unsigned int n_ctrs[0]; /* Note: the number of bits
+ * set in bb->ctr_mask decides
+ * how big this array is. */
+};
+
+struct gcov_ctr_info
+{
+ gcov_unsigned_t num;
+ gcov_type *values;
+ gcov_merge_fn merge;
+};
+
+struct bb /* should be 'struct gcov_info' but we're sticking with the old name
+ * so we can reuse some of our pre-3.4 functions */
+{
+ gcov_unsigned_t version;
+ struct bb *next;
+ gcov_unsigned_t stamp;
+ const char *filename;
+ unsigned int n_functions;
+ const struct gcov_fn_info *functions;
+ unsigned int ctr_mask;
+ struct gcov_ctr_info counts[0]; /* Note: the number of bits
+ * set in ctr_mask decides
+ * how big this array is. */
+};
+
+extern gcov_unsigned_t gcov_version;
+#endif /* GCC_VERSION */
+
+enum gcov_cmd {
+ gcov_add,
+ gcov_remove
+};
+
+extern struct bb *bb_head;
+extern const char *gcov_sourcepath;
+extern const char *gcov_objectpath;
+extern spinlock_t gcov_core_lock;
+
+extern void do_global_ctors(const char *, const char *, struct module *);
+extern void (*gcov_callback)(enum gcov_cmd, struct bb *);
+extern void remove_bb_link(struct module *);
+
+#endif /* GCOV_H */
diff -urN linux-source-2.6.16.orig/include/linux/module.h linux-source-2.6.16/include/linux/module.h
--- linux-source-2.6.16.orig/include/linux/module.h 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/include/linux/module.h 2006-04-24 10:58:01.000000000 +0100
@@ -313,6 +313,11 @@
/* The command line arguments (may be mangled). People like
keeping pointers to this stuff */
char *args;
+
+#ifdef CONFIG_GCOV_PROFILE
+ const char *ctors_start; /* Pointer to start of .ctors-section */
+ const char *ctors_end; /* Pointer to end of .ctors-section */
+#endif
};
/* FIXME: It'd be nice to isolate modules during init, too, so they
diff -urN linux-source-2.6.16.orig/kernel/module.c linux-source-2.6.16/kernel/module.c
--- linux-source-2.6.16.orig/kernel/module.c 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/kernel/module.c 2006-04-24 10:58:01.000000000 +0100
@@ -42,6 +42,7 @@
#include <asm/uaccess.h>
#include <asm/semaphore.h>
#include <asm/cacheflush.h>
+#include <linux/gcov.h>
#if 0
#define DEBUGP printk
@@ -1174,6 +1175,11 @@
/* Arch-specific cleanup. */
module_arch_cleanup(mod);
+#ifdef CONFIG_GCOV_PROFILE
+ if (mod->ctors_start && mod->ctors_end)
+ remove_bb_link(mod);
+#endif
+
/* Module unload stuff */
module_unload_free(mod);
@@ -1744,6 +1750,13 @@
/* Module has been moved. */
mod = (void *)sechdrs[modindex].sh_addr;
+#ifdef CONFIG_GCOV_PROFILE
+ modindex = find_sec(hdr, sechdrs, secstrings, ".ctors");
+ mod->ctors_start = (char *)sechdrs[modindex].sh_addr;
+ mod->ctors_end = (char *)(mod->ctors_start +
+ sechdrs[modindex].sh_size);
+#endif
+
/* Now we've moved module, initialize linked lists, etc. */
module_unload_init(mod);
@@ -1954,6 +1967,12 @@
notifier_call_chain(&module_notify_list, MODULE_STATE_COMING, mod);
up(¬ify_mutex);
+#ifdef CONFIG_GCOV_PROFILE
+ if (mod->ctors_start && mod->ctors_end) {
+ do_global_ctors(mod->ctors_start, mod->ctors_end, mod);
+ }
+#endif
+
/* Start the module */
if (mod->init != NULL)
ret = mod->init();
diff -urN linux-source-2.6.16.orig/Makefile linux-source-2.6.16/Makefile
--- linux-source-2.6.16.orig/Makefile 2006-03-22 15:20:47.000000000 +0000
+++ linux-source-2.6.16/Makefile 2006-04-24 11:07:57.000000000 +0100
@@ -81,6 +81,8 @@
# The O= assignment takes precedence over the KBUILD_OUTPUT environment
# variable.
+GCOV_FLAGS = -fprofile-arcs -ftest-coverage
+
# KBUILD_SRC is set on invocation of make in OBJ directory
# KBUILD_SRC is not intended to be used by the regular user (for now)
@@ -331,8 +333,8 @@
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
-LINUXINCLUDE := -Iinclude \
- $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
+LINUXINCLUDE := -I$(objtree)/include -I$(srctree) -I$(objtree)\
+ $(if $(KBUILD_SRC),-I$(objtree)/include2 -I$(srctree)/include) \
-include include/linux/autoconf.h
CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE)
@@ -354,6 +356,8 @@
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
+export CFLAGS_NOGCOV GCOV_FLAGS
+
# When compiling out-of-tree modules, put MODVERDIR in the module
# tree rather than in the kernel tree. The kernel tree might
@@ -917,6 +921,11 @@
# ---------------------------------------------------------------------------
# Modules
+CFLAGS_NOGCOV := $(CFLAGS)
+ifdef CONFIG_GCOV_ALL
+CFLAGS += $(GCOV_FLAGS)
+endif
+
ifdef CONFIG_MODULES
# By default, build modules as well
@@ -1018,6 +1027,8 @@
$(call cmd,rmfiles)
@find . $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
+ -o -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
+ -o -name '*.gcno' -o -name '*.gcda' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-type f -print | xargs rm -f
diff -urN linux-source-2.6.16.orig/scripts/Makefile.build linux-source-2.6.16/scripts/Makefile.build
--- linux-source-2.6.16.orig/scripts/Makefile.build 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/scripts/Makefile.build 2006-04-24 10:58:01.000000000 +0100
@@ -146,7 +146,8 @@
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
ifndef CONFIG_MODVERSIONS
-cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
+cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ \
+ $(if $(filter-out /%,$<),$(srctree)/$<,$<)
else
# When module versioning is enabled the following steps are executed:
@@ -161,7 +162,8 @@
# replace the unresolved symbols __crc_exported_symbol with
# the actual value of the checksum generated by genksyms
-cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
+cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) \
+ $(if $(filter-out /%,$<),$(srctree)/$<,$<)
cmd_modversions = \
if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
$(CPP) -D__GENKSYMS__ $(c_flags) $< \
diff -urN linux-source-2.6.16.orig/scripts/Makefile.lib linux-source-2.6.16/scripts/Makefile.lib
--- linux-source-2.6.16.orig/scripts/Makefile.lib 2006-03-20 05:53:29.000000000 +0000
+++ linux-source-2.6.16/scripts/Makefile.lib 2006-04-24 10:58:01.000000000 +0100
@@ -93,14 +93,15 @@
# If building the kernel in a separate objtree expand all occurrences
# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
-ifeq ($(KBUILD_SRC),)
+ifeq ($(KBUILD_SRC)$(CONFIG_GCOV_PROFILE),)
__c_flags = $(_c_flags)
__a_flags = $(_a_flags)
__cpp_flags = $(_cpp_flags)
else
# Prefix -I with $(srctree) if it is not an absolute path
-addtree = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
+addtree = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1))
+addtree2 = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(objtree)/%,$(1)),$(1))
# Find all -I options and call addtree
flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
@@ -108,7 +109,7 @@
# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
# and locates generated .h files
# FIXME: Replace both with specific CFLAGS* statements in the makefiles
-__c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags)
+__c_flags = $(call addtree,-I$(obj)) $(call addtree2,-I$(obj)) $(call flags,_c_flags)
__a_flags = $(call flags,_a_flags)
__cpp_flags = $(call flags,_cpp_flags)
endif
|