public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104918] New: Pass information to let the linker tell the user which virtual members are missing
@ 2022-03-14 13:59 eyalroz1 at gmx dot com
  2022-03-14 14:20 ` [Bug c++/104918] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: eyalroz1 at gmx dot com @ 2022-03-14 13:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104918

            Bug ID: 104918
           Summary: Pass information to let the linker tell the user which
                    virtual members are missing
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eyalroz1 at gmx dot com
  Target Milestone: ---

Consider the following program:

```
struct A {
    virtual void foo() { }
};

struct B : A {
    void foo() override;
};

int main() {
    B b;
}
```

this compiles, but fails to link: https://godbolt.org/z/Mzx3c7354
```
<source>:10: undefined reference to `vtable for B'
```
which is fine, but - I'm annoyed the linker doesn't tell me which virtual
member is missing. That might be an issue with the linker, but - is foo even a
symbol in the compiled code? I tried compiling this into an object file and
using objdump (on my GNU/Linux Devuan Chimaera), and got:

a.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    df *ABS*  0000000000000000 a.cpp
0000000000000000 l    d  .text  0000000000000000 .text
0000000000000000 l    d  .data  0000000000000000 .data
0000000000000000 l    d  .bss   0000000000000000 .bss
0000000000000000 l    d  .note.GNU-stack        0000000000000000
.note.GNU-stack
0000000000000000 l    d  .eh_frame      0000000000000000 .eh_frame
0000000000000000 l    d  .comment       0000000000000000 .comment
0000000000000000 g     F .text  0000000000000016 main
0000000000000000         *UND*  0000000000000000 vtable for B


So, no foo... and no way for the linker to be able to tell me what's missing.


I claim that GCC should expose information via the symbol table (or otherwise?)
that would let ld tell me which virtual member it's missing.

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

* [Bug c++/104918] Pass information to let the linker tell the user which virtual members are missing
  2022-03-14 13:59 [Bug c++/104918] New: Pass information to let the linker tell the user which virtual members are missing eyalroz1 at gmx dot com
@ 2022-03-14 14:20 ` redi at gcc dot gnu.org
  2022-03-14 14:27 ` eyalroz1 at gmx dot com
  2022-03-14 17:11 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-14 14:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104918

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The issue is that the vtable is missing, which is why the linker says so.

If the vtable is present, it does tell you about the missing virtual:
https://godbolt.org/z/zbfvTh74v

/opt/compiler-explorer/gcc-11.2.0/bin/../lib/gcc/x86_64-linux-gnu/11.2.0/../../../../x86_64-linux-gnu/bin/ld:
/tmp/ccI0XFwh.o:(.rodata._ZTV1B[_ZTV1B]+0x18): undefined reference to
`B::foo()'

I don't think there's anything for GCC to do here. Maybe the linker should
print a note after a missing vtable error saying that they key function needs
to be defined, which is already suggested at PR 42540.

See also https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_vtable

*** This bug has been marked as a duplicate of bug 42540 ***

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

* [Bug c++/104918] Pass information to let the linker tell the user which virtual members are missing
  2022-03-14 13:59 [Bug c++/104918] New: Pass information to let the linker tell the user which virtual members are missing eyalroz1 at gmx dot com
  2022-03-14 14:20 ` [Bug c++/104918] " redi at gcc dot gnu.org
@ 2022-03-14 14:27 ` eyalroz1 at gmx dot com
  2022-03-14 17:11 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: eyalroz1 at gmx dot com @ 2022-03-14 14:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104918

--- Comment #2 from Eyal Rozenberg <eyalroz1 at gmx dot com> ---
(In reply to Jonathan Wakely from comment #1)
> I don't think there's anything for GCC to do here.

Why not store information in the compiled object saying which virtual items are
undefined? The vtable was missing because some virtual members were
purely-virtual, right?

> Maybe the linker should
> print a note after a missing vtable error saying that they key function
> needs to be defined, which is already suggested at PR 42540.

Yes, that's what I'm saying... I'll comment on bug 42540.

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

* [Bug c++/104918] Pass information to let the linker tell the user which virtual members are missing
  2022-03-14 13:59 [Bug c++/104918] New: Pass information to let the linker tell the user which virtual members are missing eyalroz1 at gmx dot com
  2022-03-14 14:20 ` [Bug c++/104918] " redi at gcc dot gnu.org
  2022-03-14 14:27 ` eyalroz1 at gmx dot com
@ 2022-03-14 17:11 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-14 17:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104918

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Eyal Rozenberg from comment #2)
> Why not store information in the compiled object saying which virtual items
> are undefined? The vtable was missing because some virtual members were
> purely-virtual, right?

No, there are no pure virtual functions here. The vtable is missing because it
will be emitted in the same object file as the key function, and the key
function is not defined in the program. See the wiki link I gave.

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

end of thread, other threads:[~2022-03-14 17:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 13:59 [Bug c++/104918] New: Pass information to let the linker tell the user which virtual members are missing eyalroz1 at gmx dot com
2022-03-14 14:20 ` [Bug c++/104918] " redi at gcc dot gnu.org
2022-03-14 14:27 ` eyalroz1 at gmx dot com
2022-03-14 17:11 ` redi at gcc dot gnu.org

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).