Index: lang/rust/Makefile =================================================================== --- lang/rust/Makefile +++ lang/rust/Makefile @@ -67,7 +67,7 @@ COMPILER_RT_VERSION?= 9.0.0 BOOTSTRAPS_SUFFIX?= ${BOOTSTRAPS_SUFFIX_${ARCH}} -BOOTSTRAPS_SUFFIX_powerpc64?= -elfv1 +BOOTSTRAPS_SUFFIX_powerpc64?= -${PPC_ABI:tl} CARGO_VENDOR_DIR?= ${WRKSRC}/vendor @@ -83,11 +83,12 @@ .include -.if ${ARCH} == powerpc64 +.if ${ARCH} == powerpc64 && ${PPC_ABI} == ELFv1 # The bootstrap is hardcoded to use gcc9 # but we can build with a newer or older compiler as provided by USE_GCC=yes BUILD_DEPENDS+= gcc9:lang/gcc9 USE_GCC= yes +EXTRA_PATCHES+= ${PATCHDIR}/extra-patch-ppc64-gcc .endif .if ${OPSYS} == FreeBSD && ${ARCH} == aarch64 && \ @@ -134,6 +135,14 @@ # Disable vendor checksums @${REINPLACE_CMD} 's,"files":{[^}]*},"files":{},' \ ${CARGO_VENDOR_DIR}/*/.cargo-checksum.json +.if ${ARCH} == powerpc64 && ${PPC_ABI} == ELFv2 + @${REINPLACE_CMD} -e \ + 's|Endian::Big => ELFv1|Endian::Big => ELFv2|' \ + ${WRKSRC}/src/librustc_target/abi/call/powerpc64.rs + @${REINPLACE_CMD} -e \ + 's|powerpc64-unknown-freebsd|powerpc64-unknown-freebsd${OSREL}|' \ + ${WRKSRC}/src/librustc_target/spec/powerpc64_unknown_freebsd.rs +.endif post-patch-SOURCES-off: # Mimic tools in config.toml with just src excluded @@ -246,14 +255,14 @@ makesum: ${MAKE} -D_RUST_MAKESUM_GUARD makesum ARCH=${ONLY_FOR_ARCHS:O:[1]} DISTINFO_FILE=${DISTINFO_FILE}.tmp .for arch in ${ONLY_FOR_ARCHS:O:[2..-1]} - ${MAKE} -D_RUST_MAKESUM_GUARD makesum ARCH=${arch} DISTINFO_FILE=${DISTINFO_FILE}.${arch} + ${MAKE} -D_RUST_MAKESUM_GUARD makesum PPC_ABI=ELFv1 ARCH=${arch} DISTINFO_FILE=${DISTINFO_FILE}.${arch} ${GREP} ${_RUST_ARCH_${arch}:U${arch}} ${DISTINFO_FILE}.${arch} >> ${DISTINFO_FILE}.tmp .for file in ${DISTFILES_${arch}} ${GREP} ${file:S,:, ,:[1]} ${DISTINFO_FILE}.${arch} >> ${DISTINFO_FILE}.tmp .endfor ${RM} ${DISTINFO_FILE}.${arch} .endfor - ${MAKE} -D_RUST_MAKESUM_GUARD makesum ARCH=powerpc64 BOOTSTRAPS_SUFFIX="-elfv2" DISTINFO_FILE=${DISTINFO_FILE}.powerpc64-elfv2 + ${MAKE} -D_RUST_MAKESUM_GUARD makesum PPC_ABI=ELFv2 ARCH=powerpc64 DISTINFO_FILE=${DISTINFO_FILE}.powerpc64-elfv2 ${GREP} ${_RUST_ARCH_powerpc64:Upowerpc64} ${DISTINFO_FILE}.powerpc64-elfv2 >> ${DISTINFO_FILE}.tmp ${RM} ${DISTINFO_FILE}.powerpc64-elfv2 ${AWK} '!seen[$$0]++' ${DISTINFO_FILE}.tmp > ${DISTINFO_FILE} Index: lang/rust/files/extra-patch-ppc64-gcc =================================================================== --- lang/rust/files/extra-patch-ppc64-gcc +++ lang/rust/files/extra-patch-ppc64-gcc @@ -0,0 +1,27 @@ +--- src/librustc_llvm/build.rs.orig 2019-04-08 12:42:31 UTC ++++ src/librustc_llvm/build.rs +@@ -254,7 +254,10 @@ fn main() { + }; + + // C++ runtime library +- if !target.contains("msvc") { ++ if target == "powerpc64-unknown-freebsd" { ++ println!("cargo:rustc-link-search=native=/usr/local/lib/%CC%"); ++ println!("cargo:rustc-link-lib=static=stdc++"); ++ } else if !target.contains("msvc") { + if let Some(s) = llvm_static_stdcpp { + assert!(!cxxflags.contains("stdlib=libc++")); + let path = PathBuf::from(s); +--- src/bootstrap/native.rs.orig 2019-05-22 05:39:52 UTC ++++ src/bootstrap/native.rs +@@ -218,6 +210,10 @@ impl Step for Llvm { + } + } + ++ if target == "powerpc64-unknown-freebsd" { ++ cfg.define("CMAKE_EXE_LINKER_FLAGS", "-Wl,-rpath=/usr/local/lib/%CC% -L/usr/local/lib/%CC%"); ++ } ++ + // http://llvm.org/docs/HowToCrossCompileLLVM.html + if target != builder.config.build && !emscripten { ++ builder.ensure(Llvm { Index: lang/rust/files/patch-llvm =================================================================== --- lang/rust/files/patch-llvm +++ lang/rust/files/patch-llvm @@ -0,0 +1,71 @@ +From 9b7fc4e553f8dc1ec9f81f64ea50ca73a82007d7 Mon Sep 17 00:00:00 2001 +From: Alfredo Dal'Ava Junior +Date: Thu, 29 Aug 2019 11:41:26 -0300 +Subject: [PATCH] adalava: make elfv2 default + +--- + clang/lib/Basic/Targets/PPC.h | 21 ++++++++++++++++++-- + llvm/lib/Target/PowerPC/PPCTargetMachine.cpp | 14 +++++++++++++ + 2 files changed, 33 insertions(+), 2 deletions(-) + +diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h +index 6e5df097921b..a47fa335e931 100644 +--- src/llvm-project/clang/lib/Basic/Targets/PPC.h ++++ src/llvm-project/clang/lib/Basic/Targets/PPC.h +@@ -374,12 +374,29 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo { + IntMaxType = SignedLong; + Int64Type = SignedLong; + ++ if (Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) { ++ switch (Triple.getEnvironment()){ ++ case llvm::Triple::ELFv1: ++ ABI = "elfv1"; ++ break; ++ default: ++ ABI = "elfv2"; ++ break; ++ } ++ } else { ++ if ((Triple.getOS() == llvm::Triple::FreeBSD) && ++ (Triple.getOSMajorVersion() < 13)) { ++ ABI = "elfv1"; ++ } else { ++ ABI = "elfv2"; ++ } ++ } ++ ++ + if ((Triple.getArch() == llvm::Triple::ppc64le)) { + resetDataLayout("e-m:e-i64:64-n32:64"); +- ABI = "elfv2"; + } else { + resetDataLayout("E-m:e-i64:64-n32:64"); +- ABI = Triple.getEnvironment() == llvm::Triple::ELFv2 ? "elfv2" : "elfv1"; + } + + if (Triple.getOS() == llvm::Triple::AIX) +diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +index ce00f848dd72..356a08929682 100644 +--- src/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp ++++ src/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +@@ -209,6 +209,20 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, + if (TT.isMacOSX()) + return PPCTargetMachine::PPC_ABI_UNKNOWN; + ++ if (TT.isOSFreeBSD()) { ++ switch (TT.getArch()) { ++ case Triple::ppc64le: ++ case Triple::ppc64: ++ if (TT.getOSMajorVersion() >= 13) ++ return PPCTargetMachine::PPC_ABI_ELFv2; ++ else ++ return PPCTargetMachine::PPC_ABI_ELFv1; ++ case Triple::ppc: ++ default: ++ return PPCTargetMachine::PPC_ABI_UNKNOWN; ++ } ++ } ++ + switch (TT.getArch()) { + case Triple::ppc64le: + return PPCTargetMachine::PPC_ABI_ELFv2; Index: lang/rust/files/patch-src_bootstrap_native.rs =================================================================== --- lang/rust/files/patch-src_bootstrap_native.rs +++ lang/rust/files/patch-src_bootstrap_native.rs @@ -24,17 +24,6 @@ let _folder = builder.fold_output(|| "llvm"); let descriptor = if emscripten { "Emscripten " } else { "" }; -@@ -218,6 +210,10 @@ impl Step for Llvm { - } - } - -+ if target == "powerpc64-unknown-freebsd" { -+ cfg.define("CMAKE_EXE_LINKER_FLAGS", "-Wl,-rpath=/usr/local/lib/%CC% -L/usr/local/lib/%CC%"); -+ } -+ - // http://llvm.org/docs/HowToCrossCompileLLVM.html - if target != builder.config.build && !emscripten { - builder.ensure(Llvm { @@ -283,9 +279,7 @@ impl Step for Llvm { cfg.build(); Index: lang/rust/files/patch-src_librustc__llvm_build.rs =================================================================== --- lang/rust/files/patch-src_librustc__llvm_build.rs +++ lang/rust/files/patch-src_librustc__llvm_build.rs @@ -1,14 +0,0 @@ ---- src/librustc_llvm/build.rs.orig 2019-04-08 12:42:31 UTC -+++ src/librustc_llvm/build.rs -@@ -254,7 +254,10 @@ fn main() { - }; - - // C++ runtime library -- if !target.contains("msvc") { -+ if target == "powerpc64-unknown-freebsd" { -+ println!("cargo:rustc-link-search=native=/usr/local/lib/%CC%"); -+ println!("cargo:rustc-link-lib=static=stdc++"); -+ } else if !target.contains("msvc") { - if let Some(s) = llvm_static_stdcpp { - assert!(!cxxflags.contains("stdlib=libc++")); - let path = PathBuf::from(s);