| 1 |
.\" $Id: ccom.1,v 1.33 2018/12/15 09:12:14 plunky Exp $ |
| 2 |
.\" |
| 3 |
.\" Copyright (c) 2007 Jeremy C. Reed <[email protected]> |
| 4 |
.\" |
| 5 |
.\" Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
.\" purpose with or without fee is hereby granted, provided that the above |
| 7 |
.\" copyright notice and this permission notice appear in all copies. |
| 8 |
.\" |
| 9 |
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR AND CONTRIBUTORS DISCLAIM |
| 10 |
.\" ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 |
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHOR AND |
| 12 |
.\" CONTRIBUTORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 |
.\" DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 |
.\" PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS |
| 15 |
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF |
| 16 |
.\" THIS SOFTWARE. |
| 17 |
.\" |
| 18 |
.Dd March 22, 2012 |
| 19 |
.Dt CCOM 1 |
| 20 |
.Os |
| 21 |
.Sh NAME |
| 22 |
.Nm ccom |
| 23 |
.Nd C compiler |
| 24 |
.Sh SYNOPSIS |
| 25 |
.Nm |
| 26 |
.Op Fl gkpsv |
| 27 |
.Op Fl f Ar features |
| 28 |
.Op Fl m Ar options |
| 29 |
.Op Fl W Ar warnings |
| 30 |
.Op Fl X Ar flags |
| 31 |
.Op Fl x Ar settings |
| 32 |
.Op Fl Z Ar flags |
| 33 |
.Op infile |
| 34 |
.Op outfile |
| 35 |
.Sh DESCRIPTION |
| 36 |
The |
| 37 |
.Nm |
| 38 |
utility provides a C compiler. |
| 39 |
The frontend is usually |
| 40 |
.Xr pcc 1 . |
| 41 |
It is |
| 42 |
.Em not |
| 43 |
intended to be run directly. |
| 44 |
.Nm |
| 45 |
reads the C source from |
| 46 |
.Ar infile |
| 47 |
or standard input and writes the assembler source |
| 48 |
to |
| 49 |
.Ar outfile |
| 50 |
or to standard output. |
| 51 |
.Pp |
| 52 |
The options are as follows: |
| 53 |
.Bl -tag -width Ds |
| 54 |
.It Fl f Ar feature |
| 55 |
Enable language features. |
| 56 |
Multiple |
| 57 |
.Fl f |
| 58 |
options can be given, the following features are supported: |
| 59 |
.Bl -tag -width Ds |
| 60 |
.It Sy stack-protector |
| 61 |
Enable stack smashing protection. |
| 62 |
Currently the same as |
| 63 |
.Sy stack-protector-all . |
| 64 |
.It Sy stack-protector-all |
| 65 |
Enable stack smashing protection for all functions. |
| 66 |
.It Sy pack-struct Ns Oo = Ns Ar n Oc |
| 67 |
Specify maximum alignment for structure members, similar to a #pragma pack |
| 68 |
statement at the start of the file. |
| 69 |
If no value is given, the default is 1. |
| 70 |
.It Sy freestanding |
| 71 |
Emit code for a freestanding environment. |
| 72 |
Currently not implemented. |
| 73 |
.El |
| 74 |
.It Fl g |
| 75 |
Include debugging information in the output code for use by |
| 76 |
symbolic and source-level debuggers. |
| 77 |
Currently this uses the |
| 78 |
.Sy stabs |
| 79 |
format, encoding information in |
| 80 |
.Em s Ns ymbol Em tab Ns le entrie Ns Em s. |
| 81 |
.It Fl k |
| 82 |
Generate PIC code. |
| 83 |
.It Fl m Ar option |
| 84 |
Target-specific options, used in machine-dependent code. |
| 85 |
Multiple |
| 86 |
.Fl m |
| 87 |
options can be given, the following options are supported: |
| 88 |
.Bl -tag -width PowerPC |
| 89 |
.It AMD64 |
| 90 |
.It ARM |
| 91 |
.Sy little-endian , |
| 92 |
.Sy big-endian , |
| 93 |
.Sy fpe=fpa , |
| 94 |
.Sy fpe=vpf , |
| 95 |
.Sy soft-float , |
| 96 |
.Sy arch=armv1 , |
| 97 |
.Sy arch=armv2 , |
| 98 |
.Sy arch=armv2a , |
| 99 |
.Sy arch=armv3 , |
| 100 |
.Sy arch=armv4 , |
| 101 |
.Sy arch=armv4t , |
| 102 |
.Sy arch=armv4tej , |
| 103 |
.Sy arch=armv5 , |
| 104 |
.Sy arch=armv5te , |
| 105 |
.Sy arch=armv5tej , |
| 106 |
.Sy arch=armv6 , |
| 107 |
.Sy arch=armv6t2 , |
| 108 |
.Sy arch=armv6kz , |
| 109 |
.Sy arch=armv6k No \*(Am |
| 110 |
.Sy arch=armv7 . |
| 111 |
.It HPPA |
| 112 |
.It i386 |
| 113 |
.It M16C |
| 114 |
.It MIPS |
| 115 |
.Sy little-endian No \*(Am |
| 116 |
.Sy big-endian . |
| 117 |
.It NOVA |
| 118 |
.It PDP-10 |
| 119 |
.It PDP-11 |
| 120 |
.It PowerPC |
| 121 |
.Sy little-endian , |
| 122 |
.Sy big-endian , |
| 123 |
.Sy soft-float No \*(Am |
| 124 |
.Sy hard-float . |
| 125 |
.It Sparc64 |
| 126 |
.It VAX |
| 127 |
.El |
| 128 |
.It Fl p |
| 129 |
Generate profiling code. |
| 130 |
.It Fl s |
| 131 |
Print statistics to standard error when complete. |
| 132 |
This includes: |
| 133 |
name table entries, name string size, permanent allocated memory, |
| 134 |
temporary allocated memory, lost memory, argument list unions, |
| 135 |
dimension/function unions, struct/union/enum blocks, inline node count, |
| 136 |
inline control blocks, and permanent symtab entries. |
| 137 |
.\" TODO: explain units for above? |
| 138 |
.It Fl v |
| 139 |
Display version. |
| 140 |
.It Fl W Ar warning |
| 141 |
Do some basic checks and emit warnings about possible coding problems. |
| 142 |
Multiple |
| 143 |
.Fl W |
| 144 |
options can be given, the following warnings are supported: |
| 145 |
.Bl -tag -width Ds |
| 146 |
.It Sy error Ns Oo = Ns Ar warning Oc |
| 147 |
Enable |
| 148 |
.Ar warning , |
| 149 |
and treat it as an error condition. |
| 150 |
If a specific warning is not given, producing any warning will cause an error. |
| 151 |
.It Sy attributes |
| 152 |
Warn when unsupported attributes are used. |
| 153 |
This warning is enabled by default. |
| 154 |
.It Sy deprecated-declarations |
| 155 |
Report whenever a symbol marked with the |
| 156 |
.Sq deprecated |
| 157 |
attribute is used. |
| 158 |
This warning is enabled by default. |
| 159 |
.It Sy implicit-function-declaration |
| 160 |
(TODO) Require explicit prototypes for all called functions. |
| 161 |
.It Sy implicit-int |
| 162 |
(TODO) Warn when a function declaration lacks a type. |
| 163 |
.It Sy missing-prototypes |
| 164 |
Require explicit prototypes for all global function definitions. |
| 165 |
.It Sy pointer-sign |
| 166 |
Warn when pointer operations are done with mismatched signed and unsigned values. |
| 167 |
.It Sy sign-compare |
| 168 |
(TODO) Warn about comparisons between signed and unsigned values. |
| 169 |
.It Sy strict-prototypes |
| 170 |
(TODO) Require that function prototypes are strictly C99. |
| 171 |
.It Sy shadow |
| 172 |
Report when a local variable shadows something from a higher scope. |
| 173 |
.It Sy truncate |
| 174 |
Report when integer values may be implicitly truncated to fit a smaller type. |
| 175 |
.It Sy uninitialized |
| 176 |
A variable is read before being written. |
| 177 |
.It Sy unknown-pragmas |
| 178 |
Report unhandled pragma statements. |
| 179 |
.It Sy unreachable-code |
| 180 |
Report statements that cannot be executed. |
| 181 |
.El |
| 182 |
.Pp |
| 183 |
Any of the above may be prefixed with |
| 184 |
.Dq no- |
| 185 |
in order to disable the effect. |
| 186 |
.\" |
| 187 |
.It Fl X Ar flags |
| 188 |
C specific debugging where |
| 189 |
.Ar flags |
| 190 |
is one or more of the following: |
| 191 |
.Pp |
| 192 |
.Bl -tag -compact -width Ds |
| 193 |
.It Sy b |
| 194 |
Building of parse trees |
| 195 |
.It Sy d |
| 196 |
Declarations (using multiple |
| 197 |
.Sy d |
| 198 |
flags gives more output) |
| 199 |
.It Sy e |
| 200 |
Pass1 trees at exit |
| 201 |
.It Sy i |
| 202 |
Initializations |
| 203 |
.It Sy n |
| 204 |
Memory allocations |
| 205 |
.It Sy o |
| 206 |
Turn off optimisations |
| 207 |
.It Sy p |
| 208 |
Prototypes |
| 209 |
.It Sy s |
| 210 |
Inlining |
| 211 |
.It Sy t |
| 212 |
Type conversions |
| 213 |
.It Sy x |
| 214 |
Target-specific flag, used in machine-dependent code |
| 215 |
.El |
| 216 |
.\" |
| 217 |
.It Fl x Ar setting |
| 218 |
Enable |
| 219 |
.Ar setting |
| 220 |
in the compiler. |
| 221 |
Multiple |
| 222 |
.Fl x |
| 223 |
options can be given, the following settings are supported: |
| 224 |
.Bl -tag -width Ds |
| 225 |
.It Sy ccp |
| 226 |
Apply sparse conditional constant propagation techniques for optimization. |
| 227 |
Currently not implemented. |
| 228 |
.It Sy dce |
| 229 |
Do dead code elimination. |
| 230 |
.It Sy deljumps |
| 231 |
Delete redundant jumps and dead code. |
| 232 |
.It Sy gnu89 |
| 233 |
.It Sy gnu99 |
| 234 |
Use GNU C semantics rather than C99 for some things. |
| 235 |
Currently only inline. |
| 236 |
.It Sy inline |
| 237 |
Replace calls to functions marked with an inline specifier with a copy |
| 238 |
of the actual function. |
| 239 |
.It Sy ssa |
| 240 |
Convert statements into static single assignment form for optimization. |
| 241 |
Not yet finished. |
| 242 |
.It Sy tailcall |
| 243 |
Enable optimization of tail-recursion functions. |
| 244 |
Currently not implemented. |
| 245 |
.It Sy temps |
| 246 |
Locate automatic variables into registers where possible, for further |
| 247 |
optimization by the register allocator. |
| 248 |
.It Sy uchar |
| 249 |
Treat character constants as unsigned values. |
| 250 |
.El |
| 251 |
.\" |
| 252 |
.It Fl Z Ar flags |
| 253 |
Code generator (pass2) specific debugging where |
| 254 |
.Ar flags |
| 255 |
is one or more of the following: |
| 256 |
.Pp |
| 257 |
.Bl -tag -compact -width Ds |
| 258 |
.It Sy b |
| 259 |
Basic block and SSA building |
| 260 |
.It Sy c |
| 261 |
Code printout |
| 262 |
.It Sy e |
| 263 |
Trees when entering pass2 |
| 264 |
.It Sy f |
| 265 |
Instruction matcher, may provide much output |
| 266 |
.It Sy g |
| 267 |
Print flow graphs |
| 268 |
.It Sy n |
| 269 |
Memory allocation |
| 270 |
.It Sy o |
| 271 |
Instruction generator |
| 272 |
.It Sy r |
| 273 |
Register allocator |
| 274 |
.It Sy s |
| 275 |
Shape matching in instruction generator |
| 276 |
.It Sy t |
| 277 |
Type matching in instruction generator |
| 278 |
.It Sy u |
| 279 |
Sethi-Ullman computations |
| 280 |
.It Sy x |
| 281 |
Target-specific flag, used in machine-dependent code |
| 282 |
.El |
| 283 |
.El |
| 284 |
.Sh PRAGMAS |
| 285 |
Input lines starting with a |
| 286 |
.Dq #pragma |
| 287 |
directive can be used to modify behaviour of |
| 288 |
.Nm |
| 289 |
during compilation. |
| 290 |
All tokens up to the first unescaped newline are considered part |
| 291 |
of the pragma command, with the following operations being recognized: |
| 292 |
.Bl -tag -width Ds |
| 293 |
.It Sy STDC |
| 294 |
Standard C99 operator follows. |
| 295 |
Currently no C99 operations are implemented, and any directives starting |
| 296 |
with this token will be silently ignored. |
| 297 |
.It Sy GCC diagnostic Ar effect Qq Ar option |
| 298 |
GNU C compatibility. |
| 299 |
Alter the effects of compiler diagnostics. |
| 300 |
The required |
| 301 |
.Ar effect |
| 302 |
should be stated as |
| 303 |
.Sy warning , |
| 304 |
.Sy error |
| 305 |
or |
| 306 |
.Sy ignored , |
| 307 |
followed by the compiler diagnostic |
| 308 |
.Ar option |
| 309 |
in double quotes. |
| 310 |
For example, to force unknown pragmas to always generate an error, |
| 311 |
a standard header might include |
| 312 |
.Bd -literal -offset 2n |
| 313 |
#pragma GCC diagnostic error "-Wunknown-pragmas" |
| 314 |
.Ed |
| 315 |
.It Sy GCC poison Ar identifier ... |
| 316 |
GNU C compatibility. |
| 317 |
Cause an error if any of the following |
| 318 |
.Ar identifier Ns s |
| 319 |
subsequently appear in the code |
| 320 |
.Pq but not in any macro expansions . |
| 321 |
Currently not implemented. |
| 322 |
.It Sy GCC system_header |
| 323 |
GNU C compatibility. |
| 324 |
Currently not implemented. |
| 325 |
.It Sy GCC visibility |
| 326 |
GNU C compatibility. |
| 327 |
Currently not implemented. |
| 328 |
.It Sy pack Ns Pq Op Ar n |
| 329 |
Set the default maximum alignment for structures and unions, such that |
| 330 |
members will have their natural alignment requirements clamped at this |
| 331 |
value and may be stored misaligned. |
| 332 |
If |
| 333 |
.Ar n |
| 334 |
is not given, the alignment is reset to the target default. |
| 335 |
.It Sy pack Ns Pq Sy push Ns Op , Ar n |
| 336 |
Push the current pack setting onto an internal stack then, if |
| 337 |
.Ar n |
| 338 |
is given, change the default alignment for structures and unions. |
| 339 |
Currently not implemented. |
| 340 |
.It Sy pack Ns Pq Sy pop |
| 341 |
Change the pack setting to the most recently pushed value, and remove |
| 342 |
that setting from the stack. |
| 343 |
Currently not implemented. |
| 344 |
.It Sy packed Op Ar n |
| 345 |
Set the maximum alignment for the structure or union defined |
| 346 |
in the current statement. |
| 347 |
If |
| 348 |
.Ar n |
| 349 |
is not given, the default value of 1 is used. |
| 350 |
.Pq Currently this works except Ar n is not used |
| 351 |
.It Sy aligned Op Ar n |
| 352 |
Set the minimum alignment for the structure or union defined |
| 353 |
in the current statement. |
| 354 |
.It Sy rename Ar name |
| 355 |
Provide an alternative |
| 356 |
.Ar name |
| 357 |
which will be used to reference the object declared in the current statement. |
| 358 |
.It Sy weak Ar name Ns Op = Ns Ar alias |
| 359 |
Mark |
| 360 |
.Ar name |
| 361 |
as a weak rather than a global symbol, to allow its definition to be |
| 362 |
overridden at link time. |
| 363 |
If an |
| 364 |
.Ar alias |
| 365 |
is given, this will be used as the default value of |
| 366 |
.Ar name . |
| 367 |
.It Sy ident |
| 368 |
Currently not implemented. |
| 369 |
.El |
| 370 |
.Lp |
| 371 |
and the following target-specific operations are handled by |
| 372 |
machine-dependent code: |
| 373 |
.Bl -tag -width Ds |
| 374 |
.It Sy tls |
| 375 |
For AMD64 and i386 targets, the variable declared in the current statement |
| 376 |
will be referenced via the |
| 377 |
.Dq thread-local storage |
| 378 |
mechanism. |
| 379 |
.It Sy init |
| 380 |
For AMD64, ARM, HPPA, i386, MIPS and PowerPC targets, when the current statement is a |
| 381 |
function declaration, generate a reference in the |
| 382 |
.Sy .ctors |
| 383 |
section, enabling library code to call the function prior to entering |
| 384 |
.Fn main . |
| 385 |
.It Sy fini |
| 386 |
For AMD64, ARM, HPPA, i386, MIPS and PowerPC targets, when the current statement is a |
| 387 |
function declaration, generate a reference in the |
| 388 |
.Sy .dtors |
| 389 |
section, enabling library code to call the function when |
| 390 |
.Fn main |
| 391 |
returns or the |
| 392 |
.Fn exit |
| 393 |
function is called. |
| 394 |
.It Sy section Ar name |
| 395 |
For AMD64, ARM, HPPA and i386 targets, place the subsequent code in the named |
| 396 |
section. |
| 397 |
.Pq This is currently broken . |
| 398 |
.It Sy alias Ar name |
| 399 |
For AMD64, HPPA and i386 targets, emit assembler instructions providing an |
| 400 |
alias for the symbol defined by the current statement. |
| 401 |
.It Sy stdcall |
| 402 |
For i386 targets, enable |
| 403 |
.Dq stdcall |
| 404 |
semantics during code generation, where function arguments are passed on |
| 405 |
the stack in right-to-left order, and the callee is responsible for adjusting |
| 406 |
the stack pointer before returning. |
| 407 |
Any function result is passed in the EAX register. |
| 408 |
On win32, the function name is postfixed with an |
| 409 |
.Dq @ |
| 410 |
and the size of the stack adjustment. |
| 411 |
.It Sy cdecl |
| 412 |
For i386 targets, enable |
| 413 |
.Dq cdecl |
| 414 |
semantics during code generation, where function arguments are passed on |
| 415 |
the stack in right-to-left order, and the caller is responsible for cleaning |
| 416 |
up the stack after the function returns. |
| 417 |
Any function result is passed in the EAX register. |
| 418 |
This is the default. |
| 419 |
.It Sy fastcall |
| 420 |
For i386-win32 targets, enable |
| 421 |
.Dq fastcall |
| 422 |
semantics during code generation. |
| 423 |
.Po |
| 424 |
Currently this is equivalent to |
| 425 |
.Sy stdcall , |
| 426 |
which is likely wrong |
| 427 |
.Pc . |
| 428 |
.It Sy dllimport |
| 429 |
For i386-win32 targets, references to the external symbol defined by |
| 430 |
the current statement will be made via indirect access through a |
| 431 |
location identified by the symbol name prefixed with |
| 432 |
.Dq __imp_ . |
| 433 |
.It Sy dllexport |
| 434 |
For i386-win32 targets, the external symbol declared by the current |
| 435 |
statement will be exported as an indirect reference to be |
| 436 |
accessed with |
| 437 |
.Sy dllimport . |
| 438 |
The global locator will be the symbol name prefixed with |
| 439 |
.Dq __imp_ . |
| 440 |
Currently this is not completely implemented. |
| 441 |
.El |
| 442 |
.Pp |
| 443 |
Any unknown |
| 444 |
.Dq #pragma |
| 445 |
directives will be ignored unless the |
| 446 |
.Fl Wunknown-pragmas |
| 447 |
diagnostic is in effect. |
| 448 |
.Sh SEE ALSO |
| 449 |
.Xr as 1 , |
| 450 |
.Xr cpp 1 , |
| 451 |
.Xr pcc 1 |
| 452 |
.Sh HISTORY |
| 453 |
The |
| 454 |
.Nm |
| 455 |
compiler is based on the original Portable C Compiler by |
| 456 |
.An "S. C. Johnson" , |
| 457 |
written in the late 70's. |
| 458 |
Even though much of the compiler has been rewritten |
| 459 |
.Pq about 50% of the frontend code and 80% of the backend , |
| 460 |
some of the basics still remain. |
| 461 |
Most is written by |
| 462 |
.An "Anders Magnusson" , |
| 463 |
with the exception of the data-flow analysis part and |
| 464 |
the SSA conversion code which is written by |
| 465 |
.An "Peter A Jonsson" , |
| 466 |
and the Mips port that were written as part of a project |
| 467 |
by undergraduate students at Lulea University of Technology. |
| 468 |
.Pp |
| 469 |
This product includes software developed or owned by Caldera |
| 470 |
International, Inc. |