Bug 262706 - Build on arm64 fails to find libclang_rt.asan-aarch64.a
Summary: Build on arm64 fails to find libclang_rt.asan-aarch64.a
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-21 17:46 UTC by Yuri Victorovich
Modified: 2024-05-09 16:33 UTC (History)
9 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 17:46:10 UTC
Testcase: Port net-im/toxex @ rev.b261f70d7a8c5bc65839db4f25b9992a4afcf069

Error:
> ld: error: cannot open /usr/lib/clang/11.0.1/lib/freebsd/libclang_rt.asan-aarch64.a: No such file or directory
Comment 1 Ed Maste freebsd_committer freebsd_triage 2022-03-21 18:27:07 UTC
asan runtime support is currently built only for i386, amd64, and riscv.
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2022-03-21 20:20:34 UTC
Yep, upstream doesn't yet support aarch64 for the sanitizers. If I attempt to build it on an aarch64 machine, I see:

/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1811:23: error: field has incomplete type 'struct _aarch64_ctx'
  struct _aarch64_ctx head;
                      ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1811:10: note: forward declaration of '__sanitizer::_aarch64_ctx'
  struct _aarch64_ctx head;
         ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1817:35: error: no member named '__reserved' in '__mcontext'
  u8 *aux = ucontext->uc_mcontext.__reserved;
            ~~~~~~~~~~~~~~~~~~~~~ ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1820:12: error: member access into incomplete type '__sanitizer::_aarch64_ctx'
    if (ctx->size == 0) break;
           ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1811:10: note: forward declaration of '__sanitizer::_aarch64_ctx'
  struct _aarch64_ctx head;
         ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1821:12: error: member access into incomplete type '__sanitizer::_aarch64_ctx'
    if (ctx->magic == kEsrMagic) {
           ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1811:10: note: forward declaration of '__sanitizer::_aarch64_ctx'
  struct _aarch64_ctx head;
         ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1825:15: error: member access into incomplete type '__sanitizer::_aarch64_ctx'
    aux += ctx->size;
              ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1811:10: note: forward declaration of '__sanitizer::_aarch64_ctx'
  struct _aarch64_ctx head;
         ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2055:31: error: no member named 'pc' in '__mcontext'
  *pc = ucontext->uc_mcontext.pc;
        ~~~~~~~~~~~~~~~~~~~~~ ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2056:31: error: no member named 'regs' in '__mcontext'
  *bp = ucontext->uc_mcontext.regs[29];
        ~~~~~~~~~~~~~~~~~~~~~ ^
/home/dim/src/main/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2057:31: error: no member named 'sp' in '__mcontext'
  *sp = ucontext->uc_mcontext.sp;
        ~~~~~~~~~~~~~~~~~~~~~ ^
8 errors generated.

`_aarch64_ctx` is a Linux-specific context struct from /usr/include/aarch64-linux-gnu/asm/sigcontext.h:

/*
 * Header to be used at the beginning of structures extending the user
 * context. Such structures must be placed after the rt_sigframe on the stack
 * and be 16-byte aligned. The last structure must be a dummy one with the
 * magic and size set to 0.
 */
struct _aarch64_ctx {
        __u32 magic;
        __u32 size;
};

but obviously it doesn't exist in FreeBSD. Similarly, struct ucontext and mcontext have different members, and aren't generally compatible.

I think the only way to get this implemented is to have somebody with aarch64 knowledge, who can attempt to fix them up and submit reviews upstream.
Comment 3 Piotr Kubaj freebsd_committer freebsd_triage 2022-05-17 16:19:07 UTC
I'm not sure how it should be done on aarch64, but fixing sanitizers on powerpc64* was quite easy: https://github.com/llvm/llvm-project/commit/315d792130258a9b7250494be8d002ebb427b08f

Based on that commit, a person with aarch64 knowledge and interest could fix aarch64 build.
Comment 4 ota 2023-12-26 05:46:28 UTC
Is it still the case arm64 is not yet supported?

I tested this on 13.2-RELEASE and 14.0-RELEASE.

I get the following errors:

14.0
% ...
c++ -o xxx.pm -g main.o -L/usr/local/lib -fprofile-instr-generate -fcoverage-map
ping -fsanitize=address -fno-omit-frame-pointer -L.. -Wl,--rpath=..  -lpthread -
ledit -lboost_program_options -lboost_system -lboost_system -lpthread -ledit
ld: error: cannot open /usr/lib/clang/16/lib/freebsd/libclang_rt.asan_static-aar
ch64.a: No such file or directory
ld: error: cannot open /usr/lib/clang/16/lib/freebsd/libclang_rt.asan-aarch64.a:
 No such file or directory
ld: error: cannot open /usr/lib/clang/16/lib/freebsd/libclang_rt.asan_cxx-aarch6
4.a: No such file or directory
c++: error: linker command failed with exit code 1 (use -v to see invocation)


13.2
%
ld: error: cannot open /usr/lib/clang/14.0.5/lib/freebsd/libclang_rt.asan_static
-aarch64.a: No such file or directory
ld: error: cannot open /usr/lib/clang/14.0.5/lib/freebsd/libclang_rt.asan-aarch6
4.a: No such file or directory
ld: error: cannot open /usr/lib/clang/14.0.5/lib/freebsd/libclang_rt.asan_cxx-aa
rch64.a: No such file or directory
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2023-12-26 11:32:49 UTC
(In reply to ota from comment #4)
The Makefile for this (lib/libclang_rt/Makefile) still has only x86 listed for asan, cfi, ubsan and a few other components. I think upstream does support these (or at least part of them) for aarch64, so thanks for the reminder. I will take another look at getting those libraries in.
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-12-28 12:59:34 UTC
A commit in branch main references this bug:

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

commit e77a1bb2757471ab3fed0750b76eeb15d0c7b10a
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-28 12:57:41 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-12-28 12:57:41 +0000

    Reorganize libclang_rt Makefile and make more lib/arch combos available

    Upstream has made more clang runtime libraries available for more
    architectures, so add them. To make this easier, split up subdir lists
    into functional parts (asan, tsan, etc), and put each architecture into
    its own .if block.

    Effectively, this adds the following libraries for aarch64: asan, cfi,
    fuzzer, msan, safestack, stats, tsan, ubsan, xray.

    PR:             262706
    MFC after:      3 days

 lib/libclang_rt/Makefile | 162 ++++++++++++++++++++++++++---------------------
 1 file changed, 91 insertions(+), 71 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2024-01-01 16:43:29 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8334205c84cf8fb2006cc9dc9fdeecaa855242b3

commit 8334205c84cf8fb2006cc9dc9fdeecaa855242b3
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-28 12:57:41 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-01-01 16:34:04 +0000

    Reorganize libclang_rt Makefile and make more lib/arch combos available

    Upstream has made more clang runtime libraries available for more
    architectures, so add them. To make this easier, split up subdir lists
    into functional parts (asan, tsan, etc), and put each architecture into
    its own .if block.

    Effectively, this adds the following libraries for aarch64: asan, cfi,
    fuzzer, msan, safestack, stats, tsan, ubsan, xray.

    PR:             262706
    MFC after:      3 days

    (cherry picked from commit e77a1bb2757471ab3fed0750b76eeb15d0c7b10a)

 lib/libclang_rt/Makefile | 162 ++++++++++++++++++++++++++---------------------
 1 file changed, 91 insertions(+), 71 deletions(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2024-01-01 16:43:31 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c95aeb90f70a66c75869fa0de44283c04bbd725

commit 5c95aeb90f70a66c75869fa0de44283c04bbd725
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-28 12:57:41 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-01-01 16:41:43 +0000

    Reorganize libclang_rt Makefile and make more lib/arch combos available

    Upstream has made more clang runtime libraries available for more
    architectures, so add them. To make this easier, split up subdir lists
    into functional parts (asan, tsan, etc), and put each architecture into
    its own .if block.

    Effectively, this adds the following libraries for aarch64: asan, cfi,
    fuzzer, msan, safestack, stats, tsan, ubsan, xray.

    PR:             262706
    MFC after:      3 days

    (cherry picked from commit e77a1bb2757471ab3fed0750b76eeb15d0c7b10a)

 lib/libclang_rt/Makefile | 161 ++++++++++++++++++++++++++---------------------
 1 file changed, 91 insertions(+), 70 deletions(-)
Comment 9 Dimitry Andric freebsd_committer freebsd_triage 2024-01-01 16:48:00 UTC
I'm not sure if this is worth an Errata Notice? It's a bit of a pity that 14.0 shipped without most of the sanitizer libraries on arm64, though.
Comment 10 Kyle Evans freebsd_committer freebsd_triage 2024-01-01 18:39:22 UTC
(In reply to Dimitry Andric from comment #9)

IMO no, this is a missing feature that should've been there but at the same time there is a suitable replacement in the llvm ports, so without a compelling reason I'm not sure it's worth the overhead to write up the details and roll a build.
Comment 11 Dimitry Andric freebsd_committer freebsd_triage 2024-01-02 16:50:24 UTC
Let's close this then. The libraries will be available in the upcoming 14.1-RELEASE (and 13.3-RELEASE, when it's there).
Comment 12 commit-hook freebsd_committer freebsd_triage 2024-03-21 17:12:46 UTC
A commit in branch main references this bug:

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

commit f0620ceeccf070a69352105c5dbc23cff499a732
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 13:53:36 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-21 17:05:25 +0000

    Fix building of several libclang_rt libraries for powerpc64 and powerp64le

    I reorganized the libclang_rt Makefile in e77a1bb27574 to make it more
    readable and maintainable, but the check for 32-bit powerpc was wrong.
    This caused almost no libclang_rt libraries to be built for powerpc64
    and powerpc64le.

    PR:             262706
    Reported by:    tuexen
    Fixes:          e77a1bb27574
    MFC after:      3 days

 lib/libclang_rt/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2024-03-21 20:46:22 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=897a485c34464a44b768f13127d94137229eb83d

commit 897a485c34464a44b768f13127d94137229eb83d
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 20:44:46 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-21 20:44:46 +0000

    Slightly reorganize libclang_rt Makefile again

    Make a separate .elif section for MACHINE_ARCH==powerpc, and subdivide
    the MACHINE_CPUARCH values under it. If at some point more sanitizer
    libraries become available for powerpc CPU architectures, they can be
    added before the "nothing for other powerpc yet" case. Similar for the
    MACHINE_ARCH==arm case.

    PR:             262706
    Fixes:          e77a1bb27574
    MFC after:      3 days

 lib/libclang_rt/Makefile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Comment 14 commit-hook freebsd_committer freebsd_triage 2024-03-24 00:41:16 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=35a61f4a25ac5301b83d2c4835081d60de5b8b1e

commit 35a61f4a25ac5301b83d2c4835081d60de5b8b1e
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 20:44:46 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-24 00:36:26 +0000

    Slightly reorganize libclang_rt Makefile again

    Make a separate .elif section for MACHINE_ARCH==powerpc, and subdivide
    the MACHINE_CPUARCH values under it. If at some point more sanitizer
    libraries become available for powerpc CPU architectures, they can be
    added before the "nothing for other powerpc yet" case. Similar for the
    MACHINE_ARCH==arm case.

    PR:             262706
    Fixes:          e77a1bb27574
    MFC after:      3 days

    (cherry picked from commit 897a485c34464a44b768f13127d94137229eb83d)

 lib/libclang_rt/Makefile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Comment 15 commit-hook freebsd_committer freebsd_triage 2024-03-24 00:41:19 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=880f35eb5d489ae6b8d09da82f577381f24157d2

commit 880f35eb5d489ae6b8d09da82f577381f24157d2
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 13:53:36 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-24 00:36:18 +0000

    Fix building of several libclang_rt libraries for powerpc64 and powerp64le

    I reorganized the libclang_rt Makefile in e77a1bb27574 to make it more
    readable and maintainable, but the check for 32-bit powerpc was wrong.
    This caused almost no libclang_rt libraries to be built for powerpc64
    and powerpc64le.

    PR:             262706
    Reported by:    tuexen
    Fixes:          e77a1bb27574
    MFC after:      3 days

    (cherry picked from commit f0620ceeccf070a69352105c5dbc23cff499a732)

 lib/libclang_rt/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 16 commit-hook freebsd_committer freebsd_triage 2024-03-24 00:44:21 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c588a23c96b88327f87bb8ef6c795c442d56c2a

commit 5c588a23c96b88327f87bb8ef6c795c442d56c2a
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 20:44:46 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-24 00:37:29 +0000

    Slightly reorganize libclang_rt Makefile again

    Make a separate .elif section for MACHINE_ARCH==powerpc, and subdivide
    the MACHINE_CPUARCH values under it. If at some point more sanitizer
    libraries become available for powerpc CPU architectures, they can be
    added before the "nothing for other powerpc yet" case. Similar for the
    MACHINE_ARCH==arm case.

    PR:             262706
    Fixes:          e77a1bb27574
    MFC after:      3 days

    (cherry picked from commit 897a485c34464a44b768f13127d94137229eb83d)

 lib/libclang_rt/Makefile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Comment 17 commit-hook freebsd_committer freebsd_triage 2024-03-24 00:44:23 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=72d9e1e0ca66ca39ca157731a65be32c63916252

commit 72d9e1e0ca66ca39ca157731a65be32c63916252
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 13:53:36 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-24 00:37:23 +0000

    Fix building of several libclang_rt libraries for powerpc64 and powerp64le

    I reorganized the libclang_rt Makefile in e77a1bb27574 to make it more
    readable and maintainable, but the check for 32-bit powerpc was wrong.
    This caused almost no libclang_rt libraries to be built for powerpc64
    and powerpc64le.

    PR:             262706
    Reported by:    tuexen
    Fixes:          e77a1bb27574
    MFC after:      3 days

    (cherry picked from commit f0620ceeccf070a69352105c5dbc23cff499a732)

 lib/libclang_rt/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 18 feh 2024-05-09 09:11:57 UTC
I get the same error here after upgrade from 13.2 => 13.3:

ld: error: cannot open /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a: No such file or directory

The machine IS a AMD64:

FreeBSD bigchief.fehnet.de 13.3-RELEASE-p1 FreeBSD 13.3-RELEASE-p1 GENERIC amd64

All updates installed.

regards.
--eh.
Comment 19 feh 2024-05-09 09:13:59 UTC
Sorry: Should say: the same *kind* of error.

--eh.
Comment 20 Dimitry Andric freebsd_committer freebsd_triage 2024-05-09 16:33:07 UTC
(In reply to feh from comment #19)
It looks rather different: this bug was originally about aarch64 not supporting some (or all) of the sanitizers. Later, it became about some refactoring in the Makefiles causing libraries for some architectures to be erroneously skipped.

In your case, it looks like you used freebsd-update? And maybe it was not aware that you had the /usr/lib/clang directory at all, so it did not update it? How did you upgrade, exactly?