Closed Bug 1769063 Opened 2 years ago Closed 2 years ago

ppc64 build fails on Darwin due to wrong ABI used in mpcpucache.c

Categories

(NSS :: Build, defect, P3)

3.78

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: vital.had, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36

Steps to reproduce:

Build for ppc64 on 10.5.8 fails due to unconditional usage of assembler instruction that does not comply with Darwin ABI in mpcpucache.c.
Identical error regardless of compiler version: confirmed with gcc-4.2 and gcc11 @11.3.0.

Actual results:

mpi/mpcpucache.c: In function ‘dcbzl’:
mpi/mpcpucache.c:730: error: nested functions are disabled, use -fnested-functions to re-enable
mpi/mpcpucache.c:730: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘asm’
mpi/mpcpucache.c:730: warning: implicit declaration of function ‘asm’
mpi/mpcpucache.c:730: error: lvalue required as left operand of assignment
mpi/mpcpucache.c:732: error: ‘a’ undeclared (first use in this function)
mpi/mpcpucache.c:732: error: (Each undeclared identifier is reported only once
mpi/mpcpucache.c:732: error: for each function it appears in.)
mpi/mpcpucache.c:731: error: invalid lvalue in asm output 0
make[4]: *** [Output.OBJD/Darwin_SINGLE_SHLIB/mpcpucache.o] Error 1
make[4]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_nss/nss/work/nss-3.78-ppc64/nss/lib/freebl'
make[3]: *** [freebl_FREEBL_BUILD_SINGLE_SHLIB] Error 2
make[3]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_nss/nss/work/nss-3.78-ppc64/nss/lib/freebl'
make[2]: *** [freebl] Error 2
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_nss/nss/work/nss-3.78-ppc64/nss/lib'
make[1]: *** [lib] Error 2
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_nss/nss/work/nss-3.78-ppc64/nss'
make: *** [all] Error 2
make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_nss/nss/work/nss-3.78-ppc64/nss'
Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_nss/nss/work/nss-3.78-ppc64/nss" && /usr/bin/make -j1 -w all NSS_DISABLE_GTESTS=1 NSS_ENABLE_WERROR=0 NSPR_INCLUDE_DIR=/opt/local/include/nspr NSPR_LIB_DIR=/opt/local/lib/nspr NSS_USE_SYSTEM_SQLITE=1 USE_SYSTEM_ZLIB=1 BUILD_OPT=1 OPTIMIZER="-Os" OBJDIR_NAME="Output.OBJD" USE_64=1 CC="/usr/bin/gcc-4.2 -Os -std=c99 -arch ppc64" CCC="/usr/bin/g++-4.2 -Os -arch ppc64" 
Exit code: 2

Expected results:

  1. A trivial fix:
--- nss/lib/freebl/mpi/mpcpucache.c.orig	1970-01-01 08:00:00.000000000 +0800
+++ nss/lib/freebl/mpi/mpcpucache.c	2022-05-12 21:28:37.000000000 +0800
@@ -705,7 +705,7 @@
 #define MPI_GET_PROCESSOR_LINE_SIZE_DEFINED 1
 #endif
 
-#if defined(__ppc64__)
+#if !defined(__APPLE__) && defined(__ppc64__)
 /*
  *  Sigh, The PPC has some really nice features to help us determine cache
  *  size, since it had lots of direct control functions to do so. The POWER
  1. If someone can actually fix the assembler for ppc32 and ppc64 with Mac OSX ABI, that would be awesome. Otherwise, at least wrong instructions should not be applied. Fallback option specified in mpcpucache.c works decently: ppc32 builds fine, having no dedicated case there.

I'm not really set up to test this, but there's an alternative dcbzl implementation here. Could you see if this compiles?

static inline void
dcbzl(char *array)
{
__asm__ ("dcbzl %0, 0" : /*no result*/ : "b%" (array) : "memory")
}
Severity: -- → S4
Priority: -- → P3

(In reply to John Schanck from comment #1)

I'm not really set up to test this, but there's an alternative dcbzl implementation here. Could you see if this compiles?

static inline void
dcbzl(char *array)
{
__asm__ ("dcbzl %0, 0" : /*no result*/ : "b%" (array) : "memory")
}

Thank you for replying! This will probably work (with including a header: /Developer/usr/llvm-gcc-4.2/include/gcc/darwin/4.2/ppc_intrinsics.h) – and maybe even for Darwin ppc32 case as well, however I get the error that __dcbzl requires 2 arguments, but only 1 is given.
Without including a header it builds silently but linking fails with undefined symbol (unsurprisingly).

Definitions indeed ask for two arguments:

/*

  • __dcbzl - Data Cache Block Set to Zero
  • void __dcbzl(void *, int);
    */
    #define __dcbzl(base, index)
    asm ("dcbzl %0, %1" : /no result/ : "b%" (index), "r" (base) : "memory")

/*

  • __dcbz - Data Cache Block Set to Zero (32-bytes only)
  • WARNING: this is for legacy purposes only
  • void __dcbz(void *, int);
    */
    #define __dcbz(base, index)
    asm ("dcbz %0, %1" : /no result/ : "b%" (index), "r" (base) : "memory")

Could you try the code that I included in my comment? It's based on the implementation from ppc_intrinsics.h, but it only takes one argument.

I tried it. It fails with:

mpi/mpcpucache.c: In function 'dcbzl':
mpi/mpcpucache.c:730:66: error: expected ';' before '}' token
  730 | __asm__ ("dcbzl %0, 0" : /*no result*/ : "b%" (array) : "memory")
      |                                                                  ^
      |                                                                  ;
  731 | }
      | ~                                                                 
mpi/mpcpucache.c:731:1: error: '%' constraint used with last operand
  731 | }
      | ^
mpi/mpcpucache.c:758:1: error: expected declaration or statement at end of input
  758 | }
      | ^

Sorry about that, I should have checked on compiler explorer. Let's give it one more try with this:

static inline void
dcbzl(char *array)
{
  __asm__ ("dcbzl %0, %1" : /*no result*/ : "b%" (array), "r" (0) : "memory");
}

Yes, this one worked! Thanks!

Could you include that into the source? In the meanwhile, I will update my PR to Macports.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 3.80
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: