tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
ilp32 vs. lp64 vs. 64-bit atomics
Hi,
I came to build security/openssl 3.4.1 on my NetBSD/mipsel
virtual host, and that failed with
ld: ./libcrypto.so: undefined reference to `__atomic_fetch_sub_8'
ld: ./libcrypto.so: undefined reference to `__atomic_fetch_and_8'
ld: ./libcrypto.so: undefined reference to `__atomic_store_8'
ld: ./libcrypto.so: undefined reference to `__atomic_load_8'
ld: ./libcrypto.so: undefined reference to `__atomic_compare_exchange_8'
ld: ./libcrypto.so: undefined reference to `__atomic_fetch_or_8'
ld: ./libcrypto.so: undefined reference to `__atomic_fetch_add_8'
Looking at the Makefile it has a simple bug:
.if ${OPSYS} == "NetBSD" && \
((${MACHINE_ARCH} == "arm") || \
(${MACHINE_ARCH} == "hppa") || \
(${MACHINE_ARCH} == "i386") || \
(${MACHINE_ARCH} == "m68k") || \
(${MACHINE_ARCH} == "mips") || \
(${MACHINE_ARCH} == "powerpc") || \
(${MACHINE_ARCH} == "riscv32") || \
(${MACHINE_ARCH} == "sh3eb") || \
(${MACHINE_ARCH} == "sh3el") || \
(${MACHINE_ARCH} == "sparc") || \
(${MACHINE_ARCH} == "vax"))
# Use OpenSSL's built-in fallbacks (not actually clang-specific)
# see src/crypto/external/bsd/openssl/lib/libcrypto/arch/*/crypto.inc
CFLAGS+= -DBROKEN_CLANG_ATOMICS # no atomic 64 bit ops
.endif
It's either "mipsel" or "mipseb" for the 32-bit mips ports.
Looking at mk/atomic64.mk (which apparently should not be used in
openssl), it has a different set of conditionals:
First off, for i386, if machine arch isn't specified already, it
forces i586 to get native 64-bit atomics. For the rest it does:
# Non-NetBSD vendors tend to include libatomic as part of gcc.
.if ${OPSYS} == "NetBSD" && \
(${MACHINE_ARCH} == "m68k" || \
${MACHINE_ARCH} == "mipsel" || \
${MACHINE_ARCH} == "mipseb" || \
${MACHINE_ARCH} == "powerpc" || \
${MACHINE_ARCH} == "sh3el" || \
${MACHINE_ARCH} == "sh3eb" || \
${MACHINE_ARCH} == "sparc" || \
${MACHINE_ARCH} == "vax" || \
!empty(MACHINE_ARCH:Mearm*))
. include "../../devel/libatomic/buildlink3.mk"
.endif
The latter has the correct test for the 32-bit mips ports, and
also has the correct conditional for 32-bit arm. But where is
hppa and riscv32 in the latter?
I'm looking at what "cc -E -dD - </dev/null" with gcc produces,
and on an ilp32 (powerpc) host I get
#define __INT_WIDTH__ 32
#define __LONG_WIDTH__ 32
#define __PTRDIFF_WIDTH__ 32
and on an lp64 (aarch64) host I get
#define __INT_WIDTH__ 32
#define __LONG_WIDTH__ 64
#define __LP64__ 1
#define __PTRDIFF_WIDTH__ 64
First off, the list in atomic64.mk can get a "static" update,
adding hppa and riscv32, and the "arm" and "mips" entries in
openssl's Makefile can also be fixed.
There is also a near-certain correspondence between "being an
ilp32 port" and "being in need of assistance to do 64-bit
atomics". There are exceptions, e.g. for i386, which from
pentium on has 64-bit native atomics.
It is a little tempting to replace the static list with dynamic
detetion of ilp32 vs. lp64-ness. However, replacing the above
static lists of machine architectures with a dynamic test for
ilp32 vs. lp64 host type is going to cost a cc invocation each
time, and it's not like these lists vary much, so perhaps that's
unwanted, and we just continue with static arch lists?
Comments?
Regards,
- Håvard
Home |
Main Index |
Thread Index |
Old Index