git: c6547a4ed92a - main - lang/rust: fix build on powerpc on FreeBSD 13.1 and newer

From: Piotr Kubaj <pkubaj_at_FreeBSD.org>
Date: Wed, 23 Mar 2022 17:05:08 UTC
The branch main has been updated by pkubaj:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c6547a4ed92a9dbafd26a8ff3f758c3e60bc1959

commit c6547a4ed92a9dbafd26a8ff3f758c3e60bc1959
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2022-03-23 16:55:55 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2022-03-23 16:55:55 +0000

    lang/rust: fix build on powerpc on FreeBSD 13.1 and newer
    
    1. When building with RUST_BACKTRACE=1, cargo segfaults:
    pre-installed rustc not detected: [Errno 2] No such file or directory: 'rustc'
    falling back to auto-detect
    warning: sqlite3 not available in python, skipping build directory lock
    please file an issue on rust-lang/rust
    this is not a problem for non-concurrent x.py invocations
    Building rustbuild
    running: /wrkdirs/usr/ports/lang/rust/work/bootstrap/bin/cargo build --manifest-path /wrkdirs/usr/ports/lang/rust/work/rustc-1.59.0-src/src/bootstrap/Cargo.toml --verbose --verbose --frozen
    Traceback (most recent call last):
      File "x.py", line 27, in <module>
        bootstrap.main()
      File "/wrkdirs/usr/ports/lang/rust/work/rustc-1.59.0-src/src/bootstrap/bootstrap.py", line 1313, in main
        bootstrap(help_triggered)
      File "/wrkdirs/usr/ports/lang/rust/work/rustc-1.59.0-src/src/bootstrap/bootstrap.py", line 1284, in bootstrap
        build.build_bootstrap()
      File "/wrkdirs/usr/ports/lang/rust/work/rustc-1.59.0-src/src/bootstrap/bootstrap.py", line 1031, in build_bootstrap
        run(args, env=env, verbose=self.verbose)
      File "/wrkdirs/usr/ports/lang/rust/work/rustc-1.59.0-src/src/bootstrap/bootstrap.py", line 182, in run
        raise RuntimeError(err)
    RuntimeError: failed to run: /wrkdirs/usr/ports/lang/rust/work/bootstrap/bin/cargo build --manifest-path /wrkdirs/usr/ports/lang/rust/work/rustc-1.59.0-src/src/bootstrap/Cargo.toml --verbose --verbose --frozen
    
    From dmesg:
    pid 27701 (cargo), jid 198, uid 0: exited on signal 11
    
    2. Builds with the base LLVM 13 fail:
    ld: error: CallSiteSplitting.cpp:(function llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >::operator=(llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >&&): .text._ZN4llvm15SmallVectorImplINSt3__14pairIPNS_10BasicBlockENS_11SmallVectorINS2_IPNS_8ICmpInstEjEELj2EEEEEEaSEOSB_+0xB0): relocation R_PPC_PLTREL24 out of range: -33582208 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >::operator=(llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >&&): .text._ZN4llvm15SmallVectorImplINSt3__14pairIPNS_10BasicBlockENS_11SmallVectorINS2_IPNS_8ICmpInstEjEELj2EEEEEEaSEOSB_+0xC8): relocation R_PPC_PLTREL24 out of range: -33582232 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >::operator=(llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >&&): .text._ZN4llvm15SmallVectorImplINSt3__14pairIPNS_10BasicBlockENS_11SmallVectorINS2_IPNS_8ICmpInstEjEELj2EEEEEEaSEOSB_+0x1A0): relocation R_PPC_PLTREL24 out of range: -33582448 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >::operator=(llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >&&): .text._ZN4llvm15SmallVectorImplINSt3__14pairIPNS_10BasicBlockENS_11SmallVectorINS2_IPNS_8ICmpInstEjEELj2EEEEEEaSEOSB_+0x2B8): relocation R_PPC_PLTREL24 out of range: -33582728 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >::operator=(llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >&&): .text._ZN4llvm15SmallVectorImplINSt3__14pairIPNS_10BasicBlockENS_11SmallVectorINS2_IPNS_8ICmpInstEjEELj2EEEEEEaSEOSB_+0x2FC): relocation R_PPC_PLTREL24 out of range: -33582796 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >::operator=(llvm::SmallVectorImpl<std::__1::pair<llvm::BasicBlock*, llvm::SmallVector<std::__1::pair<llvm::ICmpInst*, unsigned int>, 2u> > >&&): .text._ZN4llvm15SmallVectorImplINSt3__14pairIPNS_10BasicBlockENS_11SmallVectorINS2_IPNS_8ICmpInstEjEELj2EEEEEEaSEOSB_+0x348): relocation R_PPC_PLTREL24 out of range: -33582872 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function _GLOBAL__sub_I_CallSiteSplitting.cpp: .text._GLOBAL__sub_I_CallSiteSplitting.cpp+0x80): relocation R_PPC_PLTREL24 out of range: -33583000 is not in [-33554432, 33554431]
    ld: error: CallSiteSplitting.cpp:(function _GLOBAL__sub_I_CallSiteSplitting.cpp: .text._GLOBAL__sub_I_CallSiteSplitting.cpp+0xB0): relocation R_PPC_PLTREL24 out of range: -33583208 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::initializeConstantHoistingLegacyPassPass(llvm::PassRegistry&): .text._ZN4llvm40initializeConstantHoistingLegacyPassPassERNS_12PassRegistryE+0x94): relocation R_PPC_PLTREL24 out of range: -33583360 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function initializeConstantHoistingLegacyPassPassOnce(llvm::PassRegistry&): .text._ZL44initializeConstantHoistingLegacyPassPassOnceRN4llvm12PassRegistryE+0x50): relocation R_PPC_PLTREL24 out of range: -33583396 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::createConstantHoistingPass(): .text._ZN4llvm26createConstantHoistingPassEv+0x3C): relocation R_PPC_PLTREL24 out of range: -33583584 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::createConstantHoistingPass(): .text._ZN4llvm26createConstantHoistingPassEv+0x78): relocation R_PPC_PLTREL24 out of range: -33583548 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::createConstantHoistingPass(): .text._ZN4llvm26createConstantHoistingPassEv+0x98): relocation R_PPC_PLTREL24 out of range: -33583580 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::createConstantHoistingPass(): .text._ZN4llvm26createConstantHoistingPassEv+0x118): relocation R_PPC_PLTREL24 out of range: -33583852 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::ConstantHoistingPass::findConstantInsertionPoint(llvm::consthoist::ConstantInfo const&) const: .text._ZNK4llvm20ConstantHoistingPass26findConstantInsertionPointERKNS_10consthoist12ConstantInfoE+0x240): relocation R_PPC_PLTREL24 out of range: -33584892 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::ConstantHoistingPass::findConstantInsertionPoint(llvm::consthoist::ConstantInfo const&) const: .text._ZNK4llvm20ConstantHoistingPass26findConstantInsertionPointERKNS_10consthoist12ConstantInfoE+0x270): relocation R_PPC_PLTREL24 out of range: -33584924 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::ConstantHoistingPass::findConstantInsertionPoint(llvm::consthoist::ConstantInfo const&) const: .text._ZNK4llvm20ConstantHoistingPass26findConstantInsertionPointERKNS_10consthoist12ConstantInfoE+0x294): relocation R_PPC_PLTREL24 out of range: -33584944 is not in [-33554432, 33554431]
    ld: error: ConstantHoisting.cpp:(function llvm::ConstantHoistingPass::findConstantInsertionPoint(llvm::consthoist::ConstantInfo const&) const: .text._ZNK4llvm20ConstantHoistingPass26findConstantInsertionPointERKNS_10consthoist12ConstantInfoE+0x90C): relocation R_PPC_PLTREL24 out of range: -33586536 is not in [-33554432, 33554431]
    
    Use LLVM 12 to build.
