Help disabling -fno-common hack

A while ago upstream gcc-10and upstream clang-11 switched from default -fcommon to default -fno-common value. 85678 – -fno-common should be default , Porting to GCC 10 - GNU Project


From user’s standpoint it turns C code with multiple global definitions an error.

I’ll take example from

// a.c
int a = 42;
// main.c
int a;
int main(){}
$ gcc -fno-common a.c main.c -o main
ld: a.o:(.bss+0x0): multiple definition of `a'; main.o:(.data+0x0): first defined here
collect2: error: ld returned 1 exit status

The fix is usually move variable definition into a single place:

// main.c (fixed)
extern int a;
int main(){}

nixpkgs workaround

To avoid widespread breakage nixpkgs flipped -fcommon back with nixpkgs/configure-flags.nix at 7fc3b44debd3a91f2e93953b06262533f686aeea · NixOS/nixpkgs · GitHub

    # Make -fcommon default on gcc10
    # TODO: fix all packages (probably 100+) and remove that
    ++ lib.optional (version >= "10.1.0") "--with-specs=%{!fno-common:%{!fcommon:-fcommon}}"

and a similar lack for llvm: nixpkgs/default.nix at 62745b65f4684a4772bd70fdfa09669a9c6af874 · NixOS/nixpkgs · GitHub

what you can do

Year(s) later many upstreams fixed -fno-common incompatibility one way or another. I’d like nixpkgs to drop the workaround. Sometimes it masks real bugs when global variable is reused by accident.

Before doing that we need to fix or workaround a few broken packages.

I collected incomplete list of candidates in the comment

Example fix: upstream, nixpkgs
Example workaround: nixpkgs

  1. You can report breakages of your packages by building them with -fno-common:
$ nix build -L --impure --expr 'with import <nixpkgs> {}; g15daemon.overrideAttrs (oa: {   NIX_CFLAGS_COMPILE = "-fno-common " + (oa.NIX_CFLAGS_COMPILE or ""); })'
g15daemon> .../ld: g15_plugins.o:/build/g15daemon- multiple definition of `lcdnode_s'; utility_funcs.o:/build/g15daemon- first defined here
  1. You can send fixes in upstream packages and in downstream nix expressions.

Thank you!


We already fixed ~170 packages! These are all packages from initial list.

In case you you’d still like a package to fix there now is a hydra jobset that targets toolchains without -fno-common hack. So far it uncovered ~40 more unfixed packages. The list will keep growing for next 2-3 days. It already found small set of darwin-specific failures: lsof, retroarchBare and sketchybar.


Hydra run uncovered about 70 more packages. All of the known failures were fixed or worked around by pushing a hack into individual packages.

Final PR to make the switch is up for review:

Hosted by Flying Circus.