M2(1)

πŸ“¦ version 16.2.0+git9497, in opensuse-leap 16.0

πŸ’– NAME πŸ’–

Okay bestie, meet gm2 β€” the GNU Modula-2 Compiler. This is M2(1), part 1, and we’re gonna get through every flag together, no cap. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

(No synopsis lines here β€” the page is giving mysterious main character energy and moving straight along.)

🌸 DESCRIPTION 🌸

(No extra description lines in this part β€” the options are the main characters.)

πŸ’… OPTIONS πŸ’…

Okay so 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 as gdb can inspect and control the 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 to NIL. Whenever a block is created all pointers declared within this scope will have their addresses assigned to NIL. πŸŽ€
  • -fbounds β€” turns on run time subrange, array index and indirection via NIL pointer checking.
  • -fcase β€” turns on compile time checking to check whether a CASE statement requires an ELSE clause when one was not specified.
  • -fcpp β€” preprocess the source with cpp -lang-asm -traditional-cpp. For further details about these options: if -fcpp is supplied then all definition modules and implementation modules which are parsed will be prepossessed by cpp.
  • -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-exceptions and 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 ISO SYSTEM module and alters the default library search path so that the ISO libraries are searched before the PIM libraries. It also affects the behavior of DIV and MOD operators.
  • -flibs= β€” modifies the default library search path. The libraries supplied are: m2pim, m2iso, m2min, m2log and m2cor. 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=m2pim or -flibs=m2iso if you also specify -fpim, -fpim2, -fpim3, -fpim4 or -fiso. Unless you are using -flibs=m2min you should include m2pim because they provide the base modules which all other dialects utilize. The option -fno-libs=- disables the gm2 driver 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-filter is 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-gimple and -fdump-lang-quad on rules. rules must be a comma separated list which can take three forms: the full decl textual name of a procedure, [libname.]module.ident or [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 and -fm2-dump-filter=StrLib.mod:StrIO.WriteString.
  • -fm2-file-offset-bits= β€” force the type SYSTEM.COFF_T to be built using the specified number of bits. If this option is not used then default is CSSIZE_T bits.
  • -fm2-g β€” improve the debugging experience for new programmers at the expense of generating nop instructions if necessary to ensure single stepping precision over all code related keywords. An example of this is in termination of a list of nested IF statements where multiple END keywords are mapped onto a sequence of nop instructions.
  • -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 -I option.
  • -fm2-pathname-root=pathroot β€” add search paths derived from the specified pathroot.
  • -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 -I options.
  • -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 a NIL value pointer. Dereferencing checking through a NIL pointer can be disabled by -fno-nil.
  • -fpim β€” turn on PIM standard features. Currently this enables the PIM SYSTEM module 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 removes SIZE from being a pervasive identifier (declared in the base module). It places SIZE in the SYSTEM module. It also affects the behavior of DIV and MOD operators.
  • -fpim3 β€” turn on PIM-3 standard features. Currently this only affects the behavior of DIV and MOD operators.
  • -fpim4 β€” turn on PIM-4 standard features. Currently this only affects the behavior of DIV and MOD operators.
  • -fpositive-mod-floor-div β€” forces the DIV and MOD operators 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 the SYSTEM implementation 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 a RETURN and do not fall out at the end. Return checking can be disabled via -fno-return.
  • -fruntime-modules= β€” bestie you get to pick the run time modules and their order, comma separated, and they get initialized first before anything else in the application dependency πŸ’…. Default list is literally m2iso:RTentity,m2iso:Storage,m2iso:SYSTEM,m2iso:M2RTS,m2iso:RTExceptions,m2iso:IOLink. And no, adding a whole squad of dependent modules won't bloat your executable β€” they only get linked in if they're actually required, so the list is just saying "if they show up, init them in this order." Lowkey considerate of it tbh ✨
  • -fscaffold-dynamic β€” makes gm2 generate a dynamic scaffold infrastructure when compiling implementation and program modules. It's on by default, so no cap, you already have it 🫢. Want it gone? Use -fno-scaffold-dynamic to turn it off, or select -fno-scaffold-static.
  • -fscaffold-c β€” generate a C source scaffold for the module you're currently compiling. C-coded bestie behavior πŸŽ€
  • -fscaffold-c++ β€” same vibe, but generate a C++ source scaffold for the current module instead. Iconic of you honestly.
  • -fscaffold-main β€” forces the generation of the main function, main character energy obviously πŸ‘‘. Fr fr not necessary if -c is omitted.
  • -fscaffold-static β€” tells gm2 to generate a static scaffold inside the program module. This thing is a whole sequence of calls to every dependent module's initialization and finalization procedures, which makes it super useful for debugging and single stepping through the initialization blocks of implementation modules πŸ¦‹.
  • -fshared β€” generate a shared library from the module. Sharing is caring, periodt.
  • -fsoft-check-all β€” turns on all the run time checks at once. It's literally the same as invoking GNU Modula-2 with the command options -fnil -frange -findex -fwholevalue -fwholediv -fcase -freturn β€” one flag, seven vibes πŸ”₯.
  • -fsources β€” displays the path to the source of each module. Use it at compile time to check that the correct definition module is actually the one being used, iykyk βœ….
  • -fswig β€” generate a swig interface file. That's it, that's the whole thing πŸ’€.
  • -funbounded-by-reference β€” this one's spicy 🌢️. It enables optimization of unbounded parameters by attempting to pass non-VAR unbounded parameters by reference, which avoids the implicit copy happening inside the callee procedure. GNU Modula-2 will only allow an unbounded parameter to be passed by reference if, inside the callee procedure, it isn't written to, no address is calculated on the array, and it isn't passed as a VAR parameter.
Heads up bestie: it is possible to write code that breaks this optimization, so use it carefully πŸ™ˆ. For example you could take the address of an array, pass the address and the array to a procedure, read from the array inside the procedure, and then write to that location through the address parameter. Yeah. Chaos.

Due to the dangerous nature of this option, it is not enabled when the -O option is specified. Safety first, slay πŸ’–

  • -fuse-list=filename β€” if -fscaffold-static is enabled, then use the file filename for the initialization order of modules. Whereas if -fscaffold-dynamic is enabled, use this file to force linking of all module ctors. Cannot be used if -fgen-module-list= is enabled β€” those two do not coexist, no negotiation 🌸
  • -fwholediv β€” generate code to detect whole number division by zero or modulus by zero. Catch the zero before the zero catches you 🫢
  • -fwholevalue β€” generate code to detect whole number overflow and underflow. Guardrails, bestie, we love them ✨
  • -Wcase-enum β€” throws a warning if a CASE statement selects on an enumerated type expression and the statement is missing one or more CASE labels. No warning if the CASE statement has a default ELSE clause β€” the ELSE is your safety net πŸ•ΈοΈ. The option -Wall will turn on this flag.
  • -Wuninit-variable-checking β€” warns you if a variable is used before it's initialized. Checking only happens in the first basic block in each procedure, and it does not check parameters, array types or set types. So like... it's doing its best πŸ’€
  • -Wuninit-variable-checking=all,known,cond β€” same warning, but now with ✨modes✨. If known is specified, checking only happens in the first basic block in each procedure. If cond or all is specified, checking continues into the conditional branches of the flow graph. All checking stops when a procedure call is invoked or the top of a loop is encountered. The option -Wall will turn on this flag with -Wuninit-variable-checking=known, and the -Wuninit-variable-checking=all will increase compile time (worth it tho 🌈).
  • -fwideset β€” turns on access to the runtime support library module M2WIDESET. It's on by default πŸŽ€. You can disable wideset provision with -fno-wideset, and then no reference at all will be made to the run time M2WIDESET library.

✨ SEE ALSO ✨

gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gm2 and gcc. Go read them, they're giving required reading for the girlies πŸ“šπŸ’…

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) πŸ¦‹


okay that's the whole page bestie, go compile something iconic πŸ’– This masterpiece is from gcc-16, dated 2026-08-07 β€” that's the M2(1) page, signed, sealed, slayed πŸŽ€βœ¨