Opened 21 months ago

Last modified 21 months ago

#65534 new defect

nspr @4.34+universal arm64,x86_64 fails to build

Reported by: potterpg Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc:
Port: nspr

Description

nspr make seems to get confused between arm64 and x86_64 on arm64 build?

Can it be built for +universal?

Any help appreciated.

port: port search nspr nspr @4.34 (devel)

A platform-neutral API for system level and libc like functions.

Log file:

:info:build --->  Building nspr for architecture arm64
:debug:build setting option build.dir to /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64
:debug:build Environment:
:debug:build CC_PRINT_OPTIONS='YES'
:debug:build CC_PRINT_OPTIONS_FILE='/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/.CC_PRINT_OPTIONS'
:debug:build CPATH='/opt/local/include'
:debug:build DEVELOPER_DIR='/Library/Developer/CommandLineTools'
:debug:build LIBRARY_PATH='/opt/local/lib'
:debug:build MACOSX_DEPLOYMENT_TARGET='11.0'
:debug:build SDKROOT='/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk'
:info:build Executing:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64" && /usr/bin/make -j4 -w all
:debug:build system:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64" && /usr/bin/make -j4 -w all
:info:build make: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64'
:info:build /Library/Developer/CommandLineTools/usr/bin/make -C config export
:info:build make[1]: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/config'
:info:build /usr/bin/clang  now.o   -o now
:info:build ld: warning: ignoring file now.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
:info:build Undefined symbols for architecture x86_64:
:info:build   "_main", referenced from:
:info:build      implicit entry/start for main executable
:info:build ld: symbol(s) not found for architecture x86_64
:info:build clang: error: linker command failed with exit code 1 (use -v to see invocation)
:info:build make[1]: *** [now] Error 1
:info:build make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/config'
:info:build make: *** [export] Error 2
:info:build make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64'
:info:build Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64" && /usr/bin/make -j4 -w all
:info:build Exit code: 2
:error:build Failed to build nspr: command execution failed
:debug:build Error code: NONE
:debug:build Backtrace: command execution failed
:debug:build     while executing
:debug:build "$procedure $targetname"

Thanks.

Attachments (1)

main.log (30.8 KB) - added by potterpg 21 months ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 21 months ago by jmroot (Joshua Root)

Summary: Trying to install port that requires nspr... system setup to try and create +universal throughout, Failed to build nspr: command execution failednspr @4.34+universal arm64,x86_64 fails to build

Could you please attach the log?

Changed 21 months ago by potterpg

Attachment: main.log added

comment:2 Changed 21 months ago by potterpg

Ok, attached...

comment:3 Changed 21 months ago by jmroot (Joshua Root)

OK, so it is using -arch arm64 when compiling that file but not when linking. Possibly related to #45506?

comment:4 Changed 21 months ago by potterpg

Ok, so if that is the problem, is it being worked upon? Might there be a solution down the line?

comment:5 Changed 21 months ago by kencu (Ken)

at least part of the problem is in config/rules.mk

when the build detects it is cross-compiling, it resets the key environment variables like this:

ifdef USE_AUTOCONF
ifdef CROSS_COMPILE
ifdef INTERNAL_TOOLS
CC=$(HOST_CC)
CCC=$(HOST_CXX)
CFLAGS=$(HOST_CFLAGS)
CXXFLAGS=$(HOST_CXXFLAGS)
LDFLAGS=$(HOST_LDFLAGS)
endif
endif
endif

but as none of those HOST* variables are defined, they all come up empty, it appears, and therefore no LDFLAGS are used in the link.

doing something like this in the Portfile:

configure.env-append HOST_CC=${configure.cc} \
                     HOST_CXX=${configure.cxx} \
                     HOST_CFLAGS=${configure.cflags} \
                     HOST_CXXFLAGS=${configure.cxxflags} \
                     HOST_LDFLAGS=${configure.ldflags}


actually does result in a successful universal build of nspr arm64/x86_64, building on Intel at least.

 % port -v installed nspr
The following ports are currently installed:
  nspr @4.34_0+universal (active) requested_variants='+universal' platform='darwin 21' archs='arm64 x86_64' date='2022-07-26T09:27:54-0700'

But it's still not 100% right as ${configure.ldflags} is not properly set up at this point in the Portfile and the environment variable is incomplete still.

comment:6 Changed 21 months ago by kencu (Ken)

I presume some merger.ldflags etc magic is needed to tweak the muniversal Portgroup to do the exact right thing.

No doubt this is a 10 second thing for Josh or Ryan, or someone might grep the ports tree and see where it has been done before in some other port.

comment:7 Changed 21 months ago by potterpg

Sounds great! Thanks for looking at this. If I wanted to try your test, where is the Portfile you talk about?

comment:8 Changed 21 months ago by kencu (Ken)

you can do something like this:

bbedit `port file nspr`

then paste in this below the configure.args part:

configure.env-append HOST_CC=${configure.cc} \
                     HOST_CXX=${configure.cxx} \
                     HOST_CFLAGS=${configure.cflags} \
                     HOST_CXXFLAGS=${configure.cxxflags} \
                     HOST_LDFLAGS=${configure.ldflags}

then

sudo port clean nspr; sudo port -v install nspr +universal

and it will probably work to install a universal nspr, as it did for me. But I'm not pushing it to master as it is still not 100% right, and needs a bit better tweaking than that to be accepted into the main ports tree.

comment:9 Changed 21 months ago by potterpg

