kefir(1)

πŸ“¦
version 0.5.0 Β· 2 versions
, in alpine 3.24

πŸ¦‹ NAME πŸ¦‹

kefir β€” C17/C23 language compiler. This is the kefir(1) page from the General Commands Manual, bestie, and we're getting through it together. πŸ’–


🌈 SYNOPSIS 🌈

kefir [options] files... [-run [args...]]

πŸ’… DESCRIPTION πŸ’…

Okay so kefir command-line options follow the c99(1) compiler interface, and they extend it with some of the supported gcc(1) flags plus flags for special kefir features. Unknown command-line flags are ignored with a warning printed for each such flag passed to the compiler β€” yes, every single one, no cap. πŸ‘€

The kefir compiler driver has multiple operation modes. Command-line flags are parsed in left-to-right order, and later flags override earlier ones. Some operation modes, once selected, prevent further parsing and immediately invoke the selected mode β€” refer to the β€œOPTIONS” section for details. ✨


πŸŽ€ OPTIONS πŸŽ€

The following options terminate command-line argument parsing:

  • -h | --help β€” Print help text.
  • -v | --version β€” Print compiler version.
  • --compiler-info β€” Print compiler information.
  • --environment-info β€” Print compiler environment information (see the β€œENVIRONMENT” section below).
  • --environment-header β€” Print compiler environment header file (based on the β€œENVIRONMENT” section and current target).
  • -verbose β€” Report commands executed by the driver verbosely.

If passed, the -cc1 argument invokes the kefir-cc1 compiler directly, skipping the driver. The argument shall always be passed first to take an effect. 🫢

