diff mbox series

[uclibc-ng-devel] Re: [PATCH] elf: support ELF binaries in noMMU

Message ID 3c9e82d8-f46e-4fd5-8e74-b654a2e3772b@kernel.org
State Not Applicable
Headers show
Series [uclibc-ng-devel] Re: [PATCH] elf: support ELF binaries in noMMU | expand

Commit Message

Greg Ungerer Dec. 4, 2023, 1:39 p.m. UTC
Hi Waldemar,

On 1/12/23 18:31, Waldemar Brodkorb wrote:
> THis breaks static building of target alpha:
> 
> /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/auxvt/getauxval.c -o libc/misc/auxvt/getauxval.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wp
> In file included from ./ldso/include/ldso.h:189,
>                   from libc/misc/auxvt/getauxval.c:21:
> ./ldso/include/dl-defs.h:76:10: fatal error: dl-sysdep.h: No such file or directory
>     76 | #include <dl-sysdep.h>
>        |          ^~~~~~~~~~~~~
> compilation terminated.
> gmake[6]: *** [Makerules:372: libc/misc/auxvt/getauxval.os] Error 1
> 
> I think it is this part of the patch:
> 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
> 
> Any idea?

Yes, that is definitely the cause. I mis-understood the implications
of removing that "#ifndef __ARCH_HAS_NO_SHARED__" conditional.

I am testing a different change here that I think might do ther job better:


Regards
Greg


> best regards
>   Waldemar
> 
> Greg Ungerer wrote,
> 
>> 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@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
>>
>> _______________________________________________
>> devel mailing list -- devel@uclibc-ng.org
>> To unsubscribe send an email to devel-leave@uclibc-ng.org
>>

Comments

Waldemar Brodkorb Dec. 6, 2023, 9:48 a.m. UTC | #1
Hi Greg,
Greg Ungerer wrote,

> Hi Waldemar,
> 
> On 1/12/23 18:31, Waldemar Brodkorb wrote:
> > THis breaks static building of target alpha:
> > 
> > /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/auxvt/getauxval.c -o libc/misc/auxvt/getauxval.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wp
> > In file included from ./ldso/include/ldso.h:189,
> >                   from libc/misc/auxvt/getauxval.c:21:
> > ./ldso/include/dl-defs.h:76:10: fatal error: dl-sysdep.h: No such file or directory
> >     76 | #include <dl-sysdep.h>
> >        |          ^~~~~~~~~~~~~
> > compilation terminated.
> > gmake[6]: *** [Makerules:372: libc/misc/auxvt/getauxval.os] Error 1
> > 
> > I think it is this part of the patch:
> > 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
> > 
> > Any idea?
> 
> Yes, that is definitely the cause. I mis-understood the implications
> of removing that "#ifndef __ARCH_HAS_NO_SHARED__" conditional.
> 
> I am testing a different change here that I think might do ther job better:
> 
> --- a/ldso/include/dl-defs.h
> +++ b/ldso/include/dl-defs.h
> @@ -72,7 +72,7 @@
>  #endif
> 
>  #ifdef _LIBC
> -#ifndef __ARCH_HAS_NO_SHARED__
> +#ifndef __ARCH_HAS_NO_LDSO__
>  /* arch specific defines */
>  #include <dl-sysdep.h>
>  #endif

That fixes the alpha problem, thanks.

But now it fails for ARM FDPIC target.

