diff mbox series

[uclibc-ng-devel] Odd thing in aarch64 support

Message ID 20220726160449.66bf6e7d@windsurf
State Accepted
Headers show
Series [uclibc-ng-devel] Odd thing in aarch64 support | expand

Commit Message

Thomas Petazzoni July 26, 2022, 2:04 p.m. UTC
Hello,

While looking at some uClibc code, I stumbled across the following
snippet in Rules.mak:

UCLIBC_LDSO_NAME := ld-uClibc
ARCH_NATIVE_BIT := 32
ifneq ($(findstring  $(TARGET_ARCH) , hppa64 ia64 powerpc64 s390x sparc64 x86_64 kvx ),)
UCLIBC_LDSO_NAME := ld64-uClibc
ARCH_NATIVE_BIT := 64
else
ifeq ($(CONFIG_MIPS_N64_ABI),y)
UCLIBC_LDSO_NAME := ld64-uClibc
ARCH_NATIVE_BIT := 64
endif
endif

I was surprised not to see aarch64 in the list of 64-bit architectures
here. Turns out that the situation is not that simple in fact. Indeed,
gcc does not expect all 64-bit architecture to have their dynamic
loader called ld64-uClibc. For aarch64 specifically, it indeed assumes
the dynamic loader is called ld-uClibc, which explains why it is
working today.

However, it means that ARCH_NATIVE_BIT is defined to 32 on aarch64,
which is obviously (?) wrong.

But turns out that ARCH_NATIVE_BIT is only used in utils/porting.h to
define __WORDSIZE and __WORDSIZE is only used in utils/ldd.c.

So to me, it seems like this would gain in being clarified. Something
like (completely untested):

Best regards,

Thomas Petazzoni

Comments

Waldemar Brodkorb Aug. 11, 2022, 12:22 a.m. UTC | #1
Hi Thomas,
Thomas Petazzoni wrote,

> Hello,
> 
> While looking at some uClibc code, I stumbled across the following
> snippet in Rules.mak:
> 
> UCLIBC_LDSO_NAME := ld-uClibc
> ARCH_NATIVE_BIT := 32
> ifneq ($(findstring  $(TARGET_ARCH) , hppa64 ia64 powerpc64 s390x sparc64 x86_64 kvx ),)
> UCLIBC_LDSO_NAME := ld64-uClibc
> ARCH_NATIVE_BIT := 64
> else
> ifeq ($(CONFIG_MIPS_N64_ABI),y)
> UCLIBC_LDSO_NAME := ld64-uClibc
> ARCH_NATIVE_BIT := 64
> endif
> endif
> 
> I was surprised not to see aarch64 in the list of 64-bit architectures
> here. Turns out that the situation is not that simple in fact. Indeed,
> gcc does not expect all 64-bit architecture to have their dynamic
> loader called ld64-uClibc. For aarch64 specifically, it indeed assumes
> the dynamic loader is called ld-uClibc, which explains why it is
> working today.
> 
> However, it means that ARCH_NATIVE_BIT is defined to 32 on aarch64,
> which is obviously (?) wrong.
> 
> But turns out that ARCH_NATIVE_BIT is only used in utils/porting.h to
> define __WORDSIZE and __WORDSIZE is only used in utils/ldd.c.
> 
> So to me, it seems like this would gain in being clarified. Something
> like (completely untested):

Thanks for your report.

I tested your patch and it seems to work and is now part of 1.0.42
release.

best regards
 Waldemar
diff mbox series

Patch

diff --git a/Rules.mak b/Rules.mak
index 3fb64c728..a0b012d7f 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -142,17 +142,8 @@  export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION ABI_VERSION LC_ALL
 LIBC := libc
 SHARED_LIBNAME := $(LIBC).so.$(ABI_VERSION)
 
-UCLIBC_LDSO_NAME := ld-uClibc
-ARCH_NATIVE_BIT := 32
-ifneq ($(findstring  $(TARGET_ARCH) , hppa64 ia64 powerpc64 s390x sparc64 x86_64 kvx ),)
-UCLIBC_LDSO_NAME := ld64-uClibc
-ARCH_NATIVE_BIT := 64
-else
-ifeq ($(CONFIG_MIPS_N64_ABI),y)
-UCLIBC_LDSO_NAME := ld64-uClibc
-ARCH_NATIVE_BIT := 64
-endif
-endif
+UCLIBC_LDSO_NAME := $(call qstrip,$(TARGET_LDSO_NAME))
+ARCH_NATIVE_BIT := $(call qstrip,$(TARGET_ARCH_BITS))
 
 UCLIBC_LDSO := $(UCLIBC_LDSO_NAME).so.$(ABI_VERSION)
 NONSHARED_LIBNAME := uclibc_nonshared.a
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index a49278b30..e6369bd82 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -145,6 +145,26 @@  config TARGET_xtensa
 
 endchoice
 
+config TARGET_LDSO_NAME
+	string
+	default "ld64-uClibc" if TARGET_ia64
+	default "ld64-uClibc" if TARGET_powerpc64
+	default "ld64-uClibc" if TARGET_sparc64
+	default "ld64-uClibc" if TARGET_x86_64
+	default "ld64-uClibc" if TARGET_kvx
+	default "ld64-uClibc" if CONFIG_MIPS_N64_ABI
+	default "ld-uClibc"
+
+config TARGET_ARCH_BITS
+	int
+	default 64 if TARGET_aarch64
+	default 64 if TARGET_ia64
+	default 64 if TARGET_powerpc64
+	default 64 if TARGET_sparc64
+	default 64 if TARGET_x86_64
+	default 64 if TARGET_kvx
+	default 64 if CONFIG_MIPS_N64_ABI
+	default 32
 
 menu "Target Architecture Features and Options"