Bug 111315 - libstdc++ stacktrace testsuite failures with --enable-default-pie
Summary: libstdc++ stacktrace testsuite failures with --enable-default-pie
Status: RESOLVED DUPLICATE of bug 112263
Alias: None
Product: gcc
Classification: Unclassified
Component: libbacktrace (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: testsuite-fail
: 112322 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-09-07 03:49 UTC by Rimvydas (RJ)
Modified: 2023-11-06 23:13 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-09-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rimvydas (RJ) 2023-09-07 03:49:44 UTC
The GCC configured with --enable-default-pie gives:

                === libstdc++ tests ===

Running target unix
FAIL: 19_diagnostics/stacktrace/entry.cc execution test
FAIL: 19_diagnostics/stacktrace/stacktrace.cc execution test

libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc:39: void test_members(): Assertion 'e1.source_line() == (__LINE__ - 5)' failed.
libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc:132: void test_assign(): Assertion 's0.at(0).source_line() == (__LINE__ - 4)' failed.

In both cases source_line() methods return 0.

Also, the -fno-pie option cannot be used when linking these tescases:
/usr/bin/ld: /tmp/ccv2BTff.o: relocation R_X86_64_32 against symbol `_ZNSt16stacktrace_entry14_S_err_handlerEPvPKci' can not be used when making a PIE object; recompile with -fPIE
Comment 1 Andrew Pinski 2023-09-07 03:58:34 UTC
Hmm, is libbacktrace not working with PIE applications ...
Comment 2 Xi Ruoyao 2023-09-07 10:34:51 UTC
(In reply to Rimvydas (RJ) from comment #0)
> The GCC configured with --enable-default-pie gives:
> 
>                 === libstdc++ tests ===
> 
> Running target unix
> FAIL: 19_diagnostics/stacktrace/entry.cc execution test
> FAIL: 19_diagnostics/stacktrace/stacktrace.cc execution test
> 
> libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc:39: void
> test_members(): Assertion 'e1.source_line() == (__LINE__ - 5)' failed.
> libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc:132: void
> test_assign(): Assertion 's0.at(0).source_line() == (__LINE__ - 4)' failed.
> 
> In both cases source_line() methods return 0.
> 
> Also, the -fno-pie option cannot be used when linking these tescases:
> /usr/bin/ld: /tmp/ccv2BTff.o: relocation R_X86_64_32 against symbol
> `_ZNSt16stacktrace_entry14_S_err_handlerEPvPKci' can not be used when making
> a PIE object; recompile with -fPIE

You need to use both -no-pie and -fno-pie.  -fno-pie only tells the compiler not to emit code for PIE, -no-pie tells the linker not to link the code for PIE.
Comment 3 Xi Ruoyao 2023-09-07 10:38:12 UTC
Confirm the issue anyway, I saw it several times recently.
Comment 4 Andrew Pinski 2023-10-31 20:06:56 UTC
*** Bug 112322 has been marked as a duplicate of this bug. ***
Comment 5 Xi Ruoyao 2023-11-03 10:03:06 UTC
Maybe related to PR112263 but I'm not sure.
Comment 6 Rimvydas (RJ) 2023-11-03 16:26:43 UTC
(In reply to Xi Ruoyao from comment #5)
> Maybe related to PR112263 but I'm not sure.

Can confirm that with patch posted at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112263#c7 the stacktrace.cc testsuite testcases (for both -std=gnu++23 and -std=gnu++26) now able to pass execution tests when gcc is built with ./configure --enable-bootstrap --enable-default-pie

--- libstdc++-v3/src/libbacktrace/Makefile.orig
+++ libstdc++-v3/src/libbacktrace/Makefile
@@ -232,3 +232,3 @@
 AWK = gawk
-BACKTRACE_CPPFLAGS =  -DHAVE_ATOMIC_FUNCTIONS=1 -DHAVE_SYNC_FUNCTIONS=1 -DHAVE_FCNTL=1 -DBACKTRACE_ELF_SIZE=64
+BACKTRACE_CPPFLAGS = -D_GNU_SOURCE -DHAVE_ATOMIC_FUNCTIONS=1 -DHAVE_SYNC_FUNCTIONS=1 -DHAVE_DL_ITERATE_PHDR=1 -DHAVE_FCNTL=1 -DBACKTRACE_ELF_SIZE=64
 BACKTRACE_SUPPORTED = 1
Comment 7 Jonathan Wakely 2023-11-03 16:32:28 UTC
Great, let's close it as a dup then.

*** This bug has been marked as a duplicate of bug 112263 ***
Comment 8 GCC Commits 2023-11-06 23:11:59 UTC
The master branch has been updated by Ian Lance Taylor <ian@gcc.gnu.org>:

https://gcc.gnu.org/g:2b64e4a54042fb8f75f1c1429eb1c13afb9fa118

commit r14-5173-g2b64e4a54042fb8f75f1c1429eb1c13afb9fa118
Author: Ian Lance Taylor <iant@golang.org>
Date:   Mon Nov 6 15:09:18 2023 -0800

    libstdc++: use -D_GNU_SOURCE when building libbacktrace
    
            PR libbacktrace/111315
            PR libbacktrace/112263
            * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when
            grepping link.h for dl_iterate_phdr.
            * configure: Regenerate.
Comment 9 GCC Commits 2023-11-06 23:12:34 UTC
The releases/gcc-13 branch has been updated by Ian Lance Taylor <ian@gcc.gnu.org>:

https://gcc.gnu.org/g:8484e3479fe80aebdc4a2406473aef906055b4f8

commit r13-8006-g8484e3479fe80aebdc4a2406473aef906055b4f8
Author: Ian Lance Taylor <iant@golang.org>
Date:   Mon Nov 6 15:12:05 2023 -0800

    libstdc++: use -D_GNU_SOURCE when building libbacktrace
    
            PR libbacktrace/111315
            PR libbacktrace/112263
            * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when
            grepping link.h for dl_iterate_phdr.
            * configure: Regenerate.
Comment 10 GCC Commits 2023-11-06 23:13:03 UTC
The releases/gcc-12 branch has been updated by Ian Lance Taylor <ian@gcc.gnu.org>:

https://gcc.gnu.org/g:56909c9d4842925749cd9e061ef4afa0501f85e9

commit r12-9961-g56909c9d4842925749cd9e061ef4afa0501f85e9
Author: Ian Lance Taylor <iant@golang.org>
Date:   Mon Nov 6 15:12:41 2023 -0800

    libstdc++: use -D_GNU_SOURCE when building libbacktrace
    
            PR libbacktrace/111315
            PR libbacktrace/112263
            * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when
            grepping link.h for dl_iterate_phdr.
            * configure: Regenerate.