M2(1)
โจ NAME โจ
okay bestie, meet gm2 โ The GNU Modula-2 Compiler. you're reading the M2(1) manual page, and we're about to make Unix make sense together. no cap. ๐
๐ธ SYNOPSIS ๐ธ
(the original synopsis section is empty here, so we keep it cute and blank)
๐ฆ DESCRIPTION ๐ฆ
(also empty here, so we move to the good stuff)
๐ OPTIONS ๐
For any given input file, the file name suffix determines what kind of compilation is done. The following kinds of input file names are supported:
file.modโ Modula-2 implementation or program source files. See the-fmod=option if you wish to compile a project which uses a different source file extension. ๐ฑfile.defโ Modula-2 definition module source files. Definition modules are not compiled separately; in GNU Modula-2 definition modules are parsed as required when program or implementation modules are compiled. See the-fdef=option if you wish to compile a project which uses a different source file extension. ๐
You can specify more than one input file on the gm2 command line,
-gโ create debugging information so that debuggers such asgdbcan inspect and control executable. ๐-Iโ used to specify the search path for definition and implementation modules. An example is:gm2 -g -c -I.:../../libs foo.mod. If this option is not specified then the default path is added which consists of the current directory followed by the appropriate language dialect library directories. ๐-fauto-initโ turns on auto initialization of pointers toNIL. Whenever a block is created all pointers declared within this scope will have their addresses assigned toNIL. โจ-fboundsโ turns on run time subrange, array index and indirection viaNILpointer checking. ๐ก๏ธ-fcaseโ turns on compile time checking to check whether aCASEstatement requires anELSEclause when one was not specified. ๐ค-fcppโ preprocess the source withcpp -lang-asm -traditional-cpp. For further details about these options. If-fcppis supplied then all definition modules and implementation modules which are parsed will be preprocessed bycpp. ๐-fdebug-builtinsโ call a real function, rather than the builtin equivalent. This can be useful for debugging parameter values to a builtin function as it allows users to single step code into an intrinsic function. ๐-fdef=โ recognize the specified suffix as a definition module filename. The default implementation and module filename suffix is.def. If this option is used GNU Modula-2 will still fall back to this default if a requested definition module is not found. ๐-fdump-system-exportsโ display all inbuilt system items. This is an internal command line option. ๐-fexceptionsโ turn on exception handling code. By default this option is on. Exception handling can be disabled by-fno-exceptionsand no references are made to the run time exception libraries. ๐จ-fextended-opaqueโ allows opaque types to be implemented as any type. This is a GNU Modula-2 extension and it requires that the implementation module defining the opaque type is available so that it can be resolved when compiling the module which imports the opaque type. ๐ฎ-ffloatvalueโ turns on run time checking to check whether a floating point number is about to exceed range. ๐-fgen-module-list=filenameโ attempt to find all modules when linking and generate a module list. If the filename is-then the contents are not written and only used to force the linking of all module ctors. This option cannot be used if-fuse-list=is enabled. ๐-findexโ generate code to check whether array index values are out of bounds. Array index checking can be disabled via-fno-index. ๐ข-fisoโ turn on ISO standard features. Currently this enables the ISOSYSTEMmodule and alters the default library search path so that the ISO libraries are searched before the PIM libraries. It also effects the behavior ofDIVandMODoperators. ๐-flibs=โ modifies the default library search path. The libraries supplied are:m2pim,m2iso,m2min,m2logandm2cor. These map onto the Programming in Modula-2 base libraries, ISO standard libraries, minimal library support, Logitech compatible library and Programming in Modula-2 with coroutines. Multiple libraries can be specified and are comma separated with precedence going to the first in the list. It is not necessary to use-flibs=m2pimor-flibs=m2isoif you also specify-fpim,-fpim2,-fpim3,-fpim4or-fiso. Unless you are using-flibs=m2minyou should includem2pimas they provide the base modules which all other dialects utilize. The option-fno-libs=-disables thegm2driver from modifying the search and library paths. ๐-static-libgm2โ On systems that provide the m2 runtimes as both shared and static libraries, this option forces the use of the static version. ๐งฑ-fm2-debug-trace=โ turn on trace debugging using a comma separated list:line,token,quad,all. This is an internal command line option. ๐-fm2-dump=โ enable dumping of modula-2 internal representation of data structures using a comma separated list. The list can contain:quad,gimple,decl,all. ๐ฆ-fm2-dump-decl=filestemโ dump the modula-2 representation of a symbol to the filestem specified. This option only takes effect if the-fm2-dump-filteris specified. ๐๏ธ-fm2-dump-gimple=filestemโ dump modula-2 gimple representation to the filestem specified. ๐งฌ-fm2-dump-quad=filestemโ dump quadruple representation to the filestem specified. ๐งฎ-fm2-dump-filter=rulesโ filter the language dumps-fdump-lang-decl,-fdump-lang-gimpleand-fdump-lang-quadon rules.rulesmust be a comma separated list which can take three forms: the full decl textual name of a procedure,[libname.]module.identor[filename:]module.ident. This is an internal command line option. Currently it only filters on procedure names and regexp matching is not implemented. Three examples of its use following the previous forms could be:
-fm2-dump-filter=_M2_hello_init
-fm2-dump-filter=m2pim.StrIO.WriteString
-fm2-dump-filter=StrLib.mod:StrIO.WriteString
-fm2-file-offset-bits=โ force the typeSYSTEM.COFF_Tto be built using the specified number of bits. If this option is not used then default isCSSIZE_Tbits. ๐-fm2-gโ improve the debugging experience for new programmers at the expense of generatingnopinstructions if necessary to ensure single stepping precision over all code related keywords. An example of this is in termination of a list of nestedIFstatements where multipleENDkeywords are mapped onto a sequence ofnopinstructions. ๐ฃ-fm2-lower-caseโ render keywords in error messages using lower case. ๐ก-fm2-pathname=โ specify the module mangled prefix name for all modules in the following include paths. ๐ท๏ธ-fm2-pathnameIโ for internal use only: used by the driver to copy the user facing-Ioption. ๐-fm2-pathname-root=pathrootโ add search paths derived from the specifiedpathroot. ๐ณ-fm2-pathname-rootIโ for internal use only: used by the driver to copy every user-fm2-pathname-root=facing option in order with all other-Ioptions. ๐งญ-fm2-pluginโ insert plugin to identify run time errors at compile time (default on). ๐-fm2-prefix=โ specify the module mangled prefix name. All exported symbols from a definition module will have the prefix name. ๐ท๏ธ-fm2-statisticsโ generates quadruple information: number of quadruples generated, number of quadruples remaining after optimization and number of source lines compiled. ๐-fm2-strict-typeโ experimental flag to turn on the new strict type checker. ๐งช-fm2-strict-type-reasonโ provides more detail why the types are incompatible. ๐ต๏ธ-fm2-whole-programโ compile all implementation modules and program module at once. Notice that you need to take care if you are compiling different dialect modules (particularly with the negative operands to modulus). But this option, when coupled together with-O3, can deliver huge performance improvements. ๐-fmod=โ recognize the specified suffix as implementation and module filenames. The default implementation and module filename suffix is.mod. If this option is used GNU Modula-2 will still fall back to this default if it needs to read an implementation module and the specified suffixed filename does not exist. ๐-fnilโ generate code to detect accessing data through aNILvalue pointer. Dereferencing checking through aNILpointer can be disabled by-fno-nil. ๐ซ-fpimโ turn on PIM standard features. Currently this enables the PIMSYSTEMmodule and determines which identifiers are pervasive (declared in the base module). If no other-fpim[234]switch is used then division and modulus operators behave as defined in PIM4. ๐-fpim2โ turn on PIM-2 standard features. Currently this removesSIZEfrom being a pervasive identifier (declared in the base module). It placesSIZEin theSYSTEMmodule. It also effects the behavior ofDIVandMODoperators. ๐-fpim3โ turn on PIM-3 standard features. Currently this only effects the behavior ofDIVandMODoperators. ๐-fpim4โ turn on PIM-4 standard features. Currently this only effects the behavior ofDIVandMODoperators. ๐-fpositive-mod-floor-divโ forces theDIVandMODoperators to behave as defined by PIM4. All modulus results are positive and the results from the division are rounded to the floor. โ-fpthreadโ link against the pthread library. By default this option is on. It can be disabled by-fno-pthread. GNU Modula-2 uses the GCC pthread libraries to implement coroutines (see theSYSTEMimplementation module). ๐งต-frangeโ generate code to check the assignment range, return value range set range and constructor range. Range checking can be disabled via-fno-range. ๐-freturnโ generate code to check that functions always exit with aRETURNand do not fall out at the end. Return checking can be disabled via-fno-return. โฉ๏ธ-fruntime-modules=โ bestie, this one lets you spell out, as a comma separated list, the run time modules and the order they show up in ๐ . Those modules get initialized first, before literally any other module in the application dependency. Default vibe is set to"m2iso:RTentity,m2iso:Storage,m2iso:SYSTEM,""m2iso:M2RTS,m2iso:RTExceptions,m2iso:IOLink". Important tho: these modules only get linked into your executable if they're actually required. Adding a long list of dependent modules will not affect the size of the executable โ it merely states the initialization order, should they be required. Lowkey just a scheduling announcement, not a guest list ๐-fscaffold-dynamicโ this option makes suregm2generates a dynamic scaffold infrastructure when it's compiling implementation and program modules โจ. By default this option is on. Want it off? Use-fno-scaffold-dynamic, or go pick-fno-scaffold-staticinstead.-fscaffold-cโ generates a C source scaffold for the current module being compiled ๐ธ-fscaffold-c++โ generates a C++ source scaffold for the current module being compiled ๐-fscaffold-mainโ forces the generation of themainfunction ๐ฅ. Not necessary if the-cis omitted, so don't stress about it unless you need it.-fscaffold-staticโ makesgm2generate a static scaffold within the program module. That static scaffold is basically a sequence of calls to all dependent module initialization and finalization procedures ๐. It's genuinely useful for debugging and single stepping the initialization blocks of implementation modules โ it's giving very much "watch me walk through this step by step" energy ๐ฆ-fsharedโ generate a shared library from the module ๐-fsoft-check-allโ turns on all the run time checks, no crumbs left ๐. Same thing as invoking GNU Modula-2 with the command options-fnil,-frange,-findex,-fwholevalue,-fwholediv,-fcase,-freturn.-fsourcesโ displays the path to the source of each module โญ. Super handy at compile time to check that the correct definition module is being used.-fswigโ generate a swig interface file ๐-funbounded-by-referenceโ enables optimization of unbounded parameters by attempting to pass nonVARunbounded parameters by reference. The whole point: this optimization avoids the implicit copy inside the callee procedure ๐ . GNU Modula-2 will only allow unbounded parameters to be passed by reference if, inside the callee procedure, they are not written to, no address is calculated on the array, and it is not passed as aVARparameter.
Heads up bestie, this one is spicy ๐ฅ. It is possible to write code that breaks this optimization, so use this option carefully. For example it would be possible to take the address of an array, pass the address and the array to a procedure, read from the array in the procedure and write to the location using the address parameter. Messy, right?
Because of the dangerous nature of this option, it is not enabled when the -O option is specified. Noted ๐
- *
-fuse-list=filename* โ if-fscaffold-staticis enabled then use the filefilenamefor the initialization order of modules ๐. Whereas if-fscaffold-dynamicis enabled then use this file to force linking of all module ctors. Cannot be used if-fgen-module-list=is enabled. Pick a lane, babe. -fwholedivโ generate code to detect whole number division by zero or modulus by zero ๐-fwholevalueโ generate code to detect whole number overflow and underflow ๐ญ-Wcase-enumโ generates a warning if aCASEstatement selects on an enumerated type expression and the statement is missing one or moreCASElabels ๐ฆ. No warning gets issued if theCASEstatement has a defaultELSEclause โ she's covered, she's fine. The option-Wallwill turn on this flag.-Wuninit-variable-checkingโ issues a warning if a variable is used before it is initialized โญ. The checking only occurs in the first basic block in each procedure. It does not check parameters, array types or set types. (Yes, it's a little limited, we know, we love her anyway ๐)-Wuninit-variable-checking=all,known,condโ same deal, issues a warning if a variable is used before it is initialized โจ. The checking will only occur in the first basic block in each procedure ifknownis specified. Ifcondorallis specified, then checking continues into conditional branches of the flow graph ๐ฅ. All checking will stop when a procedure call is invoked or the top of a loop is encountered. The option-Wallwill turn on this flag with-Wuninit-variable-checking=known. And psst โ-Wuninit-variable-checking=allwill increase compile time, so budget accordingly ๐-fwidesetโ turns on access to the runtime support library moduleM2WIDESET๐. By default this option is on. Wideset provision can be disabled by-fno-wideset, and no reference will be made to the run timeM2WIDESETlibrary.
๐ SEE ALSO ๐
The squad ๐
: gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gm2 and gcc. Go say hi, they're all lovely ๐ซถ
๐ COPYRIGHT ๐
Copyright (c) 1999-2026 Free Software Foundation, Inc. ๐
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; with 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).
And that's a wrap on M2(1), bestie โจ This one's gcc-16, dated 2026-08-10, and it ate ๐
no cap. Go forth, compile responsibly, and remember: read the flags before you ship ๐ฆ๐
๐ฆ where this page comes from
- arch rolling: gcc-m2 16.2.1+r23+gd564253eb6c8-1 ยท GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms