GDC(1)
๐ GDC(1) ๐
okay bestie, this one's from the GNU manual ๐ so grab your snacks, we're about to go through gdc together ๐ซถ
โจ NAME โจ
gdc is a GCC-based compiler for the D language ๐
๐งฉ SYNOPSIS โจ
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
only the most useful options are listed up there ๐ the rest are down below, so don't panic ๐ซถ
๐ DESCRIPTION ๐
the gdc command is the GNU compiler for the D language ๐ฅ it supports a bunch of the same options as gcc, so if you already know gcc you're literally halfway there โจ this manual only covers the options that are specific to gdc ๐ฆ
๐ OPTIONS ๐
๐ Input and Output files
the file name suffix on each input file decides what kind of compilation happens ๐ these are the kinds of input file names that work:
file.dโ D source files ๐file.ddโ Ddoc source files ๐ธfile.diโ D interface files ๐ง
you can give gdc more than one input file on the command line ๐
each one gets compiled separately. but if you use -o file, then all the input files get compiled together into one single output file called file. and this works even with -S or -c, so no judgment ๐
a D interface file only holds what an import of the module actually needs, not the whole implementation of that module โจ gdc can make these from a D source file if you use the -H option ๐ซถ when the compiler resolves an import declaration, it looks for matching .di files first, and only then goes looking for .d files ๐
a Ddoc source file has code written in the D macro processor language ๐ it's mainly made for turning embedded comments into user documentation, leaning a little toward HTML generation ๐ท and if a .d source file starts with the string "Ddoc", it gets treated as general purpose documentation instead of as D source code ๐
๐ Runtime Options
these options change how programs compiled with gdc behave at runtime ๐ฅ
-fall-instantiationsโ generates code for all template instantiations ๐ the default emission strategy is to skip code for declarations that were instantiated speculatively (like from__traits(compiles, ...)), or that come from an imported module that isn't being compiled ๐ โโ๏ธ-fno-assertโ turns off code generation forassertcontracts ๐ซ-fno-bounds-checkโ turns off array bounds checking for all functions ๐๏ธ this can speed things up for code that uses arrays a lot, BUT:
โ ๏ธ bestie, listen: if the code actually does break array bounds, this can cause unpredictable behavior ๐ it's only safe to use if you're totally sure your code never throws a RangeError.
-fbounds-check=valueโ a more flexible version of-fbounds-check, so you get more control over where bounds checking is on or off ๐ฏ the supported values are:onโ turns on array bounds checking for all functions ๐safeonlyโ turns on array bounds checking only for@safefunctions ๐ก๏ธoffโ turns off array bounds checking completely ๐ซฅ
-fno-builtinโ doesn't recognize built-in functions unless they begin with the prefix__builtin_๐ โโ๏ธ by default, the compiler does recognize when a function in thecore.stdcpackage is a built-in function โจ-fcheckaction=valueโ controls what code gets generated when an assertion, bounds check, or final switch fails ๐ฅ the supported values are:contextโ throws anAssertErrorwith extra context information ๐haltโ halts the program execution ๐throwโ throws anAssertError(this is the default) ๐
-fdebug,-fdebug=valueโ turns on compilation of conditionaldebugcode into the program ๐ the-fdebugoption by itself sets the debug level to1, while-fdebug=enablesdebugcode identified by any of these values:levelโ sets the debug level to level, so anydebugcode<= levelgets compiled in ๐identโ turns on compilation of anydebugcode identified by ident ๐ท๏ธ
-fno-druntimeโ implements <https://dlang.org/spec/betterc.html> ๐งผ hmm, the link ishttps://dlang.org/spec/betterc.html, and it assumes you're targeting an environment without a D runtime library ๐ this is the same as compiling with these options:
gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
-fextern-std=standardโ sets the C++ name mangling compatibility to the version you pick with standard ๐ง the supported values are:c++98,c++03โ set__traits(getTargetInfo, "cppStd")to199711๐ฆc++11โ sets__traits(getTargetInfo, "cppStd")to201103๐ทc++14โ sets__traits(getTargetInfo, "cppStd")to201402๐ผc++17โ sets__traits(getTargetInfo, "cppStd")to201703๐ this one's the default, so it's the main character ๐c++20โ sets__traits(getTargetInfo, "cppStd")to202002๐
-fno-invariantsโ turns off code generation forinvariantclass contracts ๐ซ-fmainโ generates a defaultmain()function when compiling ๐ this is super handy when you're unittesting a library, since you can run the unittests without manually writing an entry-point function ๐ it does nothing ifmainis already defined in your code ๐ซถ-fno-moduleinfoโ turns off generation ofModuleInfoand the related functions that would become unreferenced without it ๐งน this might let you link to programs that aren't written in D ๐ฆ the functions that don't get generated include module constructors and destructors (static thisandstatic ~this),unittestcode, andDSOregistry functions for dynamically linked code ๐-fonly=filenameโ tells the compiler to parse and run semantic analysis on all modules on the command line, but only generate code for the module specified byfilename๐ฏ-fno-postconditionsโ turns off code generation for postconditionoutcontracts ๐ซฅ-fno-preconditionsโ turns off code generation for preconditionincontracts ๐ซฅ-fpreview=idโ turns on an upcoming D language change identified by id ๐ฎ the supported values are:allโ turns on all upcoming D language features ๐คฏdip1000โ implementshttps://wiki.dlang.org/DIP1000(Scoped pointers) ๐dip1008โ implementshttps://wiki.dlang.org/DIP1008(Allow exceptions in@nogccode) ๐งdip1021โ implementshttps://wiki.dlang.org/DIP1021(Mutable function arguments) ๐dip25โ implementshttps://wiki.dlang.org/DIP25(Sealed references) ๐dtorfieldsโ turns on generation for destructing fields of partially constructed objects ๐งฉfieldwiseโ turns on generation of struct equality so it uses field-wise comparisons ๐ชfixaliasthisโ implements new lookup rules that check the current scope foralias thisbefore searching upper scopes ๐inโ implementsinparameters to meanscope const [ref], and accepts rvalues ๐ซงinclusiveincontractsโ implementsincontracts of overridden methods so they're a superset of the parent contract ๐intpromoteโ implements C-style integral promotion for unary+,-and~expressions ๐ขnosharedaccessโ turns off and disallows all access to shared memory objects ๐ซrvaluerefparamโ implements rvalue arguments torefparameters ๐ซshortenedmethodsโ implements use of=>for methods and top-level functions, in addition to lambdas โก๏ธ
-freleaseโ turns on compiling in release mode ๐ that means no runtime checks for contracts and asserts get emitted ๐โโ๏ธ array bounds checking is skipped for@systemand@trustedfunctions, and assertion failures are undefined behavior ๐
โ ๏ธ undefined behavior alert: in release mode, assertion failures are undefined behavior, so be careful, bestie ๐ซฃ
this is the same as compiling with these options:
gdc -fno-assert -fbounds-check=safe -fno-invariants \
-fno-postconditions -fno-preconditions -fno-switch-errors
-frevert=โ turns off a D language feature identified by id ๐ โโ๏ธ the supported values are:allโ turns off all revertable D language features ๐งนdip25โ revertshttps://wiki.dlang.org/DIP25(Sealed references) ๐dtorfieldsโ turns off generation for destructing fields of partially constructed objects ๐งฉmarkdownโ turns off Markdown replacements in Ddoc comments ๐
-fno-rttiโ turns off generation of run-time type information for all user defined types ๐ซฅ any code that uses language features needing this info will throw an error, so heads up ๐-fno-switch-errorsโ controls what code gets generated when no case is matched in afinal switchstatement ๐ by default, the run time behavior is to throw aSwitchError๐ฅ turning off-fswitch-errorsmeans the program immediately halts instead ๐-funittestโ turns on compilation ofunittestcode and turns on theversion(unittest)identifier ๐งช this implies-fassert๐ซถ-fversion=valueโ turns on compilation of conditionalversioncode into the program, identified by any of these values:levelโ sets the version level to level, so anyversioncode>= levelgets compiled in ๐๏ธidentโ turns on compilation ofversioncode identified by ident ๐ท๏ธ
-fno-weak-templatesโ turns off emission of declarations that can be defined in multiple objects as weak symbols ๐ซง by default, all public symbols get emitted as weak, unless the target doesn't support weak symbols ๐ if you disable this, common symbols get put in COMDAT or become private instead ๐
๐บ๏ธ Options for Directory Search
these options tell the compiler where to look for files, libraries, and other parts of the compiler itself ๐งญ
-Idirโ specifies a directory to search for imported modules at compile time ๐ you can use multiple-Ioptions, and the paths get searched in the same order ๐-Jdirโ specifies a directory to search for files in string imports at compile time ๐ this switch is required if you want to useimport(file)expressions ๐ you can use multiple-Joptions, and they're searched in the same order too ๐-Ldirโ when linking, specifies a library search directory, just like with gcc ๐-Bdirโ specifies where to find the executables, libraries, source files, and data files of the compiler itself, just like with gcc ๐ง-fmodule-file=module=specโ okay so this one is a whole vibe ๐ It rewrites the file paths of imported modules. If an imported module matches all ofmoduleor its leftmost part, the path inspecbecomes the place where D sources get searched for. This comes in clutch when your file paths and names don't line up with your package and module hierarchy ๐๏ธ Check out these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This tells the compiler to search every import path for the source file foo.d when importing A.B, and to look in the directory bar/ when importing C. Here's how that plays out in D code:
module test;
import A.B; // Matches A.B, searches for foo.d
import C.D.E; // Matches C, searches for bar/D/E.d
import A.B.C; // No match, searches for A/B/C.d
-imultilib dirโ pickdiras a subdirectory of the gcc directory that holds target-specific D sources and interfaces ๐ธ-iprefix prefixโ setprefixas the prefix for that same gcc directory with the target-specific D sources and interfaces ๐ง If the prefix is a directory, remember to add the final'/'๐ซถ-nostdincโ skip the standard system directories when hunting for D source and interface files ๐ โโ๏ธ Only the directories you passed with-Ioptions get searched (plus the directory of the current file, if that applies).
โจ Code Generation โจ
Okay so gdc has a bunch of code generation options all its own, on top of the many gcc ones that control code generation ๐
-Hโ generates D interface files for every module being compiled ๐ฆ The compiler names the output file after the input file, strips any directory components and the suffix, then slaps on the.disuffix.-Hd dirโ same as-H, but the interface files land in the directorydir๐ You can pair this with-Hf fileto set the output file and the directory path separately.-Hf fileโ same as-H, but the interface files get written tofile๐ You can pair this with-Hd dirto set the output file and the directory path independently.-Mโ outputs the module dependencies of all the source files being compiled, formatted somakecan read them ๐ The compiler spits out one make rule with the object file name for that source file, a colon, and the names of all the imported files.-MMโ basically-M, but it doesn't mention imported modules from the D standard library package directories ๐-MF fileโ when used with-Mor-MM, it picks the file the dependencies get written to ๐ When used with the driver options-MDor-MMD,-MFoverrides the default dependency output file.-MGโ exists purely for compatibility with gcc, and the compiler just ignores it ๐คทโโ๏ธ-MPโ outputs a phony target for each dependency other than the modules being compiled, so each one depends on nothing ๐ป-MT targetโ changes the target of the rule made by dependency generation to be exactly the string you give it ๐ฏ Want multiple targets? Either put them all in one argument to-MT, or use multiple-MToptions.-MQ targetโ same as-MT, except it quotes any characters that are special to make ๐-MDโ this one is equivalent to-M -MF fileโจ The driver figures outfileby stripping any directory components and the suffix from the input file, then adding a.depssuffix.-MMDโ like-MD, but it doesn't mention imported modules from the D standard library package directories ๐ซง-Xโ outputs info describing the contents of all source files being compiled, in JSON format, to a file ๐งพ The driver picksfileby stripping any directory components and the suffix from the input file, then adding a.jsonsuffix.-Xf fileโ same as-X, but all the JSON contents get written to the file you specify ๐-fdocโ generates "Ddoc" documentation and writes it to a file ๐ The compiler picksfileby stripping any directory components and the suffix from the input file, then adding a.htmlsuffix.-fdoc-dir=dirโ same as-fdoc, but the docs go into the directorydir๐ You can pair this with-fdoc-file=fileto set the output file and directory path separately.-fdoc-file=fileโ same as-fdoc, but the docs get written tofile๐ท You can pair this with-fdoc-dir=dirto set the output file and directory path independently.-fdoc-inc=fileโ tells it to readfileas a Ddoc macro file ๐งฉ You can use multiple-fdoc-incoptions, and the files get read and processed in the order you gave them.-fdump-c++-spec=fileโ for D source files, generates matching C++ declarations infile๐-fdump-c++-spec-verboseโ works together with-fdump-c++-spec=from above ๐ญ It adds comments for the ignored declarations in the generated C++ header.-fsave-mixins=fileโ generates the code expanded from Dmixinstatements and writes the processed sources tofile๐ This is super useful for debugging compilation errors, and it gives debuggers the source they need to show when you ask for it.
โจ Warnings โจ
Warnings are diagnostic messages that flag constructions that aren't technically wrong, but are risky or hint that there's probably a bug in your program ๐ Unless -Werror is specified, they won't stop your program from compiling, so no panic ๐ซถ
-Wallโ turns on all warning messages ๐จ Warnings aren't a defined part of the D language, and every construct that might trigger a warning is still valid code.-Wallocaโ warns on all uses ofallocain the source ๐ง-Walloca-larger-than=nโ warns on unbounded uses ofalloca, plus bounded uses whose bound could be bigger thannbytes ๐-Wno-alloca-larger-thanturns off the-Walloca-larger-thanwarning, and it's equivalent to-Walloca-larger-than=SIZE_MAXor larger.-Wcast-resultโ warns about casts that will end up producing a null or zero result ๐ Right now this only happens when casting between an imaginary and a non-imaginary data type, or when casting between a D class and a C++ class.-Wno-deprecatedโ stops the warnings about deprecated features and symbols that have "deprecated" attributes ๐ โโ๏ธ-Werrorโ turns every warning into an error ๐ซ Major main character energy, no cap.-Wspeculativeโ lists all error messages from speculative compiles, like the ones from__traits(compiles, ...)๐ฎ This option doesn't report messages as warnings, so they never become errors even when-Werroris also used.-Wtemplatesโ warns whenever a template instantiation is encountered ๐งฑ Some coding rules ban templates, and this helps you enforce that rule.-Wunknown-pragmasโ warns when apragma()shows up that gdc doesn't understand ๐ค This is different from-fignore-unknown-pragmas: a pragma that's part of the D language but isn't implemented by the compiler won't get reported with this one.-Wno-varargsโ doesn't warn about questionable usage of the macros used to handle variable arguments, likeva_start๐ซ-fignore-unknown-pragmasโ turns off errors for unsupported pragmas ๐-fmax-errors=nโ caps the number of error messages atn, and then gdc bails out instead of trying to keep going with the source code ๐ Ifnis0(the default), there's no limit on how many error messages get produced.-fsyntax-onlyโ checks the code for syntax errors without actually compiling it ๐ You can combine it with-fdocor-Hto generate files for each module on the command line, but it won't produce any other output file.-ftransition=idโ reports extra info about the D language changes identified byid๐ฃ These values are supported:allโ lists info on all D language transitions ๐complexโ lists all usages of complex or imaginary types ๐fieldโ lists all non-mutable fields that take up space in an object instance ๐งinโ lists all usages ofinon a parameter ๐ซณnogcโ lists all hidden GC allocations ๐๏ธtemplatesโ lists statistics on template instantiations ๐tlsโ lists all variables going into thread local storage ๐งตvmarkdownโ lists instances of Markdown replacements in Ddoc ๐
โจ Options for Linking โจ
These options come into play when the compiler links object files into an executable output file ๐ They're meaningless if the compiler isn't doing a link step, so don't stress about them then ๐
-defaultlib=libnameโ picks the library to use instead of libphobos when linking ๐ Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored.-debuglib=libnameโ picks the debug library to use instead of libphobos when linking ๐ This does nothing unless the-goption was also given on the command line. Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored here too.-nophoboslibโ doesn't use the Phobos or D runtime library when linking ๐ โโ๏ธ Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored. The standard system libraries are still used normally, unless-nostdlibor-nodefaultlibsis used.-shared-libphobosโ on systems that provide libgphobos and libgdruntime as both a shared and a static library, this forces the shared version ๐ซง If no shared version was built when the compiler was configured, this option does nothing.-static-libphobosโ on systems that provide libgphobos and libgdruntime as both a shared and a static library, this forces the static version ๐ชจ If no static version was built when the compiler was configured, this option does nothing.
โจ Developer Options โจ
This section covers command-line options that are mainly for developers or language tooling ๐ ๏ธ
-fdump-d-originalโ outputs the internal front-end AST after the "semantic3" stage ๐ณ This is only useful for debugging the GNU D compiler itself, so it's a dev-only flex ๐ค-vโ dumps info about the compiler's language processing stages while your source program is being compiled ๐ This includes listing all modules that go through the "parse", "semantic", "semantic2", and "semantic3" stages, all "import" modules and their file paths, and all "function" bodies being compiled.
โจ SEE ALSO โจ
gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gdc and gcc ๐ธ
โจ COPYRIGHT โจ
okay bestie, the legal bit at the end ๐ซถ Copyright (c) 2006-2022 Free Software Foundation, Inc. ๐ That's the FSF claiming it, full stop.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation ๐ (so you're allowed to share and remix it, as long as you follow that license ๐ฆ). There are no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts ๐ธ. A copy of the license is included in the man page gfdl(7) โจ, so go check it out if you want the nitty-gritty ๐ง.
gcc-12 ยท 2022-02-22 ยท GDC(1) ๐ that's the source version, the date, and the page name all tucked into the footer, and honestly that's giving very organized energy ๐ Stay iconic and keep reading the manuals, periodt! ๐๐
๐ฆ where this page comes from
- ubuntu jammy: gdc-12-i686-linux-gnu 12-20220222-1ubuntu1cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms