dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with gdb testsuite C++ tests and -Wl,-T<linker-script>


From: Fred Fish
Subject: Problem with gdb testsuite C++ tests and -Wl,-T<linker-script>
Date: Tue, 10 Sep 2002 10:06:48 -0500 (CDT)

I have been going through the results of running the gdb testsuite on
a mips-elf toolchain and cleaning up the problems in gdb.  One of the
issues I ran into in the part of the testsuite that tests C++ support
is that when the testsuite tries to build a C++ test case, it issues a
command to the g++ driver that uses a -Wl option to pass a specific
-T<linker-script> option to the linker.  I.E. something like:

  mips-elf-g++ misc.o -Wl,-Tidt.ld -o misc 

However some of the test case compiles invoked this way are failing
because -Wl causes the -T option to be put in the middle of the linker
argument list instead of at the end.  Basically it just plops it in
wherever it naturally occurs because of the -Wl option.  If instead of
using -Wl you just use a -T option directly, then the compilation and
link succeed.  I.E. just change the command to:

  mips-elf-g++ misc.o -Tidt.ld -o misc 

The reason this works is that the gcc and g++ front ends know to take
any -T options and put them at the end of the linker command line.
This is hardcoded into the default linker specs in the gcc driver,
gcc.c.  See the "%{T*}" arg at the end of the argument list:

  #define LINK_COMMAND_SPEC "\
  %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
    %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
    %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
    %{static:} %{L*} %(link_libgcc) %o 
%{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
    %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"

As an example of a link time failure consider the gdb.c++/misc.exp
test.  Stripped down, the failure can be reproduced with:

  $ mips-elf-g++ misc.o -Wl,-Tidt.ld -o misc 
  .../libstdc++.a(eh_personality.o): In function `size_of_encoded_value':
  .../gcc/gcc/unwind-pe.h:76: undefined reference to `abort'

and the specific argument given to the linker is:

  /tools/lib/gcc-lib/mips-elf/3.3/collect2 -EB -o misc 
/tools/lib/gcc-lib/mips-elf/3.3/crti.o \
    /tools/lib/gcc-lib/mips-elf/3.3/crtbegin.o \
    -L/tools/lib/gcc-lib/mips-elf/3.3 
-L/tools/lib/gcc-lib/mips-elf/3.3/../../../../mips-elf/lib misc.o \
    -Tidt.ld -lstdc++ -lm -lgcc -lgcc \
    /tools/lib/gcc-lib/mips-elf/3.3/crtend.o 
/tools/lib/gcc-lib/mips-elf/3.3/crtn.o

When the "-Wl," is removed, I get:

  /tools/lib/gcc-lib/mips-elf/3.3/collect2 -EB -o misc 
/tools/lib/gcc-lib/mips-elf/3.3/crti.o \
    /tools/lib/gcc-lib/mips-elf/3.3/crtbegin.o \
    -L/tools/lib/gcc-lib/mips-elf/3.3 
-L/tools/lib/gcc-lib/mips-elf/3.3/../../../../mips-elf/lib misc.o \
    -lstdc++ -lm -lgcc -lgcc \
    /tools/lib/gcc-lib/mips-elf/3.3/crtend.o 
/tools/lib/gcc-lib/mips-elf/3.3/crtn.o \
    -Tidt.ld

I'm unsure of the best way to handle this problem.  Here are some
possible solutions:

(1) Remove all the "-Wl," prefixes from the ldscript options set in
the baseboard files.  This works, but perhaps will break in
environments where the compiler in use does handle "-Wl,-Tscript.ld"
but not "-Tscript.ld".  Its been a long time since I worked with any
compiler except gcc and perhaps there are some where the -Wl form
works but not the bare -T form.

(2) Strip off the -Wl prefix inside lib/target.exp, much like what
happens for default_link:

    if [board_info $board exists ldscript] {
        # strip leading -Wl, if present
        set ldscript [board_info $board ldscript]
        regsub "^-Wl," $ldscript "" ldscript
        append flags " $ldscript"
    }

Although this is the minimal change solution, this is probably less
desirable than (1) and has all the same draw backs.

(3) Test somewhere to see if the compiler in use is gcc/g++, and if so
then strip off the leading -Wl before actually invoking the compiler.
This would seem to be the best solution, but I'm not familiar enough
with dejagnu to know the best place to insert this test and do the
stripping.  Any suggestions?

Thanks.

-Fred




reply via email to

[Prev in Thread] Current Thread [Next in Thread]