/home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/bin/arm-openadk-uclinuxfdpiceabi-gcc -c libc/misc/internals/reloc_static_pie.c -o libc/misc/intern
als/reloc_static_pie.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wno-nonnull-compare -funsigned-char -fno-builtin -fcommon -fno-asm -fmerge-all-constants -msoft-float -std=gnu99 -mlittle-endian -fno-stack-pro
tector -nostdinc -I./include -I./include -include libc-symbols.h -I./libc/sysdeps/linux/arm -I./libc/sysdeps/linux -I./ldso/ldso/arm -I./ldso/include -I. -DSTATIC -Os -fstrict-aliasing -fwrapv -fno-ident -mcpu=ar
m926ej-s -mfpu=vfp -mfloat-abi=soft -Os -pipe -fomit-frame-pointer -marm -Wa,-mfloat-abi=soft -I./libc/sysdeps/linux/common -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926
ej_s_soft_eabi_fdpic_arm_nommu/usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include-fixed -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/
usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include -I/home/wbx/embedded-test/openadk/target_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/include/ -DNDEBUG -fPIC -fno-stack-protecto
r -DL_rcrt1 -MT libc/misc/internals/reloc_static_pie.os -MD -MP -MF libc/misc/internals/.reloc_static_pie.os.dep
In file included from ./include/elf.h:29,
                 from ./include/link.h:24,
                 from libc/misc/internals/reloc_static_pie.c:19:
./ldso/include/dl-syscall.h: In function '_dl_pread':
./ldso/include/dl-syscall.h:234:76: warning: right shift count >= width of type [-Wshift-count-overflow]
  234 |         return __syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR((offset >> 32), (offset & 0xffffffff)));
      |                                                                            ^~
./include/endian.h:52:39: note: in definition of macro '__LONG_LONG_PAIR'
   52 | # define __LONG_LONG_PAIR(HI, LO) LO, HI
      |                                       ^~
In file included from ./ldso/ldso/arm/dl-inlines.h:1,
                 from ./ldso/include/ldso.h:185,
                 from libc/misc/internals/reloc_static_pie.c:23:
./ldso/ldso/arm/../fdpic/dl-inlines.h: In function '_dl_funcdesc_for':
./ldso/ldso/arm/../fdpic/dl-inlines.h:180:15: warning: assignment to 'struct funcdesc_value **' from incompatible pointer type 'void **' [-Wincompatible-pointer-types]
  180 |         entry = htab_find_slot(ht, entry_point, 1, hash_pointer, eq_pointer);
      |               ^
In file included from ./ldso/ldso/arm/dl-sysdep.h:144,
                 from ./ldso/include/dl-defs.h:77,
                 from ./ldso/include/dl-string.h:15,
                 from ./ldso/include/dl-elf.h:12,
                 from libc/misc/internals/reloc_static_pie.c:21:
libc/misc/internals/reloc_static_pie.c: In function 'reloc_static_pie':
./ldso/ldso/arm/../fdpic/dl-sysdep.h:88:43: error: 'dl_boot_got_pointer' undeclared (first use in this function)
   88 | #define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
...

Any idea?

best regards
 Waldemar
Greg Ungerer Dec. 7, 2023, 2:10 p.m. UTC | #2
Hi Waldemar,

