public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcov fails to work with shared library on 64bit platform
@ 2011-05-13 13:15 Mu Qiao
  2011-05-13 14:50 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Mu Qiao @ 2011-05-13 13:15 UTC (permalink / raw)
  To: gcc-help

Hello,

I have a C++ shared library project. When I add "--coverage" to
CXXFLAGS(I also added -g and -O0) and LDFLAGS, the project fails to
compile, here's the error message:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
.libs/variable_printer: hidden symbol `atexit' in
/usr/lib64/libc_nonshared.a(atexit.oS) is referenced by DSO
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[1]: *** [variable_printer] Error 1
make[1]: *** Waiting for unfinished jobs....
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
.libs/metadata_generator: hidden symbol `atexit' in
/usr/lib64/libc_nonshared.a(atexit.oS) is referenced by DSO
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status

variable_printer and metadata_generator are two utilities that are
linked against the shared libraries. The above error only occurs on
64bit platform. It works fine on 32bit platform. I tried with
"configure --disable-shared" and it worked for us. But I don't know
the reason of the above error and can't be sure if --disable-shared is
the correct solution.

-- 
Best wishes,
Mu Qiao
GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1 57E9

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcov fails to work with shared library on 64bit platform
  2011-05-13 13:15 gcov fails to work with shared library on 64bit platform Mu Qiao
@ 2011-05-13 14:50 ` Ian Lance Taylor
  2011-05-14  2:41   ` Mu Qiao
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2011-05-13 14:50 UTC (permalink / raw)
  To: Mu Qiao; +Cc: gcc-help

Mu Qiao <qiaomuf@gmail.com> writes:

> I have a C++ shared library project. When I add "--coverage" to
> CXXFLAGS(I also added -g and -O0) and LDFLAGS, the project fails to
> compile, here's the error message:
>
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
> .libs/variable_printer: hidden symbol `atexit' in
> /usr/lib64/libc_nonshared.a(atexit.oS) is referenced by DSO
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
> final link failed: Nonrepresentable section on output
> collect2: ld returned 1 exit status
> make[1]: *** [variable_printer] Error 1

The linker message is not very helpful in that it doesn't tell us where
the hidden symbol is referenced from.  At a guess, the reference is from
your C++ shared library.  You can verify that by using "readelf -r" and
"readelf -s" on the shared library and looking for atexit.  If you find
it there as an undefined symbol, then what is the command that you use
to build your shared library?

> I tried with
> "configure --disable-shared" and it worked for us. But I don't know
> the reason of the above error and can't be sure if --disable-shared is
> the correct solution.

Which configure script do you mean here?  The gcc configure script or
yours?

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcov fails to work with shared library on 64bit platform
  2011-05-13 14:50 ` Ian Lance Taylor
@ 2011-05-14  2:41   ` Mu Qiao
  2011-05-14  6:18     ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Mu Qiao @ 2011-05-14  2:41 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

On Fri, May 13, 2011 at 10:49 PM, Ian Lance Taylor <iant@google.com> wrote:
> Mu Qiao <qiaomuf@gmail.com> writes:
>
>> I have a C++ shared library project. When I add "--coverage" to
>> CXXFLAGS(I also added -g and -O0) and LDFLAGS, the project fails to
>> compile, here's the error message:
>>
>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
>> .libs/variable_printer: hidden symbol `atexit' in
>> /usr/lib64/libc_nonshared.a(atexit.oS) is referenced by DSO
>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
>> final link failed: Nonrepresentable section on output
>> collect2: ld returned 1 exit status
>> make[1]: *** [variable_printer] Error 1
>
> The linker message is not very helpful in that it doesn't tell us where
> the hidden symbol is referenced from.  At a guess, the reference is from
> your C++ shared library.  You can verify that by using "readelf -r" and
> "readelf -s" on the shared library and looking for atexit.  If you find
> it there as an undefined symbol, then what is the command that you use
> to build your shared library?
>

I find this line in the output of readelf -s:
18447: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND atexit

These are the flags I used for compiling:
-D_GLIBCXX_DEBUG -std=c++0x -Wall -Wextra -Wold-style-cast
-Woverloaded-virtual -Wsign-promo -pedantic-errors -Werror --coverage
-fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC -DPIC

This is the command for linking:

libtool: link: g++ -shared -nostdlib
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/crtbeginS.o
src/.libs/libcppbash_la-libbash.o
src/.libs/libcppbash_la-cppbash_builtin.o
src/builtins/.libs/libcppbash_la-echo_builtin.o
src/builtins/.libs/libcppbash_la-source_builtin.o
src/builtins/.libs/libcppbash_la-return_builtin.o
src/builtins/.libs/libcppbash_la-inherit_builtin.o
.libs/libcppbash_la-libbashLexer.o .libs/libcppbash_la-libbashParser.o
src/core/.libs/libcppbash_la-interpreter.o
src/core/.libs/libcppbash_la-bash_ast.o  -Wl,--whole-archive
./.libs/libwalker.a -Wl,--no-whole-archive  -lantlr3c
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../.. -lstdc++ -lm -lc
-lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64/crtn.o
--coverage   -Wl,-soname -Wl,libcppbash.so.0 -o
.libs/libcppbash.so.0.0.0

