README 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. Quick start documentation for the header file utilities.
  2. This isn't a full breakdown of the tools, just they typical use scenarios.
  3. - Each tool accepts -h to show it's usage. Usually no parameters will also
  4. trigger the help message. Help may specify additional functionality to what is
  5. listed here.
  6. - For all tools, option format for specifying filenames must have no spaces
  7. between the option and filename.
  8. ie.: tool -lfilename.h target.h
  9. - Many of the tools are required to be run from the core gcc source directory
  10. containing coretypes.h. Typically that is in gcc/gcc from a source checkout.
  11. For these tools to work on files not in this directory, their path needs to be
  12. specified on the command line.
  13. ie.: tool c/c-decl.cc lto/lto.cc
  14. - options can be intermixed with filenames anywhere on the command line
  15. ie. tool ssa.h rtl.h -a is equivalent to
  16. tool ssa.h -a rtl.h
  17. gcc-order-headers
  18. -----------------
  19. This will reorder any primary backend headers files known to the tool into a
  20. canonical order which will resolve any hidden dependencies they may have.
  21. Any unknown headers will simply be placed after the recognized files, and
  22. retain the same relative ordering they had.
  23. This tool must be run in the core gcc source directory.
  24. Simply execute the command listing any files you wish to process on the
  25. command line.
  26. Any files which are changed are output, and the original is saved with a
  27. .bak extention.
  28. ex.: gcc-order-headers tree-ssa.cc c/c-decl.cc
  29. -s will list all of the known headers in their canonical order. It does not
  30. show which of those headers include other headers, just the final canonical
  31. ordering.
  32. if any header files are included within a conditional code block, the tool
  33. will issue a message and not change the file. When this happens, you can
  34. manually inspect the file to determine if reordering it is actually OK. Then
  35. rerun the command with the -i option. This will ignore the conditional error
  36. condition and perform the re-ordering anyway.
  37. If any #include line has the beginning of a multi-line comment, it will also
  38. refuse to process the file until that is resolved by terminating the comment
  39. on the same line, or removing it.
  40. show-headers
  41. ------------
  42. This will show the include structure for any given file. Each level of nesting
  43. is indented, and when any duplicate headers are seen, they have their
  44. duplicate number shown
  45. -i may be used to specify additional search directories for headers to parse.
  46. -s specifies headers to look for and emphasize in the output.
  47. This tool must be run in the core gcc source directory.
  48. ex.: show-headers -sansidecl.h tree-ssa.cc
  49. tree-ssa.cc
  50. config.h
  51. auto-host.h
  52. ansidecl.h (1) <<-------
  53. system.h
  54. safe-ctype.h
  55. filenames.h
  56. hashtab.h (1)
  57. ansidecl.h (2) <<-------
  58. libiberty.h
  59. ansidecl.h (3) <<-------
  60. hwint.h
  61. coretypes.h
  62. machmode.h (1)
  63. insn-modes.h (1)
  64. signop.h
  65. <...>
  66. count-headers
  67. -------------
  68. simply count all the headers found in the specified files. A summary is
  69. printed showing occurrences from high to low.
  70. ex.: count-headers tree*.c
  71. 86 : coretypes.h
  72. 86 : config.h
  73. 86 : system.h
  74. 86 : tree.h
  75. 82 : backend.h
  76. 80 : gimple.h
  77. 72 : gimple-iterator.h
  78. 70 : ssa.h
  79. 68 : fold-const.h
  80. <...>
  81. included-by
  82. -----------
  83. This tool will search all the .c,.cc and .h files and output a list of files
  84. which include the specified header(s).
  85. A 4 level deep 'find' of all source files is performed from the current
  86. directory and each of those is inspected for a #include of the specified
  87. headers. So expect a little bit of slowness.
  88. -i limits the search to only other header files.
  89. -c limits the search to .c and .cc files.
  90. -a shows only source files which include all specified headers.
  91. -f allows you to specify a file which contains a list of source files to
  92. check rather than performing the much slower find command.
  93. ex: included-by tree-vectorizer.h
  94. config/aarch64/aarch64.cc
  95. config/i386/i386.cc
  96. config/rs6000/rs6000.cc
  97. tree-loop-distribution.cc
  98. tree-parloops.cc
  99. tree-ssa-loop-ivopts.cc
  100. tree-ssa-loop.cc
  101. replace-header
  102. --------------
  103. This tool simply replaces a single header file with one or more other headers.
  104. -r specifies the include to replace, and one or more -f options specify the
  105. replacement headers, in the order they occur.
  106. This is commonly used in conjunction with 'included-by' to change all
  107. occurrences of a header file to something else, or to insert new headers
  108. before or after.
  109. ex: to insert #include "before.h" before every occurence of tree.h in all
  110. .c and .cc source files:
  111. replace-header -rtree.h -fbefore.h -ftree.h `included-by -c tree.h`
  112. reduce-headers
  113. --------------
  114. This tool removes any header files which are not needed from a source file.
  115. This tool must be run for the core gcc source directory, and requires either
  116. a native build and sometimes target builds, depending on what you are trying
  117. to reduce.
  118. it is good practice to run 'gcc-order-headers' on a source file before trying
  119. to reduce it. This removes duplicates and performs some simplifications
  120. which reduce the chances of the reduction tool missing things.
  121. start with a completely bootstrapped native compiler.
  122. Any desired target builds should be built in one directory using a modified
  123. config-list.mk file which does not delete the build directory when it is done.
  124. any target directories which do not successfully complete a 'make all-gcc'
  125. may cause the tool to not reduce anything.
  126. (todo - provide a config-list.mk that leaves successful target builds, but
  127. deletes ones which do not compile)
  128. The tool will examine all the target builds to determine which targets build
  129. the file, and include those targets in the testing.
  130. The tool will analyze a source file and attempt to remove each non-conditional
  131. header from last to first in the file.:
  132. It will first attempt to build the native all-gcc target.
  133. If that succeeds, it will attempt to build any target build .o files
  134. If that succeeds, it will check to see if there are any conditional
  135. compilation dependencies between this header file and the source file or
  136. any header which have already been determined as non-removable.
  137. If all these tests are passed, the header file is determined to be removable
  138. and is removed from the source file.
  139. This continues until all headers have been checked.
  140. At this point, a bootstrap is attempted in the native build, and if that
  141. passes the file is considered reduced.
  142. Any files from the config subdirectory require target builds to be present
  143. in order to proceed.
  144. A small subset of targets has been determined to provide excellent coverage,
  145. at least as of Aug 31/15 . They were found by reducing all the files
  146. contained in libbackend.a oer a full set of targets(207). All conditions
  147. which disallowed removal of a header file were triggered by one or more of
  148. these targets. They are also known to the tool. When building targets it
  149. will check those targets before the rest.
  150. This coverage can be achieved by building config-list.mk with :
  151. LIST="aarch64-linux-gnu arm-netbsdelf c6x-elf epiphany-elf hppa2.0-hpux10.1 i686-mingw32crt i686-pc-msdosdjgpp mipsel-elf powerpc-eabisimaltivec rs6000-ibm-aix5.1.0 sh-superh-elf sparc64-elf"
  152. -b specifies the native bootstrapped build root directory
  153. -t specifies a target build root directory that config-list.mk was run from
  154. -f is used to limit the headers for consideration.
  155. example:
  156. mkdir gcc // checkout gcc in subdir gcc
  157. mdsir build // boostrap gcc in subdir build
  158. mkdir target // create target directory and run config-list.mk
  159. cd gcc/gcc
  160. reduce-headers -b../../build -t../../targets -falias.h -fexpr.h tree*.c (1)
  161. # This will attempt to remove only alias.h and expr.h from tree*.c
  162. reduce-headers -b../../build -t../../targets tree-ssa-live.cc
  163. # This will attempt to remove all header files from tree-ssa-live.cc
  164. the tool will generate a number of log files:
  165. reduce-headers.log : All compilation failures from attempted reductions.
  166. reduce-headers.sum : One line summary of what happened to each source file.
  167. (All the remaining logs are appended to, so if the tool is run multiple times
  168. these files are just added to. You must physically remove them yourself in
  169. order to reset the logs.)
  170. reduce-headers-kept.log: List of all the successful compiles that were
  171. ignored because of conditional macro dependencies
  172. and why it thinks that is the case
  173. $src.c.log : for each failed header removal, the compilation
  174. messages as to why it failed.
  175. $header.h.log: The same log is put into the relevant header log as well.
  176. a sample output from ira.cc.log:
  177. Compilation failed:
  178. for shrink-wrap.h:
  179. ============================================
  180. /gcc/2015-09-09/gcc/gcc/ira.cc: In function ‘bool split_live_ranges_for_shrink_wrap()’:
  181. /gcc/2015-09-09/gcc/gcc/ira.cc:4839:8: error: ‘SHRINK_WRAPPING_ENABLED’ was not declared in this scope
  182. if (!SHRINK_WRAPPING_ENABLED)
  183. ^
  184. make: *** [ira.o] Error 1
  185. the same message would be put into shrink-wrap.h.log.
  186. graph-header-logs
  187. -----------------
  188. This tool will parse all the messages from the .C files, looking for failures
  189. that show up in other headers... meaning there is a compilation dependency
  190. between the 2 header files.
  191. The tool will aggregate all these and generate a graph of the dependencies
  192. exposed during compilation. Red lines indicate dependencies that are
  193. present because a header file physically includes another file. Black lines
  194. represent data dependencies causing compilation failures if the header is
  195. not present.
  196. ex.: graph-header-logs *.c.log
  197. graph-include-web
  198. -----------------
  199. This tool can be used to visualize the include structure in files. It is
  200. rapidly turned useless if you specify too many things, but it can be
  201. useful for finding cycles and redundancies, or simply to see what a single
  202. file looks like.
  203. ex.: graph-include-web tree.cc