On Mon, 16 Nov 2020 09:43:42 +0100
Fons Adriaensen <fons(a)linuxaudio.org> wrote:
Hello all,
I'm having a strange problem with G++...
In one source file 'fb3data.cc', I define arrays like this:
const float svcoeff44 [216] =
{
1.631996e-03, 6.335480e-02, ...
...
};
(...)
/usr/bin/ld: filtbank3.o: warning: relocation against `svcoeff88'
in
read-only section `.text'
Hi,
I've already seen this strange behavior with gcc 9.x : symbols with
a const definition are by default not publicly visible. It works
if you explicitly add an "extern" in the definition:
extern const float svcoeff44 [216] = (...)
I am not sure whether it is a bug in gcc or a strict application of the
standard.
"
C language issues
Default to -fno-common
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. If tentative definitions
of particular variables need to be placed in a common block,
__attribute__((__common__)) can be used to force that behavior even in
code compiled without -fcommon. As a workaround, legacy C code where
all tentative definitions should be placed into a common block can be
compiled with -fcommon.
int x; // tentative definition - avoid in header files
extern int y; // correct declaration in a header file
"
Guess that could explain it.