The rest of the command-line options are parsed normally:

  • -c β€” Skip the link-edit phase of the compilation, save object files.
  • -S β€” Skip the assembling phase of the compilation, save assembly files.
  • -E β€” Preprocess C-language source files, print results to standard output.
  • -P β€” Preprocess C-language source files, print results to standard output.
  • -std= standard β€” Determine language standard. For C23, supported values are: c23, c2x, gnu23, gnu2x, iso9899:2024. For C17 [default], any other value not explicitly listed for C23.
  • -x -language β€” Specify processing for the next input files. Supported values: none [default], c, c-header, cpp-output, assembler, assembler-with-cpp.
  • -preprocess-save β€” Preprocess C-language source files, save results.
  • -o file β€” Save results to the output file.
  • --target specification β€” Generate code for the specified target system (see the β€œTARGET” section below).
  • -O level β€” Code optimization level (default is 0). All non-zero levels are equivalent to 1. All non-numerical levels (such as -Os) are also equivalent to 1.
  • -fpreprocessed β€” Skip preprocessor directive processing and macro expansion. Preprocessor skips over any directive except for line directive, and acts solely as tokenizer.
  • --preprocessor-linemarkers β€” Include linemarkers into preprocessor output [default: off]. Likemarker content slightly differs from gcc, which might break some builds. Enable with care.
  • -funsigned-char β€” Let the type char be unsigned. By default, it is target-specific.
  • -fsigned-char β€” Let the type char be signed. By default, it is target-specific.
  • -fcommon β€” Place tentative definitions into common section (equivalent to common attribute applied to all variables).
  • -fvisibility=default|internal|hidden|protected β€” Set visibility for symbols in the program, unless overridden by a particular symbol attribute.
  • -fno-common β€” Do not place tentative definitions into common section [default].
  • -D name[=value] β€” Define preprocessor macro.
  • -U name β€” Undefine predefined preprocessor macro.
  • -I directory β€” Add directory to preprocessor include path.
  • -isystem directory β€” Add directory to preprocessor system include path.
  • -iquote directory β€” Add directory to preprocessor include path for quoted includes exclusively (processed before -I).
  • -idirafter directory β€” Add directory to preprocessor system include path (after processing other system include directories).
  • --embed-dir= directory β€” Add directory to preprocessor embed search path.
  • -M β€” Output a make rule describing the dependencies of source file (including the dependencies from system path).
  • -MM β€” Output a make rule describing the dependencies of source file (excluding the dependencies from system path and their transitive includes).
  • -MD β€” Output a make rule describing the dependencies of source file (including the dependencies from system path), while also running normal compilation pipeline.
  • -MMD β€” Output a make rule describing the dependencies of source file (excluding the dependencies from system path and their transitive includes), while also running normal compilation pipeline.
  • -MP β€” Output a phony target for each dependency of source file.
  • -MT target β€” Override the default target name of make rule produced by dependency generation.
  • -MF filename β€” Override the default output file for make rule produced by dependency generation.
  • -include file β€” Include file during preprocessing phase.
  • -s β€” Strip linked executable.
  • -r β€” Retain relocations in linked executable.
  • -e entry β€” Override entry point of linked executable.
  • -u symbol β€” Add undefined symbol to linked executable.
  • -l library β€” Link library.
  • -L directory β€” Add directory to linker library search path.
  • -rpath directory β€” Add directory to runtime library search path.
  • -soname name β€” Pass -soname option to the linker.
  • -pthread β€” Define macros and link pthread library.
  • -rdynamic β€” Pass --export-dynamic option to the linker.
  • -static β€” Produce a statically linked executable.
  • -shared β€” Produce a shared object.
  • -fPIC | -fpic β€” Produce position-independent code [default].
  • -fno-pic β€” Do not produce position-independent code [default].
  • -pie β€” Produce position-independent executable (requires -fPIC flag).
  • -no-pie β€” Do not produce position-independent executable [default].
  • -masm=ASSEMBLER β€” Produce code for the following assembler: [x86_64-gas-intel, x86_64-gas-intel_prefix, x86_64-gas-att (default), x86_64-yasm, intel (alias for x86_64-gas-intel), att (alias for x86_64-gas-att)]. Also affects assembler flags. Note that KEFIR_AS or AS environment variable shall point to the respective assembler executable.
  • -fomit-frame-pointer β€” Omit frame pointer in leaf functions that do not need it [default on optimization levels > 0].
  • -fno-omit-frame-pointer β€” Always use frame pointer in all functions [default on optimization level 0].
  • -g | -ggdb β€” Produce debug information [default: off].
  • -g[level] | -ggdb[level] β€” Produce debug information if level is greater than 0 [default: off].
  • -nostartfiles β€” Do not link start files.
  • -nodefaultlibs β€” Do not link default libraries.
  • -nolibc β€” Do not link libc.
  • -nostdlib β€” Do not link start files and default libraries.
  • -nostdinc β€” Do not add standard library to include path.
  • -nortinc β€” Do not add runtime includes to include path.
  • --enable-atomics β€” Enables atomic support. Implies --Wdeclare-atomic-support option and links appropriate atomic primitives library (libatomic/libcompiler_rt) where necessary.
  • --disable-atomics β€” Disables atomic support. Implies --Wno-declare-atomic-support option.
  • -Wp,option β€” Pass "option" to preprocessing phase as command line option. If option contains commas, it is split into multiple options.
  • -Xpreprocessor option β€” Pass "option" to preprocessing phase as command line option.
  • -Wc,option β€” Pass "option" to compiling phase as command line option. If option contains commas, it is split into multiple options.
  • -Wa,option β€” Pass "option" to assembler phase as command line option. If option contains commas, it is split into multiple options.
  • -Xassembler option β€” Pass "option" to assembler phase as command line option.
  • -Wl,option β€” Pass "option" to linking phase as command line option. If option contains commas, it is split into multiple options.
  • -z -keyword β€” Pass "-z keyword" to linking phase as command line options.
  • -Xlinker option β€” Pass "option" to linking phase as command line option.
  • -Woption β€” Pass "--option" to compiling phase as command line option.
  • -W option β€” Pass "option" to compiling phase as command line option.
  • --restrictive-c β€” Enable restrictive compiling mode with C extensions disabled.
  • --permissive-c β€” Enable permissive compiling mode with C extensions enabled [default].
  • --print-tokens β€” Print tokenized source in JSON format.
  • --print-ast β€” Print AST in JSON format.
  • --print-ir β€” Print intermediate representation in JSON format.
  • --print-opt β€” Print optimization representation in JSON format.
  • -run [file args...] β€” Run the linked executable with the rest of command line arguments. If no input file was specified, the first argument is treated as input file.
  • -runarg arg β€” Pass an argument to the runned process (shall precede -run flag).
  • -run-stdin file β€” Redirect runned process stdin from file (shall precede -run flag).
  • -run-stdout file β€” Redirect runned process stdout to file (shall precede -run flag).
  • -run-stderr file β€” Redirect runned process stderr to file (shall precede -run flag).
  • -run-stderr2out β€” Redirect runned process stderr to stdout (shall precede -run flag).

🧚 COMPILER OPTIONS 🧚