On 6/12/23 19:48, Waldemar Brodkorb wrote:
> Hi Greg,
> Greg Ungerer wrote,
> 
>> Hi Waldemar,
>>
>> On 1/12/23 18:31, Waldemar Brodkorb wrote:
>>> THis breaks static building of target alpha:
>>>
>>> /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/auxvt/getauxval.c -o libc/misc/auxvt/getauxval.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wp
>>> In file included from ./ldso/include/ldso.h:189,
>>>                    from libc/misc/auxvt/getauxval.c:21:
>>> ./ldso/include/dl-defs.h:76:10: fatal error: dl-sysdep.h: No such file or directory
>>>      76 | #include <dl-sysdep.h>
>>>         |          ^~~~~~~~~~~~~
>>> compilation terminated.
>>> gmake[6]: *** [Makerules:372: libc/misc/auxvt/getauxval.os] Error 1
>>>
>>> I think it is this part of the patch:
>>> 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
>>>
>>> Any idea?
>>
>> Yes, that is definitely the cause. I mis-understood the implications
>> of removing that "#ifndef __ARCH_HAS_NO_SHARED__" conditional.
>>
>> I am testing a different change here that I think might do ther job better:
>>
>> --- a/ldso/include/dl-defs.h
>> +++ b/ldso/include/dl-defs.h
>> @@ -72,7 +72,7 @@
>>   #endif
>>
>>   #ifdef _LIBC
>> -#ifndef __ARCH_HAS_NO_SHARED__
>> +#ifndef __ARCH_HAS_NO_LDSO__
>>   /* arch specific defines */
>>   #include <dl-sysdep.h>
>>   #endif
> 
> That fixes the alpha problem, thanks.
> 
> But now it fails for ARM FDPIC target.
> 
> /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/bin/arm-openadk-uclinuxfdpiceabi-gcc -c libc/misc/internals/reloc_static_pie.c -o libc/misc/intern
> als/reloc_static_pie.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wno-nonnull-compare -funsigned-char -fno-builtin -fcommon -fno-asm -fmerge-all-constants -msoft-float -std=gnu99 -mlittle-endian -fno-stack-pro
> tector -nostdinc -I./include -I./include -include libc-symbols.h -I./libc/sysdeps/linux/arm -I./libc/sysdeps/linux -I./ldso/ldso/arm -I./ldso/include -I. -DSTATIC -Os -fstrict-aliasing -fwrapv -fno-ident -mcpu=ar
> m926ej-s -mfpu=vfp -mfloat-abi=soft -Os -pipe -fomit-frame-pointer -marm -Wa,-mfloat-abi=soft -I./libc/sysdeps/linux/common -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926
> ej_s_soft_eabi_fdpic_arm_nommu/usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include-fixed -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/
> usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include -I/home/wbx/embedded-test/openadk/target_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/include/ -DNDEBUG -fPIC -fno-stack-protecto
> r -DL_rcrt1 -MT libc/misc/internals/reloc_static_pie.os -MD -MP -MF libc/misc/internals/.reloc_static_pie.os.dep

Ok, this is strange. I don't see this with my ARM fdpic testing.

Can you send me your uClibc-ng .config file?

reloc_static_pie.os is only compiled if STATIC_PIE is enabled (as per
libc/misc/internals/Makefile.in) and STATIC_PIE can only be set if
!UCLIBC_FORMAT_FDPIC_ELF is true (as per extra/Configs/Config.in).
Unless I am missing something?

Regards
Greg



> In file included from ./include/elf.h:29,
>                   from ./include/link.h:24,
>                   from libc/misc/internals/reloc_static_pie.c:19:
> ./ldso/include/dl-syscall.h: In function '_dl_pread':
> ./ldso/include/dl-syscall.h:234:76: warning: right shift count >= width of type [-Wshift-count-overflow]
>    234 |         return __syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR((offset >> 32), (offset & 0xffffffff)));
>        |                                                                            ^~
> ./include/endian.h:52:39: note: in definition of macro '__LONG_LONG_PAIR'
>     52 | # define __LONG_LONG_PAIR(HI, LO) LO, HI
>        |                                       ^~
> In file included from ./ldso/ldso/arm/dl-inlines.h:1,
>                   from ./ldso/include/ldso.h:185,
>                   from libc/misc/internals/reloc_static_pie.c:23:
> ./ldso/ldso/arm/../fdpic/dl-inlines.h: In function '_dl_funcdesc_for':
> ./ldso/ldso/arm/../fdpic/dl-inlines.h:180:15: warning: assignment to 'struct funcdesc_value **' from incompatible pointer type 'void **' [-Wincompatible-pointer-types]
>    180 |         entry = htab_find_slot(ht, entry_point, 1, hash_pointer, eq_pointer);
>        |               ^
> In file included from ./ldso/ldso/arm/dl-sysdep.h:144,
>                   from ./ldso/include/dl-defs.h:77,
>                   from ./ldso/include/dl-string.h:15,
>                   from ./ldso/include/dl-elf.h:12,
>                   from libc/misc/internals/reloc_static_pie.c:21:
> libc/misc/internals/reloc_static_pie.c: In function 'reloc_static_pie':
> ./ldso/ldso/arm/../fdpic/dl-sysdep.h:88:43: error: 'dl_boot_got_pointer' undeclared (first use in this function)
>     88 | #define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
> ...
> 
> Any idea?
> 
> best regards
>   Waldemar
Waldemar Brodkorb Dec. 12, 2023, 4:58 a.m. UTC | #3
Hi Greg,
Greg Ungerer wrote,

