A while ago upstream gcc-10
and 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 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
- 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
- You can send fixes in upstream packages and in downstream nix expressions.
Thank you!