So, yes it seemed to work for me, lipo reports a universal static lib... So thanks for that, and I'm a little wiser as to how ports work....

comment:10 Changed 21 months ago by kencu (Ken)

well fixing nspr to use the proper flags during compiling and linking just runs into an error when it tries to run the arm64 binary on the intel system :>

So paradoxically the "bad" fix above, which does the wrong thing with the archs, actually works... hah.

Executing:  cd "/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64" && /usr/bin/make -j8 -w all 
make: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64'
/Library/Developer/CommandLineTools/usr/bin/make -C config export
make[1]: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/config'
/usr/bin/clang -arch arm64 -o now.o -c    -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -pipe -Os -arch arm64 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -Wall -fno-common -pthread -Os -fPIC  -UDEBUG -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DNDEBUG=1 -DXP_UNIX=1 -DDARWIN=1 -DHAVE_BSD_FLOCK=1 -DHAVE_SOCKLEN_T=1 -DHAVE_POINTER_LOCALTIME_R=1 -DHAS_CONNECTX=1 -DHAVE_CRT_EXTERNS_H=1 -DHAVE_DLADDR=1 -DHAVE_LCHOWN=1 -DHAVE_SETPRIORITY=1 -DHAVE_STRERROR=1 -DHAVE_SYSCALL=1 -DFORCE_PR_LOG -D_PR_PTHREADS -UHAVE_CVAR_BUILT_ON_SEM   now.c
/usr/bin/clang -arch arm64  now.o -L/opt/local/lib -Wl,-headerpad_max_install_names -arch arm64 -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk  -o now
/usr/bin/clang -arch arm64 -o nsinstall.o -c    -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -pipe -Os -arch arm64 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -Wall -fno-common -pthread -Os -fPIC  -UDEBUG -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DNDEBUG=1 -DXP_UNIX=1 -DDARWIN=1 -DHAVE_BSD_FLOCK=1 -DHAVE_SOCKLEN_T=1 -DHAVE_POINTER_LOCALTIME_R=1 -DHAS_CONNECTX=1 -DHAVE_CRT_EXTERNS_H=1 -DHAVE_DLADDR=1 -DHAVE_LCHOWN=1 -DHAVE_SETPRIORITY=1 -DHAVE_STRERROR=1 -DHAVE_SYSCALL=1 -DFORCE_PR_LOG -D_PR_PTHREADS -UHAVE_CVAR_BUILT_ON_SEM   nsinstall.c
/usr/bin/clang -arch arm64  nsinstall.o -L/opt/local/lib -Wl,-headerpad_max_install_names -arch arm64 -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk  -o nsinstall
rm -f nfspwd; cp nfspwd.pl nfspwd; chmod +x nfspwd
rm -f ../dist/bin/nspr-config
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/config'
/Library/Developer/CommandLineTools/usr/bin/make -C pr export
make[1]: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/pr'
/Library/Developer/CommandLineTools/usr/bin/make -C include export
make[2]: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/pr/include'
/Library/Developer/CommandLineTools/usr/bin/make -C md export
make[3]: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr-arm64/pr/include/md'
../../../config/./nsinstall -R -m 444 ./_aix32.cfg ./_aix64.cfg ./_bsdi.cfg ./_darwin.cfg ./_freebsd.cfg ./_hpux32.cfg ./_hpux64.cfg ./_linux.cfg ./_netbsd.cfg ./_nto.cfg ./_openbsd.cfg ./_os2.cfg ./_qnx.cfg ./_riscos.cfg ./_scoos.cfg ./_solaris.cfg ./_unixware.cfg ./_unixware7.cfg ./_win95.cfg ./_winnt.cfg ../../../dist/include/nspr/md
make[3]: ../../../config/./nsinstall: Bad CPU type in executable
make[3]: *** [export] Error 1

comment:11 Changed 21 months ago by kencu (Ken)

removing the muniversal PortGroup throws an "i386" arch into the mix based on the ancient coding of this build system, which fails:

--->  Building nspr
Executing:  cd "/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr" && /usr/bin/make -j8 -w all 
make: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr'
/Library/Developer/CommandLineTools/usr/bin/make -C config export
make[1]: Entering directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr/config'
/usr/bin/clang -arch i386 -o now.o -c    -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -arch arm64 -arch x86_64 -Wall -fno-common -Os -fPIC  -UDEBUG -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DNDEBUG=1 -DXP_UNIX=1 -DDARWIN=1 -DHAVE_BSD_FLOCK=1 -DHAVE_SOCKLEN_T=1 -DHAVE_POINTER_LOCALTIME_R=1 -DHAS_CONNECTX=1 -DHAVE_CRT_EXTERNS_H=1 -DFORCE_PR_LOG -D_PR_PTHREADS -UHAVE_CVAR_BUILT_ON_SEM   now.c
/usr/bin/clang -arch i386  now.o -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -arch arm64 -arch x86_64  -o now
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/lib/libSystem.tbd (3 slices)
Undefined symbols for architecture i386:
  "___stdoutp", referenced from:
      _main in now.o
  "_fprintf", referenced from:
      _main in now.o
  "_time", referenced from:
      _main in now.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [now] Error 1
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr/config'
make: *** [export] Error 2
make: Leaving directory `/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr'
Command failed:  cd "/opt/local/var/macports/build/_opt_macports-ports_devel_nspr/nspr/work/nspr-4.34/nspr" && /usr/bin/make -j8 -w all 
Exit code: 2
Note: See TracTickets for help on using tickets.