NetBSD Problem Report #56876
From www@netbsd.org Fri Jun 10 22:08:45 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 0DDD91A921F
for <gnats-bugs@gnats.NetBSD.org>; Fri, 10 Jun 2022 22:08:45 +0000 (UTC)
Message-Id: <20220610220843.473BA1A923C@mollari.NetBSD.org>
Date: Fri, 10 Jun 2022 22:08:43 +0000 (UTC)
From: tgl@sss.pgh.pa.us
Reply-To: tgl@sss.pgh.pa.us
To: gnats-bugs@NetBSD.org
Subject: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
X-Send-Pr-Version: www-1.0
>Number: 56876
>Category: port-hppa
>Synopsis: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-hppa-maintainer
>State: feedback
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jun 10 22:10:00 +0000 2022
>Closed-Date:
>Last-Modified: Sat Feb 25 22:10:01 +0000 2023
>Originator: Tom Lane
>Release: HEAD/202206081310Z
>Organization:
PostgreSQL Global Development Group
>Environment:
NetBSD sss2.sss.pgh.pa.us 9.99.97 NetBSD 9.99.97 (SD0) #3: Thu Jun 9 15:19:02 EDT 2022 tgl@nuc1.sss.pgh.pa.us:/home/tgl/netbsd-H-202206081310Z/obj.hppa/sys/arch/hppa/compile/SD0 hppa
>Description:
Eyeing the (gratifyingly short) list of remaining /usr/tests failures on HPPA, I notice that half a dozen of them boil down to "the -pg switch doesn't work". You get a link failure complaining about mprotect(). I can't find any evidence that mprotect() is treated any differently on HPPA than any other arch, so I'm pretty mystified by this.
>How-To-Repeat:
$ cat hello.c
#include <stdio.h>
#include <stdlib.h>
int main(void) {printf("hello world\n");exit(0);}
$ cc -pg hello.c
ld: /usr/lib/libgcc_s.so: undefined reference to `mprotect'
Interestingly, if the program to be compiled itself references mprotect(), all is well:
$ cat mpro.c
#include <sys/mman.h>
int main(int argc, char **argv)
{
return mprotect(argv[0], 100, PROT_READ);
}
$ cc -pg mpro.c
$
>Fix:
Given the observation that a program-supplied mprotect reference fixes it, I suspect that there's some HPPA-specific problem in the rules for when to pull in an --as-needed library. I have little idea where to look though.
>Release-Note:
>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@netbsd.org
Cc: port-hppa-maintainer@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: re: port-hppa/56876: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
Date: Sat, 11 Jun 2022 08:25:32 +1000
in general, "-pg" requires "-static". what happens there?
.mrg.
From: Tom Lane <tgl@sss.pgh.pa.us>
To: gnats-bugs@netbsd.org, matthew green <mrg@eterna.com.au>
Cc: port-hppa-maintainer@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: port-hppa/56876: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
Date: Fri, 10 Jun 2022 18:59:41 -0400
matthew green <mrg@eterna.com.au> writes:
> in general, "-pg" requires "-static". what happens there?
Hmm ... that works:
$ cc -pg -static hello.c
$ ./a.out
hello world
[ plausible-looking gmon.out produced, too ]
Shall I send in a patch to add -static to all these tests that
are invoking -pg without it? Or is it supposed to work without
that these days? I don't see any such statement in modern gcc's
manual.
regards, tom lane
From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: port-hppa/56876: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
Date: Sat, 11 Jun 2022 03:51:54 -0000 (UTC)
tgl@sss.pgh.pa.us (Tom Lane) writes:
>$ cc -pg -static hello.c
>$ ./a.out
>hello world
>[ plausible-looking gmon.out produced, too ]
It should be automatic with modern gcc. E.g. netbsd-9/i386:
% cc -v
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/libexec/lto-wrapper
Target: i486--netbsdelf
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc/dist/configure --target=i486--netbsdelf --enable-long-long --enable-threads --with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD nb4 20200810' --with-system-zlib --without-isl --enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads --with-diagnostics-color=auto-if-env --with-arch=i486 --with-tune=nocona --with-default-libstdcxx-abi=new --with-mpc-lib=/var/obj/mknative/i386/usr/src/external/lgpl3/mpc/lib/libmpc --with-mpfr-lib=/var/obj/mknative/i386/usr/src/external/lgpl3/mpfr/lib/libmpfr --with-gmp-lib=/var/obj/mknative/i386/usr/src/external/lgpl3/gmp/lib/libgmp --with-mpc-include=/usr/src/external/lgpl3/mpc/dist/src --with-mpfr-include=/usr/src/external/lgpl3/mpfr/dist/src --with-gmp-include=/usr/src/external/lgpl3/gmp/lib/libgmp/arch/i386 --enable-tls --disable-multilib --disable-libstdcxx-pch --build=i486--netbsdelf --host=i486--netbsdelf --with-sysroot=/var/obj/mknative/i386
/usr/src/destdir.i386
Thread model: posix
gcc version 7.5.0 (nb4 20200810)
% cc c.c
% file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /usr/libexec/ld.elf_so, for NetBSD 9.2, not stripped
% cc -pg c.c
% file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for NetBSD 9.2, with debug_info, not stripped
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: port-hppa/56876: hppa: "cc -pg" fails with "undefined reference
to `mprotect'"
Date: Sat, 11 Jun 2022 08:36:35 +0200
On Sat, Jun 11, 2022 at 03:55:01AM +0000, Michael van Elst wrote:
> It should be automatic with modern gcc. E.g. netbsd-9/i386:
I think the specs are broken for several of our in-tree gcc, we should
audit them all for this issue.
Martin
From: Nick Hudson <nick.hudson@gmx.co.uk>
To: gnats-bugs@netbsd.org, port-hppa-maintainer@netbsd.org,
gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, tgl@sss.pgh.pa.us,
matthew green <mrg@eterna.com.au>
Cc:
Subject: Re: port-hppa/56876: hppa: "cc -pg" fails with "undefined reference
to `mprotect'"
Date: Sat, 11 Jun 2022 07:38:39 +0100
On 11/06/2022 00:00, Tom Lane wrote:
> The following reply was made to PR port-hppa/56876; it has been noted by=
GNATS.
>
> From: Tom Lane <tgl@sss.pgh.pa.us>
> To: gnats-bugs@netbsd.org, matthew green <mrg@eterna.com.au>
> Cc: port-hppa-maintainer@netbsd.org, netbsd-bugs@netbsd.org
> Subject: Re: port-hppa/56876: hppa: "cc -pg" fails with "undefined refer=
ence to `mprotect'"
> Date: Fri, 10 Jun 2022 18:59:41 -0400
>
> matthew green <mrg@eterna.com.au> writes:
> > in general, "-pg" requires "-static". what happens there?
>
> Hmm ... that works:
>
> $ cc -pg -static hello.c
> $ ./a.out
> hello world
> [ plausible-looking gmon.out produced, too ]
>
> Shall I send in a patch to add -static to all these tests that
> are invoking -pg without it? Or is it supposed to work without
> that these days? I don't see any such statement in modern gcc's
> manual.
I did this a little while ago
http://www.netbsd.org/~skrll/pg-static.diff
I think this is safer than trying to fix gcc specs with the netbsd-10
branch so close. We can also work on fixing the gcc specs.
Nick
From: "Nick Hudson" <skrll@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56876 CVS commit: src/tests/usr.bin
Date: Sun, 12 Jun 2022 08:55:36 +0000
Module Name: src
Committed By: skrll
Date: Sun Jun 12 08:55:36 UTC 2022
Modified Files:
src/tests/usr.bin/c++: asan_common.subr t_call_once.sh t_call_once2.sh
t_cxxruntime.sh t_fuzzer_oom.sh t_fuzzer_simple.sh
t_fuzzer_timeout.sh t_hello.sh t_msan_allocated_memory.sh
t_msan_check_mem.sh t_msan_free.sh t_msan_heap.sh
t_msan_partial_poison.sh t_msan_poison.sh t_msan_realloc.sh
t_msan_shadow.sh t_msan_stack.sh t_msan_unpoison.sh
t_pthread_once.sh t_static_destructor.sh t_tsan_data_race.sh
t_tsan_heap_use_after_free.sh t_tsan_lock_order_inversion.sh
t_tsan_locked_mutex_destroy.sh t_tsan_signal_errno.sh
t_tsan_thread_leak.sh t_tsan_vptr_race.sh ubsan_common.subr
src/tests/usr.bin/cc: asan_common.subr t_fuzzer_oom.sh
t_fuzzer_simple.sh t_fuzzer_timeout.sh t_hello.sh
t_msan_allocated_memory.sh t_msan_check_mem.sh t_msan_free.sh
t_msan_heap.sh t_msan_partial_poison.sh t_msan_poison.sh
t_msan_realloc.sh t_msan_shadow.sh t_msan_stack.sh
t_msan_unpoison.sh t_tsan_data_race.sh
t_tsan_heap_use_after_free.sh t_tsan_lock_order_inversion.sh
t_tsan_locked_mutex_destroy.sh t_tsan_signal_errno.sh
t_tsan_thread_leak.sh ubsan_common.subr
Log Message:
Sprinkle "-static" when using "-pg" as profiling only works with static and
the gcc specs are currently broken.
PR/56876: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/c++/asan_common.subr \
src/tests/usr.bin/c++/t_fuzzer_oom.sh \
src/tests/usr.bin/c++/t_fuzzer_simple.sh \
src/tests/usr.bin/c++/t_fuzzer_timeout.sh \
src/tests/usr.bin/c++/t_msan_allocated_memory.sh \
src/tests/usr.bin/c++/t_msan_check_mem.sh \
src/tests/usr.bin/c++/t_msan_free.sh src/tests/usr.bin/c++/t_msan_heap.sh \
src/tests/usr.bin/c++/t_msan_partial_poison.sh \
src/tests/usr.bin/c++/t_msan_poison.sh \
src/tests/usr.bin/c++/t_msan_realloc.sh \
src/tests/usr.bin/c++/t_msan_shadow.sh \
src/tests/usr.bin/c++/t_msan_stack.sh \
src/tests/usr.bin/c++/t_msan_unpoison.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/c++/t_call_once.sh \
src/tests/usr.bin/c++/t_call_once2.sh \
src/tests/usr.bin/c++/t_pthread_once.sh \
src/tests/usr.bin/c++/t_static_destructor.sh
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/c++/t_cxxruntime.sh \
src/tests/usr.bin/c++/t_hello.sh
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/c++/t_tsan_data_race.sh \
src/tests/usr.bin/c++/t_tsan_heap_use_after_free.sh \
src/tests/usr.bin/c++/t_tsan_lock_order_inversion.sh \
src/tests/usr.bin/c++/t_tsan_locked_mutex_destroy.sh \
src/tests/usr.bin/c++/t_tsan_signal_errno.sh \
src/tests/usr.bin/c++/t_tsan_thread_leak.sh \
src/tests/usr.bin/c++/t_tsan_vptr_race.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/c++/ubsan_common.subr
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/cc/asan_common.subr
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/cc/t_fuzzer_oom.sh \
src/tests/usr.bin/cc/t_fuzzer_simple.sh \
src/tests/usr.bin/cc/t_fuzzer_timeout.sh \
src/tests/usr.bin/cc/t_msan_allocated_memory.sh \
src/tests/usr.bin/cc/t_msan_check_mem.sh \
src/tests/usr.bin/cc/t_msan_free.sh src/tests/usr.bin/cc/t_msan_heap.sh \
src/tests/usr.bin/cc/t_msan_partial_poison.sh \
src/tests/usr.bin/cc/t_msan_poison.sh \
src/tests/usr.bin/cc/t_msan_realloc.sh \
src/tests/usr.bin/cc/t_msan_shadow.sh \
src/tests/usr.bin/cc/t_msan_stack.sh \
src/tests/usr.bin/cc/t_msan_unpoison.sh
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/cc/t_hello.sh
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/cc/t_tsan_data_race.sh \
src/tests/usr.bin/cc/t_tsan_heap_use_after_free.sh \
src/tests/usr.bin/cc/t_tsan_lock_order_inversion.sh \
src/tests/usr.bin/cc/t_tsan_locked_mutex_destroy.sh \
src/tests/usr.bin/cc/t_tsan_signal_errno.sh \
src/tests/usr.bin/cc/t_tsan_thread_leak.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/cc/ubsan_common.subr
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->feedback
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Thu, 16 Jun 2022 06:17:16 +0000
State-Changed-Why:
Workaround applied. OK to close?
From: Tom Lane <tgl@sss.pgh.pa.us>
To: gnats-bugs@netbsd.org
Cc: port-hppa-maintainer@netbsd.org
Subject: Re: port-hppa/56876 (hppa: "cc -pg" fails with "undefined reference to `mprotect'")
Date: Thu, 16 Jun 2022 09:36:20 -0400
skrll@NetBSD.org writes:
> Workaround applied. OK to close?
Hmm, I just did a full run from HEAD/202206150250Z, and I'm still
seeing failures in a lot of these tests:
usr.bin/c++/t_call_once:call_once_pic_profile
usr.bin/c++/t_call_once:call_once_profile
usr.bin/c++/t_cxxruntime:cxxruntime_pic_profile
usr.bin/c++/t_hello:hello_pic_profile
usr.bin/c++/t_pthread_once:pthread_once_pic_profile
usr.bin/c++/t_static_destructor:static_destructor_pic_profile
Some of them look like you missed adding -static there, but the
call_once_profile test does have that, and it's failing at runtime
instead of link time:
tc-start: 1655357349.87927, call_once_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o call_once test.cpp -L. -ltest -pthrea=
d ]
tc-so:Executing command [ ./call_once ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:./libtest.so: text relocations
tc-se:./libtest.so: Unsupported relocation type 2 in non-PLT relocations
tc-se:
tc-end: 1655357364.713581, call_once_pic_profile, failed, atf-check failed=
; see\
the output of the test for details
tc-start: 1655357379.351896, call_once_profile
tc-so:Executing command [ c++ -static -pg -o call_once test.cpp -pthread ]
tc-so:Executing command [ ./call_once ]
tc-se:Fail: program did not exit cleanly
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:
tc-end: 1655357394.885760, call_once_profile, failed, atf-check failed; se=
e the\
output of the test for details
tc-start: 1655357565.223298, cxxruntime_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o hello test.cpp -L. -ltest ]
tc-so:Executing command [ ./hello ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:./libtest.so: text relocations
tc-se:./libtest.so: Unsupported relocation type 2 in non-PLT relocations
tc-se:
tc-end: 1655357580.373063, cxxruntime_pic_profile, failed, atf-check faile=
d; se\
e the output of the test for details
tc-start: 1655357630.972360, hello_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o hello test.cpp -L. -ltest ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:ld: /usr/lib/libgcc_s.so: undefined reference to `mprotect'
tc-se:
tc-end: 1655357634.759712, hello_pic_profile, failed, atf-check failed; se=
e the\
output of the test for details
tc-start: 1655357670.940, pthread_once_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o pthread_once test.cpp -L. -ltest -pth=
read \
]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:ld: /usr/lib/libgcc_s.so: undefined reference to `mprotect'
tc-se:
tc-end: 1655357680.841495, pthread_once_pic_profile, failed, atf-check fai=
led; \
see the output of the test for details
tc-start: 1655357740.974899, static_destructor_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o hello test.cpp -L. -ltest ]
tc-so:Executing command [ ./hello ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:./libtest.so: text relocations
tc-se:./libtest.so: Unsupported relocation type 2 in non-PLT relocations
tc-se:
tc-end: 1655357756.269253, static_destructor_pic_profile, failed, atf-chec=
k fai\
led; see the output of the test for details
regards, tom lane
From: Tom Lane <tgl@sss.pgh.pa.us>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: port-hppa/56876: hppa: "cc -pg" fails with "undefined reference to `mprotect'"
Date: Sat, 25 Feb 2023 16:19:28 -0500
(GNATS is still bugging me about this report being in "feedback" state,
hopefully this will shut it up.)
I just ran the ATF tests against 10.0_BETA snapshot 202302240730Z,
and I am still seeing substantially the same failures as with
202206150250Z:
usr.bin/c++/t_call_once:call_once_pic_profile
usr.bin/c++/t_call_once:call_once_profile
usr.bin/c++/t_cxxruntime:cxxruntime_pic_profile
usr.bin/c++/t_hello:hello_pic_profile
usr.bin/c++/t_pthread_once:pthread_once_pic_profile
usr.bin/c++/t_static_destructor:static_destructor_pic_profile
tc-start: 1677309513.739028, call_once_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o call_once test.cpp -L. -ltest -pthrea=
d ]
tc-so:Executing command [ ./call_once ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:./libtest.so: text relocations
tc-se:./libtest.so: Unsupported relocation type 2 in non-PLT relocations
tc-se:
tc-end: 1677309529.346494, call_once_pic_profile, failed, atf-check failed=
; see the output of the test for details
tc-start: 1677309544.11978, call_once_profile
tc-so:Executing command [ c++ -static -pg -o call_once test.cpp -pthread ]
tc-so:Executing command [ ./call_once ]
tc-se:Fail: program did not exit cleanly
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:
tc-end: 1677309559.626921, call_once_profile, failed, atf-check failed; se=
e the output of the test for details
tc-start: 1677309730.580325, cxxruntime_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o hello test.cpp -L. -ltest ]
tc-so:Executing command [ ./hello ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:./libtest.so: text relocations
tc-se:./libtest.so: Unsupported relocation type 2 in non-PLT relocations
tc-se:
tc-end: 1677309745.668451, cxxruntime_pic_profile, failed, atf-check faile=
d; see the output of the test for details
tc-start: 1677309795.861917, hello_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o hello test.cpp -L. -ltest ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:ld: /usr/lib/libgcc_s.so: undefined reference to `mprotect'
tc-se:
tc-end: 1677309799.661230, hello_pic_profile, failed, atf-check failed; se=
e the output of the test for details
tc-start: 1677309907.624063, static_destructor_pic_profile
tc-so:Executing command [ c++ -pg -fPIC -shared -o libtest.so pic.cpp ]
tc-so:Executing command [ c++ -pg -o hello test.cpp -L. -ltest ]
tc-so:Executing command [ ./hello ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:./libtest.so: text relocations
tc-se:./libtest.so: Unsupported relocation type 2 in non-PLT relocations
tc-se:
tc-end: 1677309922.897904, static_destructor_pic_profile, failed, atf-chec=
k failed; see the output of the test for details
regards, tom lane
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.