Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 5 | clang - the Clang C and Objective-C compiler |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 6 | |
| 7 | =head1 SYNOPSIS |
| 8 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 9 | B<clang> [B<-c>|B<-S>|B<-E>] B<-std=>I<standard> B<-g> |
| 10 | [B<-O0>|B<-O1>|B<-O2>|B<-Os>|B<-O3>|B<-O4>] |
| 11 | B<-W>I<warnings...> B<-pedantic> |
| 12 | B<-I>I<dir...> B<-L>I<dir...> |
| 13 | B<-D>I<macro[=defn]> |
| 14 | B<-f>I<feature-option...> |
| 15 | B<-m>I<machine-option...> |
| 16 | B<-o> I<output-file> |
| 17 | I<input-filenames> |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 18 | |
| 19 | =head1 DESCRIPTION |
| 20 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 21 | B<clang> is a C and Objective-C compiler which encompasses preprocessing, |
| 22 | parsing, optimization, code generation, assembly, and linking. Depending on |
| 23 | which high-level mode setting is passed, Clang will stop before doing a full |
| 24 | link. While Clang is highly integrated, it is important to understand the |
| 25 | stages of compilation, to understand how to invoke it. These stages are: |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 26 | |
| 27 | =over |
| 28 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 29 | =item B<Driver> |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 30 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 31 | The B<clang> executable is actually a small driver which controls the overall |
| 32 | execution of other tools such as the compiler, assembler and linker. Typically |
| 33 | you do not need to interact with the driver, but you transparently use it to run |
| 34 | the other tools. |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 35 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 36 | =item B<Preprocessing> |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 37 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 38 | This stage handles tokenization of the input source file, macro expansion, |
| 39 | #include expansion and handling of other preprocessor directives. The output of |
| 40 | this stage is typically called a ".i" (for C) or ".mi" (for Objective-C) file. |
| 41 | |
| 42 | =item B<Parsing and Semantic Analysis> |
| 43 | |
| 44 | This stage parses the input file, translating preprocessor tokens into a parse |
| 45 | tree. Once in the form of a parser tree, it applies semantic analysis to compute |
| 46 | types for expressions as well and determine whether the code is well formed. This |
| 47 | stage is responsible for generating most of the compiler warnings as well as |
| 48 | parse errors. The output of this stage is an "Abstract Syntax Tree" (AST). |
| 49 | |
| 50 | =item B<Code Generation and Optimization> |
| 51 | |
| 52 | This stage translates an AST into low-level intermediate code or machine code |
| 53 | (depending on the optimization level). This phase is responsible for optimizing |
| 54 | the generated code and handling target-specfic code generation. The output of |
| 55 | this stage is typically called a ".s" file. |
| 56 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 57 | =item B<Assembler> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 58 | |
| 59 | This stage runs the target assembler to translate the output of the compiler |
| 60 | into a target object file. The output of this stage is typically called a ".o" |
| 61 | file. |
| 62 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 63 | =item B<Linker> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 64 | |
| 65 | This stage runs the target linker to merge multiple object files into an |
| 66 | executable or dynamic library. The output of this stage is typically called an |
| 67 | "a.out", ".dylib" or ".so" file. |
| 68 | |
| 69 | =back |
| 70 | |
| 71 | The Clang compiler supports a large number of options to control each of these |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 72 | stages. In addition to compilation of code, Clang also supports other tools. |
| 73 | |
| 74 | B<Clang Static Analyzer> |
| 75 | |
| 76 | The Clang Static Analyzer is a tool that scans source code to try to find bugs |
| 77 | though code analysis. This tool uses many parts of Clang and is built into the |
| 78 | same driver. |
| 79 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 80 | |
| 81 | =head1 OPTIONS |
| 82 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 83 | =head2 Stage Selection Options |
| 84 | |
| 85 | =over |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 86 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 87 | =item B<-E> |
| 88 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 89 | Run the preprocessor stage. |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 90 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 91 | =item B<-fsyntax-only> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 92 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 93 | Run the preprocessor, parser and type checking stages. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 94 | |
| 95 | =item B<-emit-llvm> |
| 96 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 97 | Run the preprocessor, parser, type checking stages, LLVM generation and |
| 98 | optimization stages. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 100 | =item B<-S> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 101 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 102 | Run all of the above, plus target-specific code generation, producing an |
| 103 | assembly file. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 105 | =item B<-c> |
| 106 | |
| 107 | Run all of the above, plus the assembler, generating a target ".o" object file. |
| 108 | |
| 109 | =item B<no stage selection option> |
| 110 | |
| 111 | If no stage selection option is specified, all stages above are run, and the |
| 112 | linker is run to combine the results into an executable or shared library. |
| 113 | |
| 114 | =item B<--analyze> |
| 115 | |
| 116 | Run the Clang Static Analyzer. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 117 | |
| 118 | =back |
| 119 | |
| 120 | |
| 121 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 122 | =head2 Driver Options |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 123 | |
| 124 | =over |
| 125 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 126 | =item B<-###> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 127 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 128 | Print the commands to run for this compilation. |
| 129 | |
| 130 | =item B<--help> |
| 131 | |
| 132 | Display available options. |
| 133 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 134 | =item B<-ObjC++> |
| 135 | |
| 136 | Treat source input files as Objective-C++ inputs. |
| 137 | |
| 138 | =item B<-ObjC> |
| 139 | |
| 140 | Treat source input files as Objective-C inputs. |
| 141 | |
| 142 | =item B<-Qunused-arguments> |
| 143 | |
| 144 | Don't emit warning for unused driver arguments. |
| 145 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 146 | =item B<-Wa,>I<args> |
| 147 | |
| 148 | Pass the comma separated arguments in I<args> to the assembler. |
| 149 | |
| 150 | =item B<-Wl,>I<args> |
| 151 | |
| 152 | Pass the comma separated arguments in I<args> to the linker. |
| 153 | |
| 154 | =item B<-Wp,>I<args> |
| 155 | |
| 156 | Pass the comma separated arguments in I<args> to the preprocessor. |
| 157 | |
| 158 | =item B<-Xanalyzer> I<arg> |
| 159 | |
| 160 | Pass I<arg> to the static analyzer. |
| 161 | |
| 162 | =item B<-Xassembler> I<arg> |
| 163 | |
| 164 | Pass I<arg> to the assembler. |
| 165 | |
| 166 | =item B<-Xclang> I<arg> |
| 167 | |
| 168 | Pass I<arg> to the clang compiler. |
| 169 | |
| 170 | =item B<-Xlinker> I<arg> |
| 171 | |
| 172 | Pass I<arg> to the linker. |
| 173 | |
| 174 | =item B<-Xpreprocessor> I<arg> |
| 175 | |
| 176 | Pass I<arg> to the preprocessor. |
| 177 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 178 | =item B<-o> I<file> |
| 179 | |
| 180 | Write output to I<file>. |
| 181 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 182 | =item B<-print-file-name>=I<file> |
| 183 | |
| 184 | Print the full library path of I<file>. |
| 185 | |
| 186 | =item B<-print-libgcc-file-name> |
| 187 | |
| 188 | Print the library path for "libgcc.a". |
| 189 | |
| 190 | =item B<-print-prog-name>=I<name> |
| 191 | |
| 192 | Print the full program path of I<name>. |
| 193 | |
| 194 | =item B<-print-search-dirs> |
| 195 | |
| 196 | Print the paths used for finding libraries and programs. |
| 197 | |
| 198 | =item B<-save-temps> |
| 199 | |
| 200 | Save intermediate compilation results. |
| 201 | |
| 202 | =item B<-time> |
| 203 | |
| 204 | Time individual commands. |
| 205 | |
| 206 | =item B<-v> |
| 207 | |
| 208 | Show commands to run and use verbose output. |
| 209 | |
| 210 | =item B<-x> I<language> |
| 211 | |
| 212 | Treat subsequent input files as having type I<language>. |
| 213 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 214 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 215 | =back |
| 216 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | =head2 Preprocessor Options |
| 222 | |
| 223 | =over |
| 224 | |
| 225 | =back |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | =head2 Parser and Semantic Analysis Options |
| 231 | |
| 232 | =over |
| 233 | |
| 234 | =back |
| 235 | |
| 236 | |
| 237 | |
| 238 | =head2 Code Generation and Optimization Options |
| 239 | |
| 240 | =over |
| 241 | |
| 242 | =back |
| 243 | |
| 244 | |
| 245 | =head2 Assembler Options |
| 246 | |
| 247 | =over |
| 248 | |
| 249 | =back |
| 250 | |
| 251 | |
| 252 | =head2 Linker Options |
| 253 | |
| 254 | =over |
| 255 | |
| 256 | =back |
| 257 | |
| 258 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 259 | =head1 ENVIRONMENT |
| 260 | |
Daniel Dunbar | e58c943 | 2009-05-06 19:18:09 +0000 | [diff] [blame^] | 261 | =over |
| 262 | |
| 263 | =item B<TMPDIR>, B<TEMP>, B<TMP> |
| 264 | |
| 265 | These environment variables are checked, in order, for the location to |
| 266 | write temporary files used during the compilation process. |
| 267 | |
| 268 | =item B<CPATH> |
| 269 | |
| 270 | If this environment variable is present, it is treated as a delimited |
| 271 | list of paths to be added to the default system include path list. The |
| 272 | delimiter is the platform dependent delimitor, as used in the I<PATH> |
| 273 | environment variable. |
| 274 | |
| 275 | Empty components in the environment variable are ignored. |
| 276 | |
| 277 | =item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>, |
| 278 | B<OBJCPLUS_INCLUDE_PATH> |
| 279 | |
| 280 | These environment variables specify additional paths, as for CPATH, |
| 281 | which are only used when processing the appropriate language. |
| 282 | |
| 283 | =item B<MACOSX_DEPLOYMENT_TARGET> (Apple only) |
| 284 | |
| 285 | If -mmacosx-version-min is unspecified, the default deployment target |
| 286 | is read from this environment variable. |
| 287 | |
| 288 | =back |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 289 | |
| 290 | =head1 BUGS |
| 291 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 292 | Clang currently does not have C++ support, and this manual page is incomplete. |
| 293 | To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should |
Daniel Dunbar | e58c943 | 2009-05-06 19:18:09 +0000 | [diff] [blame^] | 294 | include preprocessed source files (use the B<-E> option) and the full output of |
| 295 | the compiler, along with information to reproduce. |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 296 | |
| 297 | =head1 SEE ALSO |
| 298 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 299 | as(1), ld(1) |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 300 | |
| 301 | =head1 AUTHOR |
| 302 | |
| 303 | Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>). |
| 304 | |
| 305 | =cut |