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

background

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

I’ll take example from https://wiki.gentoo.org/wiki/Project:Toolchain/Gcc_10_porting_notes/fno_common:

// 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 https://github.com/NixOS/nixpkgs/blob/7fc3b44debd3a91f2e93953b06262533f686aeea/pkgs/development/compilers/gcc/common/configure-flags.nix#L225-L227

    # 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: https://github.com/NixOS/nixpkgs/blob/62745b65f4684a4772bd70fdfa09669a9c6af874/pkgs/development/compilers/llvm/11/clang/default.nix#L53-L64

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-1.9.5.3/g15daemon/g15daemon.h:203: multiple definition of `lcdnode_s'; utility_funcs.o:/build/g15daemon-1.9.5.3/g15daemon/g15daemon.h:203: first defined here
  1. You can send fixes in upstream packages and in downstream nix expressions.

Thank you!

5 Likes

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.

3 Likes

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: treewide: migrate to -fno-common by Gaelan · Pull Request #110571 · NixOS/nixpkgs · GitHub