---
 lang/rust/Makefile | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lang/rust/Makefile b/lang/rust/Makefile
index b6044d2effb4..8d4d53160eb2 100644
--- a/lang/rust/Makefile
+++ b/lang/rust/Makefile
@@ -38,8 +38,7 @@ CPE_VENDOR=	rust-lang
 
 MAKE_ENV=	DESTDIR=${STAGEDIR} \
 		LIBGIT2_NO_PKG_CONFIG=1 \
-		OPENSSL_DIR="${OPENSSLBASE}" \
-		RUST_BACKTRACE=1
+		OPENSSL_DIR="${OPENSSLBASE}"
 TEST_ENV=	${MAKE_ENV} \
 		ALLOW_NONZERO_RLIMIT_CORE=1
 
@@ -96,8 +95,16 @@ IGNORE=		is only for FreeBSD
 
 .if ${ARCH} == powerpc
 # bfd to link rustc_driver; lld currently can't
-BUILD_DEPENDS+=	ld.bfd:devel/binutils
+BUILD_DEPENDS+=	ld.bfd:devel/binutils \
+		clang12:devel/llvm12
+BINARY_ALIAS+=	cpp=${LOCALBASE}/bin/clang-cpp12 \
+		cc=${LOCALBASE}/bin/clang12 \
+		c++=${LOCALBASE}/bin/clang++12 \
+		ar=${LOCALBASE}/bin/llvm-ar12 \
+		nm=${LOCALBASE}/bin/llvm-nm12 \
+		ld=${LOCALBASE}/bin/ld.lld12
 .else
+MAKE_ENV+=	RUST_BACKTRACE=1
 # rls needs 64-bit atomics
 _RUST_TOOLS+=	rls
 .endif