> Hi Waldemar,
> 
> On 6/12/23 19:48, Waldemar Brodkorb wrote:
> > Hi Greg,
> > Greg Ungerer wrote,
> > 
> > > Hi Waldemar,
> > > 
> > > On 1/12/23 18:31, Waldemar Brodkorb wrote:
> > > > THis breaks static building of target alpha:
> > > > 
> > > > /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/auxvt/getauxval.c -o libc/misc/auxvt/getauxval.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wp
> > > > In file included from ./ldso/include/ldso.h:189,
> > > >                    from libc/misc/auxvt/getauxval.c:21:
> > > > ./ldso/include/dl-defs.h:76:10: fatal error: dl-sysdep.h: No such file or directory
> > > >      76 | #include <dl-sysdep.h>
> > > >         |          ^~~~~~~~~~~~~
> > > > compilation terminated.
> > > > gmake[6]: *** [Makerules:372: libc/misc/auxvt/getauxval.os] Error 1
> > > > 
> > > > I think it is this part of the patch:
> > > > 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
> > > > 
> > > > Any idea?
> > > 
> > > Yes, that is definitely the cause. I mis-understood the implications
> > > of removing that "#ifndef __ARCH_HAS_NO_SHARED__" conditional.
> > > 
> > > I am testing a different change here that I think might do ther job better:
> > > 
> > > --- a/ldso/include/dl-defs.h
> > > +++ b/ldso/include/dl-defs.h
> > > @@ -72,7 +72,7 @@
> > >   #endif
> > > 
> > >   #ifdef _LIBC
> > > -#ifndef __ARCH_HAS_NO_SHARED__
> > > +#ifndef __ARCH_HAS_NO_LDSO__
> > >   /* arch specific defines */
> > >   #include <dl-sysdep.h>
> > >   #endif
> > 
> > That fixes the alpha problem, thanks.
> > 
> > But now it fails for ARM FDPIC target.
> > 
> > /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/bin/arm-openadk-uclinuxfdpiceabi-gcc -c libc/misc/internals/reloc_static_pie.c -o libc/misc/intern
> > als/reloc_static_pie.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wno-nonnull-compare -funsigned-char -fno-builtin -fcommon -fno-asm -fmerge-all-constants -msoft-float -std=gnu99 -mlittle-endian -fno-stack-pro
> > tector -nostdinc -I./include -I./include -include libc-symbols.h -I./libc/sysdeps/linux/arm -I./libc/sysdeps/linux -I./ldso/ldso/arm -I./ldso/include -I. -DSTATIC -Os -fstrict-aliasing -fwrapv -fno-ident -mcpu=ar
> > m926ej-s -mfpu=vfp -mfloat-abi=soft -Os -pipe -fomit-frame-pointer -marm -Wa,-mfloat-abi=soft -I./libc/sysdeps/linux/common -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926
> > ej_s_soft_eabi_fdpic_arm_nommu/usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include-fixed -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/
> > usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include -I/home/wbx/embedded-test/openadk/target_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/include/ -DNDEBUG -fPIC -fno-stack-protecto
> > r -DL_rcrt1 -MT libc/misc/internals/reloc_static_pie.os -MD -MP -MF libc/misc/internals/.reloc_static_pie.os.dep
> 
> Ok, this is strange. I don't see this with my ARM fdpic testing.
> 
> Can you send me your uClibc-ng .config file?

The generation of the config file was broken, I fixed it up.

I committed and pushed your patch now!

Thanks 
 Waldemar
Greg Ungerer Dec. 12, 2023, 5:28 a.m. UTC | #4
Hi Waldemar,