Extra compiler options available via the -W switch:

  • --c17-standard β€” Use C17 language standard.
  • --c23-standard β€” Use C23 language standard.
  • --pp-timestamp timestamp β€” Override preprocessor timestamp.
  • --json-errors β€” Print errors in JSON format to stderr.
  • --tabular-errors β€” Print errors in tabular format to stderr.
  • --target-profile profile β€” Generate code for specified target (see the β€œTARGET” subsection).
  • --source-id identifier β€” Force use provided source file identifier.
  • --extension-lib libpath β€” loads up an extension library from libpath, bestie πŸ’–
  • --system-include-dir dir β€” drops dir onto the include search path and flags it as a system include path (which matters for dependency output, iykyk)
  • --embed-dir directory β€” adds directory to the preprocessor's embed search path πŸŽ€
  • --debug-info β€” bakes debug information right into the produced output
  • --optimizer-max-inline-depth depth β€” the max depth for function inlining (5 by default, no cap on the vibes)
  • --optimizer-max-inlines-per-func inlines β€” the max number of inlined functions per function (10 by default)
  • --enable-lowering β€” does the target-specific SSA lowering. This one is mandatory for bit-precise integer support, so like… don't skip it [default] ✨
  • --disable-lowering β€” skips the target-specific SSA lowering entirely πŸ™ˆ
  • --preprocessor-assembly-mode β€” turns on assembly preprocessing mode (that's the default for .S files, lowercase-capital-S girlies). In this mode, leading '$' characters are not treated as part of an identifier
  • --preprocessor-normal-mode β€” turns assembly preprocessing mode back off (the default) πŸ¦‹
  • --feature-[name] β€” enables a compiler feature (go peek at the β€œFEATURES” subsection πŸ‘€)
  • --no-feature-[name] β€” disables a compiler feature (again: β€œFEATURES” subsection)
  • --internal-[flag] β€” enables a compiler internal flag (see β€œINTERNALS”)
  • --no-internal-[flag] β€” disables a compiler internal flag (see β€œINTERNALS”)
  • --codegen-[option] β€” enables an option for the code generator (see β€œCODEGEN”)
  • --no-codegen-[option] β€” disables an option for the code generator (see β€œCODEGEN”)
  • --optimizer-pipeline spec β€” your optimizer pipeline specification (see β€œOPTIMIZER”)
  • --precise-bitfield-load-store β€” loads and stores bitfields at byte boundaries [default: on]. It gives you extra correctness for structures allocated close to a boundary with unmapped memory pages, at the cost of less efficient bitfield handling. Does not change bitfield layout, so breathe 🫢
  • --no-precise-bitfield-load-store β€” loads and stores bitfields at machine word boundaries [default: off]. Heads up: this may cause failures for structures allocated close to boundaries with unmapped memory pages. Still doesn't change bitfield layout though ⭐
  • --declare-atomic-support β€” declares that atomics are supported (might require you to explicitly link a software atomic library like libatomic or libcompiler_rt, fr fr)
  • --no-declare-atomic-support β€” declares the absence of atomic support by defining the __STDC_NO_ATOMICS__ macro πŸ’€
  • --optimize-stack-frame β€” optimizes the stack frame layout by reusing space for variables with disjoint lifetimes. Might increase compilation time and memory use on very large functions [default: on]
  • --no-optimize-stack-frame β€” no stack frame layout optimization, every variable gets its own separate allocation, no sharing, no slay 🌸
  • --unsigned-char β€” makes the type char unsigned. By default it's target-specific, so don't @ me
  • --signed-char β€” makes the type char signed. By default it's target-specific πŸ’…
  • --codegen-tentative-common β€” places tentative definitions into the common section (equivalent to the common attribute applied to all variables)
  • --codegen-tentative-no-common β€” does not place tentative definitions into the common section [default]
  • --codegen-visibility-default β€” keeps default visibility for all symbols [default] ✨
  • --codegen-visibility-hidden β€” makes all symbols hidden unless an attribute says otherwise
  • --codegen-visibility-protected β€” makes all symbols protected unless an attribute says otherwise
  • --codegen-visibility-internal β€” makes all symbols internal unless an attribute says otherwise

✨ FEATURES ✨

These are the supported features, and you use them with the --Wfeature-[feature-name] and --Wno-feature-[feature-name] flags. Okay so here's the whole menu πŸ“

  • fail-on-attributes β€” fails if __attribute__((...)) shows up [default: off]
  • missing-function-return-type β€” permits function definitions that are missing their return type [default: on]
  • designated-init-colons β€” permits the "fieldname:" syntax in designated initializers [default: on]
  • labels-as-values β€” permits label-addressing with the && operator [default: on]
  • non-strict-qualifiers β€” disables strict qualifier checks for pointers [default: on]
  • signed-enums β€” forces all enums to have a signed integral type [default: off]
  • implicit-function-decl β€” permits implicit function declarations at the use-site [default: on]
  • empty-structs β€” permits empty structure/union definitions [default: on]
  • ext-pointer-arithmetics β€” permits pointer arithmetics with function and void pointers [default: on]
  • missing-braces-subobj β€” permits missing braces for subobject initialization with scalar [default: on]
  • statement-expressions β€” enables statement expressions [default: on]
  • omitted-conditional-operand β€” permits omission of the middle ternary expression operand [default: on]
  • int-to-pointer β€” permits any integral type conversion to pointer [default: on]
  • permissive-pointer-conv β€” permits conversions between any pointer types [default: on]
  • named-macro-vararg β€” permits named macro variable arguments [default: on]
  • include-next β€” permits the include_next preprocessor directive [default: on]
  • fail-on-assembly β€” disables support of inline assembly [default: off]
  • va-args-comma-concat β€” enables special processing for the ", ##__VA_ARGS" case in the preprocessor [default: on]
  • switch-case-ranges β€” enables support for ranges in switch cases [default: on]
  • designator-subscript-ranges β€” enables support for ranges in designator subscripts [default: on]

🌈 CODEGEN 🌈

Supported code generator options, and you use these with the --Wcodegen-[option] and --Wno-codegen-[option] flags πŸ’œ

  • emulated-tls β€” use emulated TLS [disabled by default, enabled on the openbsd platform]
  • tls-common β€” generate a common section for thread-local storage if the respective attribute is on [enabled for linux and netbsd]
  • pic β€” generate position-independent code ✨
  • omit-frame-pointer β€” omit the frame pointer in leaf functions that don't need it
  • valgrind-compatible-x87 β€” replaces x87 opcodes that Valgrind doesn't support with more expensive alternatives [default: on]
  • syntax=SYNTAX β€” produces assembly output with the specified syntax. Your options are x86_64-intel_noprefix, x86_64-intel_prefix, x86_64-att (that's the default), and x86_64-yasm.
  • details=DETAILS-SPEC β€” augments assembly output with internal code generator details in comments. DETAILS-SPEC can be: vasm (virtual assembly), vasm+regs (virtual assembly and register allocations), or devasm (devirtualized assembly).
  • pipeline=PIPELINE-SPEC β€” the code generator transformation pipeline spec, which is a comma separated list of pipeline pass names:
    • noop β€” no-operation pass 😌
    • amd64-drop-virtual β€” non-functional virtual instruction elimination for amd64 targets
    • amd64-peephole β€” peephole optimizations for amd64 targets

πŸ”₯ OPTIMIZER πŸ”₯

The optimizer pipeline specification is a comma separated list of pipeline pass names. Here's the roster πŸ‘‘

  • noop β€” no-operation pass. She does nothing and she does it flawlessly πŸ’…
  • phi-propagate β€” wherever possible, substitutes phi nodes of the SSA representation with actual references
  • mem2reg β€” pulls function local variables into registers
  • op-simplify β€” general code simplification
  • constant-fold β€” folding constant expressions
  • gvn β€” global value numbering pass, there to eliminate redundant arithmetic and bitwise operations
  • local-alloc-sink β€” moves local variable allocations closer to their actual uses (and does not affect effective variable lifetimes, noted)
  • dead-code-elimination β€” eliminates dead code, blocks and phi links
  • block-merge β€” removes unnecessary jump instructions and merges the respective blocks
  • dead-alloc β€” removes dead local variable allocations
  • inline-func β€” performs function inlining
  • tail-call β€” performs tail call optimization
  • lowering β€” performs target-specific lowering of the SSA representation. Mandatory for bit-precise integer support, so this one's kind of a big deal 😀

πŸ¦‹ TARGET πŸ¦‹

Target platforms get specified in the format [<backend>-]<platform>[-<variant>] where:

  • backend β€” opt [default]
  • platform β€” <arch>-<os> | host [default]
  • arch β€” x86_64 | hostcpu [default]
  • platform β€” linux | freebsd | openbsd | netbsd | hostos [default]
  • variant β€” none | musl | gnu | system | default

Backend and variant are the optional parts of the target specification, bestie β€” they can dip if they want πŸ’«

Variant "none" avoids any implicit library linkages and include path. On linux, "default" is equivalent to "gnu", and on other platforms it's equivalent to "system". That's the whole tea β˜•

✨ ENVIRONMENT ✨

okay bestie, these are the env vars that change how kefir behaves. read carefully, some of them are literally mandatory for certain platforms πŸ’…

  • KEFIR_AS | AS β€” overrides the default "as" assembler πŸ› οΈ
  • KEFIR_LD | LD β€” overrides the default "ld" linker πŸ”—
  • KEFIR_RTINC β€” tells kefir where the runtime include location lives. this one is mandatory for every platform variant except "*-none" 🫢
  • KEFIR_MUSL_INCLUDE β€” musl include paths, separated by ';'. mandatory for the "linux-musl" platform variant 🌸
  • KEFIR_MUSL_LIB β€” musl library paths, separated by ';'. mandatory for the "linux-musl" platform variant 🌸
  • KEFIR_MUSL_DYNAMIC_LINKER β€” dynamic linker path. optional for the "linux-musl" platform variant ✨
  • KEFIR_GNU_INCLUDE β€” GNU include paths, separated by ';'. mandatory for the "linux-gnu" platform variant πŸ’œ
  • KEFIR_GNU_LIB β€” GNU library paths, separated by ';'. mandatory for the "linux-gnu" platform variant πŸ’œ
  • KEFIR_GNU_DYNAMIC_LINKER β€” dynamic linker path. optional for the "linux-gnu" platform variant ✨
  • KEFIR_FREEBSD_INCLUDE β€” FreeBSD include paths, separated by ';'. mandatory for the "freebsd-system" platform variant πŸ¦‹
  • KEFIR_FREEBSD_LIB β€” FreeBSD library paths, separated by ';'. mandatory for the "freebsd-system" platform variant πŸ¦‹
  • KEFIR_FREEBSD_DYNAMIC_LINKER β€” dynamic linker path. optional for the "freebsd-system" platform variant ✨
  • KEFIR_OPENBSD_INCLUDE β€” OpenBSD include paths, separated by ';'. mandatory for the "openbsd-system" platform variant 🐑
  • KEFIR_OPENBSD_LIB β€” OpenBSD library paths, separated by ';'. mandatory for the "openbsd-system" platform variant 🐑
  • KEFIR_OPENBSD_DYNAMIC_LINKER β€” dynamic linker path. optional for the "openbsd-system" platform variant ✨
  • KEFIR_TMPDIR β€” overrides kefir's temporary directory πŸ“
  • KEFIR_DRIVER_CLI_QUIET β€” set it to "yes" (no quotes, bestie) and it suppresses warnings about unknown command line options 🀫
  • SOURCE_DATE_EPOCH β€” overrides the preprocessor timestamp with whatever value you give it. it wants a Unix epoch timestamp ⏰
fyi the ; separators are literal, don't go putting spaces or commas in there, okay? iykyk πŸŽ€

πŸ’€ EXIT STATUS πŸ’€

normally kefir exits with a 0 exit code, slay. but if literally any error shows up in any of the compilation stages, all further compilation gets aborted and you get a non-zero exit code back. so if you see a non-zero, something went wrong, no cap 😭


πŸ‘‘ STANDARDS πŸ‘‘

kefir implements the C17 language standard as specified in its final draft, plus the C23 language standard (except _Decimal support) as specified in the first draft of C2Y. the range, the icon behavior 🫢


πŸ¦‹ NOTES πŸ¦‹

the kefir compiler is licensed under the terms of the GNU GPLv3 license. the runtime code provided along with kefir is licensed under the terms of the BSD-3-Clause license πŸ“œ

kefir is developed and maintained by Jevgenij Protopopov (legally: Jevgenijs Protopopovs) πŸ‘‘

please report bugs found in kefir to jevgenij@protopopov.lv β€” like, actually do it, don't just complain in the group chat πŸ™ˆ

kefir is available online at https://sr.ht/~jprotopopov/kefir with read-only mirrors at https://git.protopopov.lv/kefir and https://codeberg.org/jprotopopov/kefir 🌈


and that's the whole page bestie, you're officially caught up πŸ’– this one's the Debian build from September 2025, filed under kefir(1) β€” go compile something iconic, periodt βœ¨πŸŽ€

πŸ“¦ where this page comes from