I googled and some people say that -nostdlib in the linking command
caused the problem. But the command is run by libtool. I don't know
what to do with it except applying a patch.

>> I tried with
>> "configure --disable-shared" and it worked for us. But I don't know
>> the reason of the above error and can't be sure if --disable-shared is
>> the correct solution.
>
> Which configure script do you mean here?  The gcc configure script or
> yours?
>

I mean my configure script. "configure --diable-shared" works fine on
both 32bit and 64bit machine.

-- 
Best wishes,
Mu Qiao
GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1 57E9

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcov fails to work with shared library on 64bit platform
  2011-05-14  2:41   ` Mu Qiao
@ 2011-05-14  6:18     ` Ian Lance Taylor
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2011-05-14  6:18 UTC (permalink / raw)
  To: Mu Qiao; +Cc: gcc-help

Mu Qiao <qiaomuf@gmail.com> writes:

> On Fri, May 13, 2011 at 10:49 PM, Ian Lance Taylor <iant@google.com> wrote:
>> Mu Qiao <qiaomuf@gmail.com> writes:
>>
>>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
>>> .libs/variable_printer: hidden symbol `atexit' in
>>> /usr/lib64/libc_nonshared.a(atexit.oS) is referenced by DSO
>>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld:
>>> final link failed: Nonrepresentable section on output
>>> collect2: ld returned 1 exit status
>>> make[1]: *** [variable_printer] Error 1
>>
>> The linker message is not very helpful in that it doesn't tell us where
>> the hidden symbol is referenced from.  At a guess, the reference is from
>> your C++ shared library.  You can verify that by using "readelf -r" and
>> "readelf -s" on the shared library and looking for atexit.  If you find
>> it there as an undefined symbol, then what is the command that you use
>> to build your shared library?
>>
>
> I find this line in the output of readelf -s:
> 18447: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND atexit
>
> These are the flags I used for compiling:
> -D_GLIBCXX_DEBUG -std=c++0x -Wall -Wextra -Wold-style-cast
> -Woverloaded-virtual -Wsign-promo -pedantic-errors -Werror --coverage
> -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC -DPIC
>
> This is the command for linking:
>
> libtool: link: g++ -shared -nostdlib
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64/crti.o
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/crtbeginS.o
> src/.libs/libcppbash_la-libbash.o
> src/.libs/libcppbash_la-cppbash_builtin.o
> src/builtins/.libs/libcppbash_la-echo_builtin.o
> src/builtins/.libs/libcppbash_la-source_builtin.o
> src/builtins/.libs/libcppbash_la-return_builtin.o
> src/builtins/.libs/libcppbash_la-inherit_builtin.o
> .libs/libcppbash_la-libbashLexer.o .libs/libcppbash_la-libbashParser.o
> src/core/.libs/libcppbash_la-interpreter.o
> src/core/.libs/libcppbash_la-bash_ast.o  -Wl,--whole-archive
> ./.libs/libwalker.a -Wl,--no-whole-archive  -lantlr3c
> -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2
> -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64
> -L/lib/../lib64 -L/usr/lib/../lib64
> -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/lib
> -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../.. -lstdc++ -lm -lc
> -lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/crtendS.o
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64/crtn.o
> --coverage   -Wl,-soname -Wl,libcppbash.so.0 -o
> .libs/libcppbash.so.0.0.0
>
> I googled and some people say that -nostdlib in the linking command
> caused the problem. But the command is run by libtool. I don't know
> what to do with it except applying a patch.


Yes, this problem is coming from -nostdlib.  That is telling g++ to not
link against -lc, which means that there is no definition of atexit.

If this command is coming from libtool then you need to talk to the
libtool maintainers to find out why they are using -nostdlib.  Or I
suppose you could explicitly link against -lc.


>>> I tried with
>>> "configure --disable-shared" and it worked for us. But I don't know
>>> the reason of the above error and can't be sure if --disable-shared is
>>> the correct solution.
>>
>> Which configure script do you mean here?  The gcc configure script or
>> yours?
>>
>
> I mean my configure script. "configure --diable-shared" works fine on
> both 32bit and 64bit machine.

If this works for you, there is nothing wrong with doing that.  Of
course, then you don't get a shared library.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-14  6:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-13 13:15 gcov fails to work with shared library on 64bit platform Mu Qiao
2011-05-13 14:50 ` Ian Lance Taylor
2011-05-14  2:41   ` Mu Qiao
2011-05-14  6:18     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).