On 12/12/23 14:58, Waldemar Brodkorb wrote:
> Hi Greg,
> Greg Ungerer wrote,
> 
>> Hi Waldemar,
>>
>> On 6/12/23 19:48, Waldemar Brodkorb wrote:
>>> Hi Greg,
>>> Greg Ungerer wrote,
>>>
>>>> Hi Waldemar,
>>>>
>>>> On 1/12/23 18:31, Waldemar Brodkorb wrote:
>>>>> THis breaks static building of target alpha:
>>>>>
>>>>> /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/auxvt/getauxval.c -o libc/misc/auxvt/getauxval.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wp
>>>>> In file included from ./ldso/include/ldso.h:189,
>>>>>                     from libc/misc/auxvt/getauxval.c:21:
>>>>> ./ldso/include/dl-defs.h:76:10: fatal error: dl-sysdep.h: No such file or directory
>>>>>       76 | #include <dl-sysdep.h>
>>>>>          |          ^~~~~~~~~~~~~
>>>>> compilation terminated.
>>>>> gmake[6]: *** [Makerules:372: libc/misc/auxvt/getauxval.os] Error 1
>>>>>
>>>>> I think it is this part of the patch:
>>>>> 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
>>>>>
>>>>> Any idea?
>>>>
>>>> Yes, that is definitely the cause. I mis-understood the implications
>>>> of removing that "#ifndef __ARCH_HAS_NO_SHARED__" conditional.
>>>>
>>>> I am testing a different change here that I think might do ther job better:
>>>>
>>>> --- a/ldso/include/dl-defs.h
>>>> +++ b/ldso/include/dl-defs.h
>>>> @@ -72,7 +72,7 @@
>>>>    #endif
>>>>
>>>>    #ifdef _LIBC
>>>> -#ifndef __ARCH_HAS_NO_SHARED__
>>>> +#ifndef __ARCH_HAS_NO_LDSO__
>>>>    /* arch specific defines */
>>>>    #include <dl-sysdep.h>
>>>>    #endif
>>>
>>> That fixes the alpha problem, thanks.
>>>
>>> But now it fails for ARM FDPIC target.
>>>
>>> /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/bin/arm-openadk-uclinuxfdpiceabi-gcc -c libc/misc/internals/reloc_static_pie.c -o libc/misc/intern
>>> als/reloc_static_pie.os -Wall -Wstrict-prototypes -Wstrict-aliasing -Wno-nonnull-compare -funsigned-char -fno-builtin -fcommon -fno-asm -fmerge-all-constants -msoft-float -std=gnu99 -mlittle-endian -fno-stack-pro
>>> tector -nostdinc -I./include -I./include -include libc-symbols.h -I./libc/sysdeps/linux/arm -I./libc/sysdeps/linux -I./ldso/ldso/arm -I./ldso/include -I. -DSTATIC -Os -fstrict-aliasing -fwrapv -fno-ident -mcpu=ar
>>> m926ej-s -mfpu=vfp -mfloat-abi=soft -Os -pipe -fomit-frame-pointer -marm -Wa,-mfloat-abi=soft -I./libc/sysdeps/linux/common -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926
>>> ej_s_soft_eabi_fdpic_arm_nommu/usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include-fixed -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/
>>> usr/lib/gcc/arm-openadk-uclinuxfdpiceabi/13.2.0/include -I/home/wbx/embedded-test/openadk/target_qemu-arm-versatilepb_uclibc-ng_arm926ej_s_soft_eabi_fdpic_arm_nommu/usr/include/ -DNDEBUG -fPIC -fno-stack-protecto
>>> r -DL_rcrt1 -MT libc/misc/internals/reloc_static_pie.os -MD -MP -MF libc/misc/internals/.reloc_static_pie.os.dep
>>
>> Ok, this is strange. I don't see this with my ARM fdpic testing.
>>
>> Can you send me your uClibc-ng .config file?
> 
> The generation of the config file was broken, I fixed it up.
> 
> I committed and pushed your patch now!

Great news, thanks!

Regards
Greg
diff mbox series

Patch

--- a/ldso/include/dl-defs.h
+++ b/ldso/include/dl-defs.h
@@ -72,7 +72,7 @@ 
  #endif

  #ifdef _LIBC
-#ifndef __ARCH_HAS_NO_SHARED__
+#ifndef __ARCH_HAS_NO_LDSO__
  /* arch specific defines */
  #include <dl-sysdep.h>
  #endif