Bug 262709 - -pg profiling not available on arm64 [fails with undefined symbol: .mcount]
Summary: -pg profiling not available on arm64 [fails with undefined symbol: .mcount]
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.0-STABLE
Hardware: arm64 Any
: --- Affects Only Me
Assignee: Andrew Turner
URL: https://reviews.freebsd.org/D34634
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-21 19:24 UTC by Yuri Victorovich
Modified: 2022-04-19 10:48 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2022-03-21 19:24:01 UTC
Testcase: port biology/dsr-pdb @ rev.cf118ccf875508b9a1c570044c93cfcc82bd455c

Error:
> ld: error: undefined symbol: .mcount
Comment 1 Ed Maste freebsd_committer freebsd_triage 2022-03-21 23:30:36 UTC
This port seems to unconditionally pass -pg:

work/dsr-pdb-1.0.3/lib/Makefile.am
5:AM_CPPFLAGS = -I../include -pg

work/dsr-pdb-1.0.3/lib/Makefile.in
183:AM_CPPFLAGS = -I../include -pg
Comment 2 Mark Millard 2022-03-22 01:25:44 UTC
(In reply to Ed Maste from comment #1)

To go along with your note, I'll quote main's [so: 14's]
"man src.conf":

QUOTE
     WITH_PROFILE
             Build profiled libraries for use with gprof(8).  This option is
             deprecated and is not present in FreeBSD 14.
END QUOTE

So, going forward to after stable/13 , it would not be
just aarch64 that would not work.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2022-03-22 03:59:42 UTC
The -pg option still works in main / 14, it's just that we don't build special versions of the system libraries already compiled with -pg.
Comment 4 Mark Millard 2022-03-22 05:33:04 UTC
(In reply to Ed Maste from comment #3)

If that is not what leads to "undefined symbol: .mcount",
then sorry for the noise.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2022-03-22 13:01:17 UTC
(In reply to Mark Millard from comment #4)
Looks like the issue is just that we don't have the low-level mcount bits on arm64; see sys/arm64/include/profile.h and compare with sys/amd64/include/profile.h.

See also
NetBSD sys/arch/aarch64/include/profile.h
OpenBSD sys/arch/arm64/include/profile.h
Comment 6 Andrew Turner freebsd_committer freebsd_triage 2022-03-22 16:35:50 UTC
See https://reviews.freebsd.org/D34634 for an implementation of .mcount for arm64.
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-03-23 15:32:02 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=16d5f9a1649e6a3e5841c6c41d6af9430ed9f064

commit 16d5f9a1649e6a3e5841c6c41d6af9430ed9f064
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-03-22 15:46:15 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-03-23 15:16:59 +0000

    Add an implementation of .mcount on arm64

    To support cc -pg on arm64 we need to implement .mcount. As clang and
    gcc think it is function like it just needs to load the arguments
    to _mcount and call it.

    On gcc the first argument is passed in x0, however this is missing on
    clang so we need to load it from the stack. As it's the caller return
    address this will be at a known location.

    PR:             262709
    Reviewed by:    emaste (earlier version)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D34634

 lib/libc/aarch64/Symbol.map |  1 +
 sys/arm64/include/profile.h | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2022-04-19 10:05:56 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2e38975e5aa41c576b87e5766b51d28fed0034ee

commit 2e38975e5aa41c576b87e5766b51d28fed0034ee
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-03-22 15:46:15 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-04-19 09:18:02 +0000

    Add an implementation of .mcount on arm64

    To support cc -pg on arm64 we need to implement .mcount. As clang and
    gcc think it is function like it just needs to load the arguments
    to _mcount and call it.

    On gcc the first argument is passed in x0, however this is missing on
    clang so we need to load it from the stack. As it's the caller return
    address this will be at a known location.

    PR:             262709
    Reviewed by:    emaste (earlier version)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D34634

    (cherry picked from commit 16d5f9a1649e6a3e5841c6c41d6af9430ed9f064)

 lib/libc/aarch64/Symbol.map |  1 +
 sys/arm64/include/profile.h | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)