Skip to content

Fix compilation with -fno-common (new GCC 10 default)#818

Merged
natoscott merged 2 commits intoperformancecopilot:masterfrom
ddiss:gcc_no_common
Jan 13, 2020
Merged

Fix compilation with -fno-common (new GCC 10 default)#818
natoscott merged 2 commits intoperformancecopilot:masterfrom
ddiss:gcc_no_common

Conversation

@ddiss
Copy link
Copy Markdown
Contributor

@ddiss ddiss commented Jan 9, 2020

As described in https://bugzilla.opensuse.org/show_bug.cgi?id=1160244


Starting from the upcoming GCC release 10, the default of -fcommon option will change to -fno-common:

In C, global variables with multiple tentative definitions will result in linker errors. Global variable accesses are also more efficient on various targets.

Porting advice:

A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it
results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common,
which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. As a workaround, legacy C code can be compiled with -fcommon.

  int x;  // tentative definition - avoid in header files 
  extern int y;  // correct declaration in a header file 

Recommendations for package maintainers:

  • report the violation to upstream
  • cherry pick a fix from upsteam

ddiss added 2 commits January 9, 2020 12:54
SDS_NOINIT is currently declared in sds.h without extern, resulting in
multiple definitions across sds.h consumers.
With GCC 10, the default of -fcommon option will change to -fno-common,
resulting in an error:

Signed-off-by: David Disseldorp <ddiss@suse.de>
The global_version_major and global_version_minor variables are declared
in pmdacifs.h. Currently both cifs/pmda.c and cifs/stats.c carry
definitions, resulting in an error when compiling with -fno-common (a
new GCC 10 default).

Signed-off-by: David Disseldorp <ddiss@suse.de>
@ddiss
Copy link
Copy Markdown
Contributor Author

ddiss commented Jan 9, 2020

FWIW, I've also submitted the sds fix upstream via antirez/sds#120 , but given the backlog of PRs and lack of activity, I doubt it'll be merged there any time soon.

@natoscott natoscott merged commit cab300c into performancecopilot:master Jan 13, 2020
natoscott added a commit that referenced this pull request Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants