public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105671] New: Unexplained "undefined reference" error
@ 2022-05-20 10:06 christian.morales.vega at gmail dot com
  2022-05-20 10:08 ` [Bug c++/105671] " christian.morales.vega at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: christian.morales.vega at gmail dot com @ 2022-05-20 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105671
           Summary: Unexplained "undefined reference" error
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christian.morales.vega at gmail dot com
  Target Milestone: ---

Created attachment 53005
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53005&action=edit
Full verbose build log

I have found a strange issue in my project build that reproduces is Ubuntu
22.04 (gcc 11.2) and Fedora 36 (gcc 12.1.1). This is the most I have been able
to reduce it:

$ tar xf boost_1_79_0.tar.bz2 
$ cd boost_1_79_0/
$ ./bootstrap.sh
$ ./b2 --with-program_options link=static --user-config=$PWD/../user-config.jam
$ cd ..
$ g++ -o /dev/null test.cpp -Iboost_1_79_0
boost_1_79_0/stage/lib/libboost_program_options.a -Os -flto
/usr/bin/ld: /tmp/cccbpRrv.ltrans0.ltrans.o: in function
`boost::program_options::options_description::get_option_column_width() const':
<artificial>:(.text+0x28cd): undefined reference to
`std::__cxx11::basic_stringbuf<char, std::char_traits<char>,
std::allocator<char> >::_M_high_mark() const'
/usr/bin/ld: /tmp/cccbpRrv.ltrans0.ltrans.o: in function
`boost::program_options::(anonymous namespace)::format_one(std::ostream&,
boost::program_options::option_description const&, unsigned int, unsigned int)
[clone .constprop.0]':
<artificial>:(.text+0x2d80): undefined reference to
`std::__cxx11::basic_stringbuf<char, std::char_traits<char>,
std::allocator<char> >::_M_high_mark() const'
/usr/bin/ld: <artificial>:(.text+0x2e13): undefined reference to
`std::__cxx11::basic_stringbuf<char, std::char_traits<char>,
std::allocator<char> >::_M_high_mark() const'
/usr/bin/ld: <artificial>:(.text+0x3d40): undefined reference to
`std::__cxx11::basic_stringbuf<char, std::char_traits<char>,
std::allocator<char> >::_M_high_mark() const'
collect2: error: ld returned 1 exit status
$

I'm attaching a log showing the whole Boost.Program_options verbose build log.

- Change "-Os" for "-O1" and it works
- Remove the -supposedly unused- "#include <boost/asio/spawn.hpp>" line and it
works.

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

* [Bug c++/105671] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
@ 2022-05-20 10:08 ` christian.morales.vega at gmail dot com
  2022-05-26 23:09 ` [Bug libstdc++/105671] [11/12/13 Regression] " jsm28 at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: christian.morales.vega at gmail dot com @ 2022-05-20 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Cristian Morales Vega <christian.morales.vega at gmail dot com> ---
It's in the full verbose build log, but failed to include it here. These are
the contents of the files:

$ cat user-config.jam 
using gcc : : g++ : <cxxflags>"-flto" ;
$ cat test.cpp
#include <boost/asio/spawn.hpp>
#include <boost/program_options.hpp>
#include <iostream>

int
main()
{
    auto generic = boost::program_options::options_description{};
    std::cout << generic;
}

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

* [Bug libstdc++/105671] [11/12/13 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
  2022-05-20 10:08 ` [Bug c++/105671] " christian.morales.vega at gmail dot com
@ 2022-05-26 23:09 ` jsm28 at gcc dot gnu.org
  2022-05-27 10:19 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2022-05-26 23:09 UTC (permalink / raw)
  To: gcc-bugs

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

Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Unexplained "undefined      |[11/12/13 Regression]
                   |reference" error            |Unexplained "undefined
                   |                            |reference" error
                 CC|                            |jsm28 at gcc dot gnu.org
          Component|c++                         |libstdc++
   Target Milestone|---                         |11.4

--- Comment #2 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
I'm seeing the same undefined reference on a customer test case. I haven't
reduced it to a self-contained test case either, but as far as I can see this
is a libstdc++ issue (rather than a front-end or LTO bug). _M_high_mark (which
is new in libstdc++ in GCC 11) isn't exported from libstdc++.so (it's present
in libstdc++.a), presumably because the symbol version maps don't include it,
so if the compiler decides to inline one of the functions from the header that
calls _M_high_mark, without inlining _M_high_mark itself, there is an undefined
reference to _M_high_mark. (This selective inlining is what I haven't
reproduced in a self-contained test, even when adjusting various inlining
parameters, but it would explain the undefined reference.)

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

* [Bug libstdc++/105671] [11/12/13 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
  2022-05-20 10:08 ` [Bug c++/105671] " christian.morales.vega at gmail dot com
  2022-05-26 23:09 ` [Bug libstdc++/105671] [11/12/13 Regression] " jsm28 at gcc dot gnu.org
@ 2022-05-27 10:19 ` redi at gcc dot gnu.org
  2022-05-27 13:51 ` christian.morales.vega at gmail dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-27 10:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-05-27
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
           Priority|P3                          |P2

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Since we can't add the export to the release branches now, the simplest fix
might be to mark that function always_inline.

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

* [Bug libstdc++/105671] [11/12/13 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (2 preceding siblings ...)
  2022-05-27 10:19 ` redi at gcc dot gnu.org
@ 2022-05-27 13:51 ` christian.morales.vega at gmail dot com
  2022-05-27 14:23 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: christian.morales.vega at gmail dot com @ 2022-05-27 13:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Cristian Morales Vega <christian.morales.vega at gmail dot com> ---
I can confirm adding "__attribute__((always_inline))" in _M_high_mark() solves
the issue.

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

* [Bug libstdc++/105671] [11/12/13 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (3 preceding siblings ...)
  2022-05-27 13:51 ` christian.morales.vega at gmail dot com
@ 2022-05-27 14:23 ` cvs-commit at gcc dot gnu.org
  2022-05-27 14:25 ` [Bug libstdc++/105671] [11/12 " redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-27 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:de57440858591a88e8fd7ba2505ca54546c86021

commit r13-801-gde57440858591a88e8fd7ba2505ca54546c86021
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri May 27 12:43:18 2022 +0100

    libstdc++: Mark non-exported function always_inline [PR105671]

    This new function was added for gcc 11.1 but is not exported from the
    shared library. Depending on inlining decisions, its callers might get
    inlined but an external definition be needed for this function. That
    then fails to link.

    Since we can't add the export to the gcc-11 release branch now, mark it
    always_inline. We can consider exporting it for gcc-13 if/when we bump
    the shared library version (and maybe also for gcc-12 which is currently
    at the same version as trunk). For now, the attribute will solve the
    problem on all affected branches. The function is small enough that
    force-inlining it shouldn't cause problems.

    libstdc++-v3/ChangeLog:

            PR libstdc++/105671
            * include/std/sstream (basic_stringbuf::_M_high_mark): Add
            always_inline attribute.

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

* [Bug libstdc++/105671] [11/12 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (4 preceding siblings ...)
  2022-05-27 14:23 ` cvs-commit at gcc dot gnu.org
@ 2022-05-27 14:25 ` redi at gcc dot gnu.org
  2022-06-08 15:53 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-27 14:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13 Regression]       |[11/12 Regression]
                   |Unexplained "undefined      |Unexplained "undefined
                   |reference" error            |reference" error

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, I verified it using your test program (thanks!) against all affected
branches. It's fixed on trunk, I'll backport the attribute in a couple of
weeks.

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

* [Bug libstdc++/105671] [11/12 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (5 preceding siblings ...)
  2022-05-27 14:25 ` [Bug libstdc++/105671] [11/12 " redi at gcc dot gnu.org
@ 2022-06-08 15:53 ` cvs-commit at gcc dot gnu.org
  2022-06-08 16:10 ` [Bug libstdc++/105671] [11 " redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-08 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:d47c4f0f1da0aa84097878b82e100d08deb6d950

commit r12-8465-gd47c4f0f1da0aa84097878b82e100d08deb6d950
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri May 27 12:43:18 2022 +0100

    libstdc++: Mark non-exported function always_inline [PR105671]

    This new function was added for gcc 11.1 but is not exported from the
    shared library. Depending on inlining decisions, its callers might get
    inlined but an external definition be needed for this function. That
    then fails to link.

    Since we can't add the export to the gcc-11 release branch now, mark it
    always_inline. We can consider exporting it for gcc-13 if/when we bump
    the shared library version (and maybe also for gcc-12 which is currently
    at the same version as trunk). For now, the attribute will solve the
    problem on all affected branches. The function is small enough that
    force-inlining it shouldn't cause problems.

    libstdc++-v3/ChangeLog:

            PR libstdc++/105671
            * include/std/sstream (basic_stringbuf::_M_high_mark): Add
            always_inline attribute.

    (cherry picked from commit de57440858591a88e8fd7ba2505ca54546c86021)

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

* [Bug libstdc++/105671] [11 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (6 preceding siblings ...)
  2022-06-08 15:53 ` cvs-commit at gcc dot gnu.org
@ 2022-06-08 16:10 ` redi at gcc dot gnu.org
  2022-07-07 23:33 ` cvs-commit at gcc dot gnu.org
  2022-07-07 23:34 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-08 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12 Regression]          |[11 Regression] Unexplained
                   |Unexplained "undefined      |"undefined reference" error
                   |reference" error            |

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 12.2 as well.

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

* [Bug libstdc++/105671] [11 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (7 preceding siblings ...)
  2022-06-08 16:10 ` [Bug libstdc++/105671] [11 " redi at gcc dot gnu.org
@ 2022-07-07 23:33 ` cvs-commit at gcc dot gnu.org
  2022-07-07 23:34 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-07 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:03af8492bee6243a9d10e78fea1a3e423bd5f9cd

commit r11-10135-g03af8492bee6243a9d10e78fea1a3e423bd5f9cd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri May 27 12:43:18 2022 +0100

    libstdc++: Mark non-exported function always_inline [PR105671]

    This new function was added for gcc 11.1 but is not exported from the
    shared library. Depending on inlining decisions, its callers might get
    inlined but an external definition be needed for this function. That
    then fails to link.

    Since we can't add the export to the gcc-11 release branch now, mark it
    always_inline. We can consider exporting it for gcc-13 if/when we bump
    the shared library version (and maybe also for gcc-12 which is currently
    at the same version as trunk). For now, the attribute will solve the
    problem on all affected branches. The function is small enough that
    force-inlining it shouldn't cause problems.

    libstdc++-v3/ChangeLog:

            PR libstdc++/105671
            * include/std/sstream (basic_stringbuf::_M_high_mark): Add
            always_inline attribute.

    (cherry picked from commit de57440858591a88e8fd7ba2505ca54546c86021)

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

* [Bug libstdc++/105671] [11 Regression] Unexplained "undefined reference" error
  2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
                   ` (8 preceding siblings ...)
  2022-07-07 23:33 ` cvs-commit at gcc dot gnu.org
@ 2022-07-07 23:34 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-07 23:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 11.4 now too.

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

end of thread, other threads:[~2022-07-07 23:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 10:06 [Bug c++/105671] New: Unexplained "undefined reference" error christian.morales.vega at gmail dot com
2022-05-20 10:08 ` [Bug c++/105671] " christian.morales.vega at gmail dot com
2022-05-26 23:09 ` [Bug libstdc++/105671] [11/12/13 Regression] " jsm28 at gcc dot gnu.org
2022-05-27 10:19 ` redi at gcc dot gnu.org
2022-05-27 13:51 ` christian.morales.vega at gmail dot com
2022-05-27 14:23 ` cvs-commit at gcc dot gnu.org
2022-05-27 14:25 ` [Bug libstdc++/105671] [11/12 " redi at gcc dot gnu.org
2022-06-08 15:53 ` cvs-commit at gcc dot gnu.org
2022-06-08 16:10 ` [Bug libstdc++/105671] [11 " redi at gcc dot gnu.org
2022-07-07 23:33 ` cvs-commit at gcc dot gnu.org
2022-07-07 23:34 ` 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).