Project:Toolchain/Gcc 10 porting notes/fno common
From Gentoo Wiki
< Project:Toolchain(Redirected from Gcc 10 porting notes/fno common)
Jump to:navigation
Jump to:search
Overview
gcc-10 and above flipped a default from -fcommon to -fno-common.
This changed gcc code generator to emit globals without explicit initializer from .bss (via COMMON symbol type) to .data (via DEFAULT symbol type).
Example
The problem
GCC will reject multiple definitions of global variables starting from gcc-10:
int a = 42;
int a;
int main(){}
user $
gcc 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 (source changes, preferred)
Explicitly mark declarations as such and avoid multiple definitions in order to fix the bug.
int a = 42;
extern int a;
int main(){}
The -fcommon workaround (discouraged)
If the problem is not that easy to fix or you are afraid it can break the program you then can report a bug upstream to make the decision on a correct fix.
As a local workaround you can revert back to old behaviour:
src_configure() {
# discouraged, source change fix is preferred
append-cflags -fcommon # https://link/to/upstream/bug/report
econf ...
}
Reproducing the build failure with older gcc versions
The following command can also be used to test your patch
user $
CFLAGS="-fno-common" ebuild mycat/mypkg-1.2.3 clean compile install
Links
- Upstream ticket: https://gcc.gnu.org/PR85678
- Tracker bug #705764
- This bug is topic of the Bugday 2020-06-06 and Bugday 2020-07-04