The Linux kernels ELF-FDPIC binfmt program loader can support loading and
running conventional ELF format binaries on noMMU kernels when compiled
appropriately. That is when they are constant displacement binaries such
as generated using the -pie compile option.
Add a configure option to allow selecting ELF binary support in noMMU
mode configurations on architectures that support this. The main
requirement is to generate the ldso run-time loader to perform relocation
at load time. These configurations do not support shared libraries, so
there is no need to generate a full shared library, only the static
version is required.
The use of ELF format binaries does mean a slightly simpler toolchain
generation (does not require a -uclinux- for some architectures) and does
not require an extra tool like elf2flt.
This initial support targets M68K, ARM and RISC-V architectures. No kernel
changes are required, the required support for this is already in mainline
kernels (certainly as of linux-6.6).
Note that for the M68K and ARM architectures that the initialized
registers and stack layout at process startup is slightly different for
the flat format loader and the ELF/ELF-FDPIC loaders. So we need some
changes to the startup code (crt1.S) for them.
I have not done extensive testing outside of M68K, ARM and RISC-V.
I had to make changes to a couple of the dl-startup.h architecture files
to get them to build for this noMMU case. I did not dig down too deep on
the reasons, but they still seem ok for the MMU case as well.
Signed-off-by: Greg Ungerer <gerg(a)linux-m68k.org>
---
Makerules | 3 +++
Rules.mak | 2 ++
extra/Configs/Config.in | 9 +++++++--
extra/Configs/Config.in.arch | 8 ++++++++
ldso/include/dl-defs.h | 2 --
ldso/include/ldso.h | 2 +-
ldso/ldso/arm/dl-startup.h | 2 ++
ldso/ldso/m68k/dl-startup.h | 3 +++
ldso/ldso/m68k/dl-sysdep.h | 2 ++
ldso/ldso/riscv64/dl-startup.h | 2 ++
libc/sysdeps/linux/arm/crt1.S | 2 +-
libc/sysdeps/linux/m68k/crt1.S | 10 +++++++---
12 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/Makerules b/Makerules
index 845d81897..1a7443c39 100644
--- a/Makerules
+++ b/Makerules
@@ -22,6 +22,9 @@ ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
libs: $(lib-gdb-y)
endif
libs: $(lib-a-y)
+ifeq ($(HAVE_LDSO),y)
+$(lib-a-y): | $(ldso)
+endif
endif
objs: all_objs
$(lib-so-y) $(lib-a-y): | $(top_builddir)lib
diff --git a/Rules.mak b/Rules.mak
index 5b9154b72..2aacee521 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -167,6 +167,8 @@ endif
ifneq ($(HAVE_SHARED),y)
libc :=
+endif
+ifneq ($(HAVE_LDSO),y)
interp :=
ldso :=
endif
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index 287db13d2..18748d54b 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -333,8 +333,9 @@ config STATIC_PIE
bool "Add support for Static Position Independent Executables (PIE)"
default n
depends on DOPIC && !UCLIBC_FORMAT_FDPIC_ELF && \
- (TARGET_arm || TARGET_i386 || TARGET_x86_64 || TARGET_aarch64 || \
- TARGET_mips || TARGET_xtensa || TARGET_powerpc)
+ (TARGET_aarch64 || TARGET_arm || TARGET_i386 || \
+ TARGET_m68k || TARGET_mips || TARGET_powerpc || \
+ TARGET_riscv64 || TARGET_x86_64 || TARGET_xtensa)
config ARCH_HAS_NO_SHARED
bool
@@ -346,9 +347,13 @@ config ARCH_HAS_NO_LDSO
config ARCH_HAS_UCONTEXT
bool
+config HAVE_LDSO
+ bool
+
config HAVE_SHARED
bool "Enable shared libraries"
depends on !ARCH_HAS_NO_SHARED
+ select HAVE_LDSO
default y
help
If you wish to build uClibc with support for shared libraries then
diff --git a/extra/Configs/Config.in.arch b/extra/Configs/Config.in.arch
index 91b639493..4bcf3ff3f 100644
--- a/extra/Configs/Config.in.arch
+++ b/extra/Configs/Config.in.arch
@@ -10,6 +10,14 @@
if !ARCH_USE_MMU
choice
prompt "Target File Format"
+config UCLIBC_FORMAT_ELF
+ bool "ELF (using ELF_FDPIC loader)"
+ depends on !ARCH_USE_MMU && (TARGET_arm || TARGET_m68k || \
+ TARGET_riscv64)
+ select DOPIC
+ select STATIC_PIE
+ select ARCH_HAS_NO_SHARED
+ select HAVE_LDSO
config UCLIBC_FORMAT_FDPIC_ELF
bool "FDPIC ELF"
depends on !ARCH_USE_MMU && (TARGET_bfin || TARGET_frv || TARGET_arm)
diff --git a/ldso/include/dl-defs.h b/ldso/include/dl-defs.h
index daa6685cb..e404f17ec 100644
--- a/ldso/include/dl-defs.h
+++ b/ldso/include/dl-defs.h
@@ -72,10 +72,8 @@ typedef struct {
#endif
#ifdef _LIBC
-#ifndef __ARCH_HAS_NO_SHARED__
/* arch specific defines */
#include <dl-sysdep.h>
-#endif
#ifdef __TARGET_c6x__
#include <dl-sysdep.h>
#endif
diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h
index 8d9d057a0..80d5d5dd5 100755
--- a/ldso/include/ldso.h
+++ b/ldso/include/ldso.h
@@ -48,7 +48,7 @@
/* Pull in the MIN macro */
#include <sys/param.h>
/* Pull in the ldso syscalls and string functions */
-#ifndef __ARCH_HAS_NO_SHARED__
+#if !defined(__ARCH_HAS_NO_SHARED__) || !defined(__ARCH_HAS_NO_LDSO__)
#include <dl-syscall.h>
#include <dl-string.h>
/* Now the ldso specific headers */
diff --git a/ldso/ldso/arm/dl-startup.h b/ldso/ldso/arm/dl-startup.h
index cacd461e1..d00e7b053 100644
--- a/ldso/ldso/arm/dl-startup.h
+++ b/ldso/ldso/arm/dl-startup.h
@@ -301,3 +301,5 @@ int raise(int sig)
_dl_exit(1);
}
#endif /* __FDPIC__ */
+
+#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR)
diff --git a/ldso/ldso/m68k/dl-startup.h b/ldso/ldso/m68k/dl-startup.h
index dfece443f..9c3285e27 100644
--- a/ldso/ldso/m68k/dl-startup.h
+++ b/ldso/ldso/m68k/dl-startup.h
@@ -55,6 +55,9 @@ _dl_start_user:\n\
* do something a little more subtle here. */
#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1)
+/* We can't call functions earlier in the dl startup process */
+#define NO_FUNCS_BEFORE_BOOTSTRAP
+
/* Handle relocation of the symbols in the dynamic loader. */
static __always_inline
void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
diff --git a/ldso/ldso/m68k/dl-sysdep.h b/ldso/ldso/m68k/dl-sysdep.h
index 21937b259..5d2d7a097 100644
--- a/ldso/ldso/m68k/dl-sysdep.h
+++ b/ldso/ldso/m68k/dl-sysdep.h
@@ -83,3 +83,5 @@ elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
*reloc_addr = load_off + rpnt->r_addend;
} while (--relative_count);
}
+
+#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR)
diff --git a/ldso/ldso/riscv64/dl-startup.h b/ldso/ldso/riscv64/dl-startup.h
index dabe1bebd..82e525e66 100644
--- a/ldso/ldso/riscv64/dl-startup.h
+++ b/ldso/ldso/riscv64/dl-startup.h
@@ -88,3 +88,5 @@ void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, ElfW(Addr) *reloc_addr,
_dl_exit(1);
}
}
+
+#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR)
diff --git a/libc/sysdeps/linux/arm/crt1.S b/libc/sysdeps/linux/arm/crt1.S
index fade1d25c..799f11080 100644
--- a/libc/sysdeps/linux/arm/crt1.S
+++ b/libc/sysdeps/linux/arm/crt1.S
@@ -245,7 +245,7 @@ _start:
mov fp, #0
mov lr, #0
-#ifdef __ARCH_USE_MMU__
+#if defined(__ARCH_USE_MMU__) || defined(__UCLIBC_FORMAT_ELF__)
#ifdef L_rcrt1
/* We don't need to save a1 since no dynamic linker should have run */
ldr a1, .L_GOT /* Get value at .L_GOT + 0 (offset to GOT)*/
diff --git a/libc/sysdeps/linux/m68k/crt1.S b/libc/sysdeps/linux/m68k/crt1.S
index 815a6076f..e7292682b 100644
--- a/libc/sysdeps/linux/m68k/crt1.S
+++ b/libc/sysdeps/linux/m68k/crt1.S
@@ -78,9 +78,13 @@ _start:
sub.l %fp, %fp
#if !defined __ARCH_USE_MMU__ && defined __PIC__
+#ifdef UCLIBC_FORMAT_ELF
+ move.l #_GLOBAL_OFFSET_TABLE_, %a5
+#else
/* Set up the global pointer. The GOT is at the beginning of the
data segment, whose address is in %d5. */
move.l %d5,%a5
+#endif
.equ have_current_got, 1
#endif
@@ -92,11 +96,11 @@ _start:
arguments for `main': argc, argv. envp will be determined
later in __libc_start_main. */
move.l (%sp)+, %d0 /* Pop the argument count. */
-#ifndef __ARCH_USE_MMU__
- move.l (%sp)+, %a0
-#else
+#if defined(__ARCH_USE_MMU__) || defined(__UCLIBC_FORMAT_ELF__)
move.l %sp, %a0 /* The argument vector starts just at the
current stack top. */
+#else
+ move.l (%sp)+, %a0
#endif
/* Provide the highest stack address to the user code (for stacks
--
2.25.1
When compiling getaddrinfo.c with clang the -Wmisleading-indentation
option will cause a warning due to the indentation lining up with the
previous statement in the if block above.
For gcc the warning is blinded by the commented line. See also:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107162
Move the comment behind the function call to make both compilers happy.
---
libc/inet/getaddrinfo.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libc/inet/getaddrinfo.c b/libc/inet/getaddrinfo.c
index a9000ae13..f34a4726c 100644
--- a/libc/inet/getaddrinfo.c
+++ b/libc/inet/getaddrinfo.c
@@ -959,8 +959,7 @@ getaddrinfo(const char *name, const char *service,
last_i = i;
if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
continue;
- /*if (p) - freeaddrinfo works ok on NULL too */
- freeaddrinfo(p);
+ freeaddrinfo(p); /* freeaddrinfo works ok on NULL too */
return -(i & GAIH_EAI);
}
if (end)
--
2.42.0
I would like to extend the functions that can be utilized from the vDSO to
check for potential issues with combinations of config, architecture,
kernel, and gcc. I've created GitHub workflows for this purpose at
https://github.com/lordrasmus/uclibc-ng. Currently, the kvx port has shown
the most success with the highest number of passed tests.
I encountered an issue where busybox, when statically linked, fails with
vDSO support. The problem lies in _dl__vdso_gettimeofday, which is present
in ld-uClibc_so.a but not in libc.a.
It seems that busybox cannot utilize ld-uClibc_so.a because it's not
installed into the sysroot. I'm seeking suggestions on how to resolve this
issue. If anyone has ideas or solutions, please share them.
Additionally, if there are any suggestions for improving my workflows, I
would appreciate the input.
I'm currently developing a tool to simplify the download of files such as
configuration and compilers used in the workflow for local checking. This
tool also integrates the ability to run tests on qemu. You can find it at
https://github.com/lordrasmus/uclibc-ng-dev.
From: Pavel Kozlov <pavel.kozlov(a)synopsys.com>
Linux kernel returns -1ULL as RLIM64_INFINITY for all cpus.
Fix RLIM64_INFINTIY and 64-bit variant of RLIM_INFINITY macro for
sparc, mips, alpha, as for these CPUs the library uses different
value than what the kernel sets and it can cause incorrect
RLIM64_INFINTY check.
Because alpha is a 64-bit arch, fix the RLIM_INFINITY macro twice
(the value should be the same with and without __USE_FILE_OFFSET64
definition) to match the prlimit64 syscall in the kernel.
Previous implementation of setrlimit/getrlimit functions didn't use
prlimit64 syscall and didn't receive RLIM64_INFINTIY from the kernel,
RLIM64_INFINTY macro was used by the library itself to mimic the
64-bit rlimit in the getrlimit64/setrlimit64 functions, that allowed
to have RLIM64_INFINTIY different from what the kernel sets.
New implementation of setrlimit/getrlimit uses prlimit64 and checks
for RLIM64_INFINITY value and must have equal RLIM64_INFINITY
definition with what the kernel uses.
This issue is indicated by the tst-rlim/tst-rlim64 tests
on sparc/mips32/alpha, tests return 23 (UNSUPPORTED) because of
incorrect RLIM_INFINTY check for available rlimit type.
This patch will require rebuild of sparc/mips32/alpha binaries that
explicitly use RLIM64_INFINTY or 64-bit variant of RLIM_INFINITY
(if binary for 32-bit CPU was built with _FILE_OFFSET_BITS=64) to
update the macro value.
Signed-off-by: Pavel Kozlov <pavel.kozlov(a)synopsys.com>
---
libc/sysdeps/linux/alpha/bits/resource.h | 6 +++---
libc/sysdeps/linux/mips/bits/resource.h | 4 ++--
libc/sysdeps/linux/sparc/bits/resource.h | 4 ++--
libc/sysdeps/linux/sparc64/bits/resource.h | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/libc/sysdeps/linux/alpha/bits/resource.h b/libc/sysdeps/linux/alpha/bits/resource.h
index 38f73961e99d..dba818714d84 100644
--- a/libc/sysdeps/linux/alpha/bits/resource.h
+++ b/libc/sysdeps/linux/alpha/bits/resource.h
@@ -113,13 +113,13 @@ enum __rlimit_resource
/* Value to indicate that there is no limit. */
#ifndef __USE_FILE_OFFSET64
-# define RLIM_INFINITY ((long int)(~0UL >> 1))
+# define RLIM_INFINITY ((unsigned long int)(~0UL))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
#endif
/* We can represent all limits. */
diff --git a/libc/sysdeps/linux/mips/bits/resource.h b/libc/sysdeps/linux/mips/bits/resource.h
index 5690527bf9a3..97487d274f21 100644
--- a/libc/sysdeps/linux/mips/bits/resource.h
+++ b/libc/sysdeps/linux/mips/bits/resource.h
@@ -123,10 +123,10 @@ enum __rlimit_resource
# ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((long int)(~0UL >> 1))
# else
-# define RLIM_INFINITY 0x7fffffffffffffffULL
+# define RLIM_INFINITY 0xffffffffffffffffULL
# endif
# ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffULL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
# endif
#endif
diff --git a/libc/sysdeps/linux/sparc/bits/resource.h b/libc/sysdeps/linux/sparc/bits/resource.h
index a5ec31e4e677..48e1049f41a6 100644
--- a/libc/sysdeps/linux/sparc/bits/resource.h
+++ b/libc/sysdeps/linux/sparc/bits/resource.h
@@ -114,11 +114,11 @@ enum __rlimit_resource
#ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((long int)(~0UL >> 1))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
#endif
/* We can represent all limits. */
diff --git a/libc/sysdeps/linux/sparc64/bits/resource.h b/libc/sysdeps/linux/sparc64/bits/resource.h
index f1e11e239602..84c76878520d 100644
--- a/libc/sysdeps/linux/sparc64/bits/resource.h
+++ b/libc/sysdeps/linux/sparc64/bits/resource.h
@@ -128,11 +128,11 @@ enum __rlimit_resource
#ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((long int)(~0UL >> 1))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
#endif
#endif
--
2.25.1
Hi Ramin,
> the variable i is overwritten with 0 after the getrlimit() call
> my guess is that rlim needs a 8 byte alignment on sparc
Thanks for sharing this problem.
> i'm using the current uclibc-ng master ( only a few commits are not merged )
Please point to the exact commit you are on.
If you are somewhere between:
95e38b37 ("add support for systems without legacy setrlimit/getrlimit syscalls")
and
8c2f6218 (setrlimit/getrlimit: fix prlimit64 syscall use for 32-bit CPUs)
then I have a simple explanation for this problem, and it is already
fixed by the 8c2f6218 and the following commits. Please check the
8c2f6218 commit description.
Regards,
- Pavel
From: Ramin Moussavi <lordrasmus(a)gmail.com>
Sent: Tuesday, November 14, 2023 11:47 PM
To: Waldemar Brodkorb <mail(a)waldemar-brodkorb.de>
Cc: devel(a)uclibc-ng.org <devel(a)uclibc-ng.org>
Subject: [uclibc-ng-devel] Re: diable misc tests
i'm using the current uclibc-ng master ( only a few commits are not merged )
i wanted to report that issue later when know what is going wrong
for now i just disabled the misc tests on sparc
what i discovered is that when running the test suite on qemu sparc the test tst-rlimit.c runs into an endless loop
here is what is happening on my build
int main(void)
{
int rnum = -1;
struct rlimit rlim;
int i, ret;
/* Find a resource with hard limit set to infinity */
for (i = 0; i < nresources; ++i) {
ret = getrlimit(resources[i], &rlim);
if ((!ret) && (rlim.rlim_max == RLIM_INFINITY)) {
rnum = resources[i];
break;
}
}
the variable i is overwritten with 0 after the getrlimit() call
my guess is that rlim needs a 8 byte alignment on sparc
when i set the alignment for rlim to 8 bytes via gcc attributes the tests runs fine
for now i don't know if its a gcc , qemu or kernel issue
Am Di., 14. Nov. 2023 um 14:27 Uhr schrieb Waldemar Brodkorb <wbx(a)uclibc-ng.org>:
Hi,
works for me. You need to use uclibc-ng master for the new
rlimit tests.
I pushed them to github now.
best regards
Waldemar
Ramin Moussavi wrote,
>
> _______________________________________________
> devel mailing list -- devel(a)uclibc-ng.org
> To unsubscribe send an email to devel-leave(a)uclibc-ng.org
In certain cases, fnmatch() could access the next byte beyond the end of
he passed pattern. A triggering pattern to match is the following
invocation:
fnmatch("[A-Z[.", "F", 0)
The normal A-Z group match gets us to fnmatch_loop.c:421 and then to
fnmatch_loop:599. The F in the filaname matches this expression and
we end up in fnmatch_loop:867 which handles skipping the rest of a
bracked expression that already matched. Here we enter the case where
the next chars to parse are a collating symbol starting with "[."
(fnmatch_loop:918). Currently the p pointer is then advanced by one,
moving it beyond the "." and to the \0 byte of the pattern string
(fnmatch_loop:920). Inside the while loop the pointer is then
incremented again and immediately dereferenced, reaching beyond the
end of the pattern string.
The increment before the while loop must be removed, because only inside
the while loop (after the other increment) a check for the end of the
string is performend. This is sufficient and the check of the end of
the collating symbol is only performed if p[1] is at most the
terminating \0 byte.
Signed-Off-By: Frank Mehnert <frank.mehnert(a)kernkonzept.com>
---
libc/misc/fnmatch/fnmatch_loop.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libc/misc/fnmatch/fnmatch_loop.c b/libc/misc/fnmatch/fnmatch_loop.c
index 32ee079a3..025510de6 100644
--- a/libc/misc/fnmatch/fnmatch_loop.c
+++ b/libc/misc/fnmatch/fnmatch_loop.c
@@ -917,7 +917,6 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
else if (c == L('[') && *p == L('.'))
{
- ++p;
while (1)
{
c = *++p;
--
2.42.0