[patch] Improve linker errors for missing key method definitions

Jeffrey Yasskin jyasskin@google.com
Thu Jul 15 23:36:00 GMT 2010


Hi Mark. You seem to have modified code around key methods most
recently of the C++ maintainers, so I was wondering if you could take
a look at this patch?

On Tue, Jul 13, 2010 at 7:31 PM, Jeffrey Yasskin <jyasskin@google.com> wrote:
> Andrew also pointed out that this will fix http://gcc.gnu.org/PR42540.
>
> On Tue, Jul 13, 2010 at 3:17 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>> I notice you don't test inline functions which could be key functions.
>>  Is there a reason behind that (like arm-eabi C++ ABI's key function
>> is slightly different from the other ABIs)?
>
> No, I just forgot about them. Here's a new patch that does test them.
> Testing with:
>
> build/gcc$ make check-g++ RUNTESTFLAGS="--target_board=arm-sim diagnostic.exp"
>
> passes, where diagnostic.exp is a small file pointing at just the
> tests in gcc/testsuite/g++.dg/diagnostic/. I couldn't find
> instructions on using qemu, and Richard Earnshaw's hint at
> http://www.mail-archive.com/gcc@gcc.gnu.org/msg43448.html wasn't
> enough to point me in the right direction.
>
>>  How does this interactive
>> with LTO (in that using -r at link time and then linking the final
>> result)?
>
> $ cat test.cc
> struct Poly {
>  virtual void KeyMethod();
>  virtual ~Poly();
> };
>
> int main() {
>  Poly p;
> }
> $ cat poly.cc
> struct Poly {
>  virtual void KeyMethod();
>  virtual ~Poly();
> };
>
> Poly::~Poly() {}
> //void Poly::KeyMethod() {}
>
> $ g++-4.6svn -fuse-key-methods -O3 -flto test.cc poly.cc -o test
> /tmp/ccW501Jx.o: In function `main':
> test.cc:(.text+0xb): undefined reference to `vtable for Poly'
> /tmp/ccW501Jx.o: In function `__use_needed_key_methods()':
> test.cc:(.text+0x21): undefined reference to `Poly::KeyMethod()'
> /tmp/cczIIliN.o: In function `Poly::~Poly()':
> poly.cc:(.text+0x3): undefined reference to `vtable for Poly'
> /tmp/cczIIliN.o: In function `Poly::~Poly()':
> poly.cc:(.text+0x13): undefined reference to `vtable for Poly'
> /tmp/cczIIliN.o: In function `__use_needed_key_methods()':
> poly.cc:(.text+0x21): undefined reference to `Poly::KeyMethod()'
> collect2: ld returned 1 exit status
>
> that's the same as without -flto. Partial linking with -r doesn't seem
> to change the result either.
>
> Thanks for taking a look,
> Jeffrey
>



More information about the Gcc-patches mailing list