Hello,
This patch series implements the uClibc-ng contribution of the FDPIC ABI for ARM targets.
This ABI enables to run Linux on ARM MMU-less cores and supports shared libraries to reduce the memory footprint.
Without MMU, text and data segments relative distances are different from one process to another, hence the need for a dedicated FDPIC register holding the start address of the data segment. One of the side effects is that function pointers require two words to be represented: the address of the code, and the data segment start address. These two words are designated as "Function Descriptor", hence the "FD PIC" name.
On ARM, the FDPIC register is r9 [1], and the target name is arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another ABI and the BFLAT file format; it does not support code sharing.
This work was developed some time ago by STMicroelectronics, and was presented during Linaro Connect SFO15 (September 2015). You can watch the discussion and read the slides [2]. This presentation was related to the toolchain published on github [3], which is based on binutils-2.22, gcc-4.7, uclibc-0.9.33.2, gdb-7.5.1 and qemu-2.3.0, and for which pre-built binaries are available [3].
The ABI itself is described in details in [1].
Our Linux kernel patches have been updated and committed by Nicolas Pitre (Linaro) in July 2017. They are required so that the loader is able to handle this new file type. Indeed, the ELF files are tagged with ELFOSABI_ARM_FDPIC. This new tag has been allocated by ARM, as well as the new relocations involved.
The binutils and QEMU patch series have been merged recently. [4][5]
The GCC patch series has been submitted and is under discussion. [6]
This patch series consists in the original uClibc-based patches, which I have rebased and updated for uClibc-ng. Most of them are strictly related to FDPIC on ARM, while a few others address generic issues.
Are the uClibc-ng patches OK for inclusion in master?
Thanks,
Christophe.
[1] https://github.com/mickael-guene/fdpic_doc/blob/master/abi.txt [2] http://connect.linaro.org/resource/sfo15/sfo15-406-arm-fdpic-toolset-kernel-... [3] https://github.com/mickael-guene/fdpic_manifest [4] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=f1ac0afe... [5] https://git.qemu.org/?p=qemu.git;a=commit;h=e8fa72957419c11984608062c7dcb204... [6] https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01439.html
Christophe Lyon (32): [ARM][FDPIC] Allow to select FDPIC ELF for arm architecture [FDPIC] rtld: Do not protect RELRO segments when we don't use an MMU. [ARM][FDPIC] rtld: Add #if defined (__FDPIC__) [ARM][FDPIC] rtld: Add FDPIC code for arm [ARM][FDPIC] rtld: Avoid FUNCDESC relocation on _start [ARM][FDPIC] rtld: Add startup code [ARM] Fix bug in _dl_pread when using pread64 syscall [ARM][FDPIC] Add application startup code for FDPIC [ARM][FDPIC] Add runtime support needed for C++ exceptions [ARM][FDPIC] Allow to generate PIE 'static' binary [ARM][FDPIC] rtld: Add lazy binding support [ARM][FDPIC] TLS: fix relocation computation [ARM][FDPIC] rtld: Compile with -fno-unwind-tables -fno-asynchronous-unwind-tables [ARM][FDPIC] arm/clone.S: Fix threading support [ARM][FDPIC] enable NPTL on TARGET_arm [ARM][FDPIC] rtld: Use ELF_RTYPE_CLASS_DLSYM [FDPIC] rtld: Initialize _dl_error_catch_tsd without FUNCDESC relocation [FDPIC] nptl: disable mprotect usage in stack protection [FDPIC] nptl: Disable fork and atfork on MMU-less systems. [FDPIC] nptl: Do not use madvise [ARM][FDPIC] nptl: Use linker-defined symbol to find start of .tdata section. [FDPIC] nptl: Allow sem_open to work on MMU-less systems [FDPIC] nptl: Add pthread_mutex_getprioceiling and pthread_mutex_setprioceiling support [FDPIC] nptl: Use vfork on MMU-less for system() nptl: Clear TLS area for static binaries. [FDPIC] nptl: Replace sbrk with mmap nptl threads: Fix bug in using a weak variable. Fix htab_delete loop counter isnan: Add isnan weak alias to __isnan mbtowc: Fix non compliant behavior for end of string Fix shm_open posix compliance error code [ARM] rtld: Avoid crash on R_ARM_NONE relocation
extra/Configs/Config.in | 2 +- extra/Configs/Config.in.arch | 2 +- include/elf.h | 2 + include/link.h | 6 +- ldso/include/dl-elf.h | 2 +- ldso/include/dl-hash.h | 2 +- ldso/include/dl-string.h | 3 +- ldso/include/dl-syscall.h | 13 +- ldso/include/inline-hashtab.h | 2 +- ldso/ldso/Makefile.in | 2 - ldso/ldso/arm/dl-inlines.h | 1 + ldso/ldso/arm/dl-startup.h | 112 +++++++++++++- ldso/ldso/arm/dl-sysdep.h | 63 ++++++-- ldso/ldso/arm/elfinterp.c | 166 +++++++++++++++++---- ldso/ldso/arm/resolve.S | 23 +++ ldso/ldso/dl-elf.c | 6 +- ldso/ldso/dl-hash.c | 4 +- ldso/ldso/dl-tls.c | 1 + ldso/ldso/fdpic/dl-inlines.h | 2 + ldso/ldso/fdpic/dl-sysdep.h | 2 +- ldso/ldso/ldso.c | 23 ++- libc/misc/elf/dl-iterate-phdr.c | 2 +- libc/misc/internals/__uClibc_main.c | 47 +++++- libc/stdlib/stdlib.c | 6 +- libc/stdlib/system.c | 5 + libc/sysdeps/linux/arm/Makefile.arch | 2 +- libc/sysdeps/linux/arm/bits/elf-fdpic.h | 114 ++++++++++++++ libc/sysdeps/linux/arm/clone.S | 12 ++ libc/sysdeps/linux/arm/crt1.S | 66 ++++++++ libc/sysdeps/linux/arm/crtreloc.c | 144 ++++++++++++++++++ libc/sysdeps/linux/arm/find_exidx.c | 38 +++++ libc/sysdeps/linux/arm/find_got.c | 72 +++++++++ libm/s_isnan.c | 1 + libpthread/nptl/Makefile.in | 1 - libpthread/nptl/allocatestack.c | 6 + libpthread/nptl/linux_fsinfo.h | 5 +- libpthread/nptl/pthread_create.c | 4 + libpthread/nptl/sem_open.c | 8 +- libpthread/nptl/sysdeps/generic/libc-tls.c | 27 +++- libpthread/nptl/sysdeps/unix/sysv/linux/fork.c | 3 + .../sysdeps/unix/sysv/linux/libc_pthread_init.c | 4 + .../nptl/sysdeps/unix/sysv/linux/register-atfork.c | 14 +- .../sysdeps/unix/sysv/linux/unregister-atfork.c | 10 +- librt/shm.c | 3 + 44 files changed, 958 insertions(+), 75 deletions(-) create mode 100644 ldso/ldso/arm/dl-inlines.h create mode 100644 libc/sysdeps/linux/arm/bits/elf-fdpic.h create mode 100644 libc/sysdeps/linux/arm/crtreloc.c create mode 100644 libc/sysdeps/linux/arm/find_got.c
* extra/Configs/Config.in.arch: Add TARGET_arm to the target list for UCLIBC_FORMAT_FDPIC_ELF.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/extra/Configs/Config.in.arch b/extra/Configs/Config.in.arch index b51ed81..91b6394 100644 --- a/extra/Configs/Config.in.arch +++ b/extra/Configs/Config.in.arch @@ -12,7 +12,7 @@ choice prompt "Target File Format" config UCLIBC_FORMAT_FDPIC_ELF bool "FDPIC ELF" - depends on !ARCH_USE_MMU && (TARGET_bfin || TARGET_frv) + depends on !ARCH_USE_MMU && (TARGET_bfin || TARGET_frv || TARGET_arm) select DOPIC config UCLIBC_FORMAT_DSBT_ELF bool "DBST ELF"
Without MMU, we cannot mark memory regions as read-only.
* ldso/ldso/dl-elf.c (_dl_protect_relro): Do nothing if __ARCH_USE_MMU__ is defined.
Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index d264e6a..1768b5b 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -117,6 +117,7 @@ int _dl_unmap_cache(void) void _dl_protect_relro (struct elf_resolve *l) { +#ifdef __ARCH_USE_MMU__ ElfW(Addr) base = (ElfW(Addr)) DL_RELOC_ADDR(l->loadaddr, l->relro_addr); ElfW(Addr) start = (base & PAGE_ALIGN); ElfW(Addr) end = ((base + l->relro_size) & PAGE_ALIGN); @@ -126,6 +127,7 @@ _dl_protect_relro (struct elf_resolve *l) _dl_dprintf(2, "%s: cannot apply additional memory protection after relocation", l->libname); _dl_exit(0); } +#endif }
/* This function's behavior must exactly match that
Like for other FDPIC targets, add defined(__FDPIC__) where needed.
* include/link.h: Include bits/elf-fdpic.h if __FDPIC__ is defined. (link_map): Use elf32_fdpic_loadaddr if __FDPIC__ is defined. (dl_phdr_info): Likewise. * ldso/include/dl-elf.h (__dl_parse_dynamic_info): Support __FDPIC__. * ldso/include/dl-hash.h (elf_resolve): Add funcdesc_ht field if __FDPIC__ is defined. * ldso/ldso/dl-hash.c (_dl_find_hash): Support __FDPIC__. * libc/misc/elf/dl-iterate-phdr.c (dl_iterate_phdr): Support __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/include/link.h b/include/link.h index 711777b..ef4a016 100644 --- a/include/link.h +++ b/include/link.h @@ -79,7 +79,7 @@ extern struct r_debug _r_debug; */ extern ElfW(Dyn) _DYNAMIC[];
-#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) # include <bits/elf-fdpic.h> #endif #ifdef __DSBT__ @@ -97,7 +97,7 @@ struct link_map /* These first few members are part of the protocol with the debugger. This is the same format used in SVR4. */
-#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) struct elf32_fdpic_loadaddr l_addr; #else #ifdef __DSBT__ @@ -184,7 +184,7 @@ enum
struct dl_phdr_info { -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) struct elf32_fdpic_loadaddr dlpi_addr; #else #ifdef __DSBT__ diff --git a/ldso/include/dl-elf.h b/ldso/include/dl-elf.h index a827b8d..2b99958 100644 --- a/ldso/include/dl-elf.h +++ b/ldso/include/dl-elf.h @@ -202,7 +202,7 @@ unsigned int __dl_parse_dynamic_info(ElfW(Dyn) *dpnt, unsigned long dynamic_info /* Don't adjust .dynamic unnecessarily. For FDPIC targets, we'd have to walk all the loadsegs to find out if it was actually unnecessary, so skip this optimization. */ -#if !defined __FRV_FDPIC__ && !defined __BFIN_FDPIC__ && !defined __DSBT__ +#if !defined __FRV_FDPIC__ && !defined __BFIN_FDPIC__ && !defined __DSBT__ && !defined __FDPIC__ if (load_off != 0) #endif { diff --git a/ldso/include/dl-hash.h b/ldso/include/dl-hash.h index cb46bec..d1deea9 100644 --- a/ldso/include/dl-hash.h +++ b/ldso/include/dl-hash.h @@ -134,7 +134,7 @@ struct elf_resolve { unsigned long data_words; #endif
-#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) /* Every loaded module holds a hashtable of function descriptors of functions defined in it, such that it's easy to release the memory when the module is dlclose()d. */ diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c index 18b3045..0fede84 100644 --- a/ldso/ldso/dl-hash.c +++ b/ldso/ldso/dl-hash.c @@ -377,7 +377,7 @@ char *_dl_find_hash(const char *name, struct r_scope_elem *scope, struct elf_res break; #endif case STB_GLOBAL: -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) if (sym_ref) sym_ref->tpnt = tpnt; #endif @@ -386,7 +386,7 @@ char *_dl_find_hash(const char *name, struct r_scope_elem *scope, struct elf_res break; } } -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) if (sym_ref) sym_ref->tpnt = tpnt; #endif diff --git a/libc/misc/elf/dl-iterate-phdr.c b/libc/misc/elf/dl-iterate-phdr.c index 27a9254..e21e88c 100644 --- a/libc/misc/elf/dl-iterate-phdr.c +++ b/libc/misc/elf/dl-iterate-phdr.c @@ -58,7 +58,7 @@ dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, /* This entry describes this statically-linked program itself. */ struct dl_phdr_info info; int ret; -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) info.dlpi_addr.map = NULL; info.dlpi_addr.got_value = NULL; #elif defined(__DSBT__)
Add FDPIC dynamic relocations support, similar to what other FDPIC targets do.
Lazy binding is implemented in a folllow-up patch.
Disable the SEND* macros because they involve relocations to access constant strings that are unsupported by the existing arm version.
Define DL_START, START, ARCH_NEEDS_BOOTSTRAP_RELOCS, DL_CHECK_LIB_TYPE similarly to what other FDPIC targets do.
Define raise() because _dl_find_hash references __aeabi_uidivmod, which uses __aeabi_idiv0 which in turn references raise.
* include/elf.h (R_ARM_FUNCDESC): Define. (R_ARM_FUNCDESC_VALUE): Define. * ldso/include/dl-string.h (SEND_STDERR, SEND_ADDRESS_STDERR) (SEND_NUMBER_STDERR): Define empty for __FDPIC__. * ldso/ldso/arm/dl-inlines.h: New file. * ldso/ldso/arm/dl-startup.h (PERFORM_BOOTSTRAP_RELOC): Fix type of load_addr. Fix handling of R_ARM_RELATIVE, add support for R_ARM_FUNCDESC_VALUE. (DL_START, START): Define for __FDPIC__. (raise): Define. * ldso/ldso/arm/dl-sysdep.h (ARCH_NEEDS_BOOTSTRAP_RELOCS): Define. (DL_CHECK_LIB_TYPE): Define. (elf_machine_type_class): Take into account FDPIC related relocations. (elf_machine_load_address): Support __FDPIC__. (elf_machine_relative): Likewise. * ldso/ldso/arm/elfinterp.c (_dl_linux_resolver): Dummy support for __FDPIC__, implemented in a later patch. (_dl_do_reloc): Fix reloc_adr computation for __FDPIC__, fix handling of local symbols. Fix handling of R_ARM_RELATIVE, add support for R_ARM_FUNCDESC_VALUE, R_ARM_FUNCDESC. * ldso/ldso/arm/resolve.S: Make _dl_linux_resolve hidden. * ldso/ldso/fdpic/dl-inlines.h (htab_delete): Declare. * libc/sysdeps/linux/arm/bits/elf-fdpic.h: New file, similar to bfin's. * libc/sysdeps/linux/arm/crtreloc.c: Likewise. * libc/sysdeps/linux/arm/find_exidx.c (__dl_addr_in_loadaddr) Define. (find_exidx_callback): Support __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/include/elf.h b/include/elf.h index 2db85c5..6280a56 100644 --- a/include/elf.h +++ b/include/elf.h @@ -2696,6 +2696,8 @@ typedef Elf32_Addr Elf32_Conflict; #define R_ARM_TLS_LDO12 109 #define R_ARM_TLS_LE12 110 #define R_ARM_TLS_IE12GP 111 +#define R_ARM_FUNCDESC 163 +#define R_ARM_FUNCDESC_VALUE 164 #define R_ARM_RXPC25 249 #define R_ARM_RSBREL32 250 #define R_ARM_THM_RPC22 251 diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h index fc1d1fc..bf69971 100644 --- a/ldso/include/dl-string.h +++ b/ldso/include/dl-string.h @@ -256,7 +256,8 @@ static __always_inline char * _dl_simple_ltoahex(char *local, unsigned long i)
/* On some (wierd) arches, none of this stuff works at all, so * disable the whole lot... */ -#if defined(__mips__) +/* The same applies for ARM FDPIC at least for the moment. */ +#if defined(__mips__) || (__FDPIC__)
# define SEND_STDERR(X) # define SEND_ADDRESS_STDERR(X, add_a_newline) diff --git a/ldso/ldso/arm/dl-inlines.h b/ldso/ldso/arm/dl-inlines.h new file mode 100644 index 0000000..8fdf6eb --- /dev/null +++ b/ldso/ldso/arm/dl-inlines.h @@ -0,0 +1 @@ +#include "../fdpic/dl-inlines.h" diff --git a/ldso/ldso/arm/dl-startup.h b/ldso/ldso/arm/dl-startup.h index 371dc22..d15264f 100644 --- a/ldso/ldso/arm/dl-startup.h +++ b/ldso/ldso/arm/dl-startup.h @@ -131,7 +131,7 @@ __asm__( /* Handle relocation of the symbols in the dynamic loader. */ static __always_inline void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, - unsigned long symbol_addr, unsigned long load_addr, Elf32_Sym *symtab) + unsigned long symbol_addr, DL_LOADADDR_TYPE load_addr, Elf32_Sym *symtab) { switch (ELF_R_TYPE(rpnt->r_info)) { case R_ARM_NONE: @@ -176,12 +176,53 @@ void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, *reloc_addr = symbol_addr; break; case R_ARM_RELATIVE: - *reloc_addr += load_addr; + *reloc_addr = DL_RELOC_ADDR(load_addr, *reloc_addr); break; case R_ARM_COPY: break; + case R_ARM_FUNCDESC_VALUE: + { + struct funcdesc_value *dst = (struct funcdesc_value *) reloc_addr; + + dst->entry_point += symbol_addr; + dst->got_value = load_addr.got_value; + } + break; default: SEND_STDERR("Unsupported relocation type\n"); _dl_exit(1); } } + +#ifdef __FDPIC__ +#undef DL_START +#define DL_START(X) \ +static void __attribute__ ((used)) \ +_dl_start (Elf32_Addr dl_boot_got_pointer, \ + struct elf32_fdpic_loadmap *dl_boot_progmap, \ + struct elf32_fdpic_loadmap *dl_boot_ldsomap, \ + Elf32_Dyn *dl_boot_ldso_dyn_pointer, \ + struct funcdesc_value *dl_main_funcdesc, \ + X) + +/* + * Transfer control to the user's application, once the dynamic loader + * is done. We return the address of the function's entry point to + * _dl_boot, see boot1_arch.h. + */ +#define START() do { \ + struct elf_resolve *exec_mod = _dl_loaded_modules; \ + dl_main_funcdesc->entry_point = _dl_elf_main; \ + while (exec_mod->libtype != elf_executable) \ + exec_mod = exec_mod->next; \ + dl_main_funcdesc->got_value = exec_mod->loadaddr.got_value; \ + return; \ +} while (0) + +/* We use __aeabi_idiv0 in _dl_find_hash, so we need to have the raise + symbol. */ +int raise(int sig) +{ + _dl_exit(1); +} +#endif /* __FDPIC__ */ diff --git a/ldso/ldso/arm/dl-sysdep.h b/ldso/ldso/arm/dl-sysdep.h index a47a552..2bb0023 100644 --- a/ldso/ldso/arm/dl-sysdep.h +++ b/ldso/ldso/arm/dl-sysdep.h @@ -10,6 +10,19 @@ /* Define this if the system uses RELOCA. */ #undef ELF_USES_RELOCA #include <elf.h> + +#ifdef __FDPIC__ +/* Need bootstrap relocations */ +#define ARCH_NEEDS_BOOTSTRAP_RELOCS + +#define DL_CHECK_LIB_TYPE(epnt, piclib, _dl_progname, libname) \ +do \ +{ \ + (piclib) = 2; \ +} \ +while (0) +#endif /* __FDPIC__ */ + /* Initialization sequence for the GOT. */ #define INIT_GOT(GOT_BASE,MODULE) \ { \ @@ -62,11 +75,17 @@ unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry); define the value.
ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one - of the main executable's symbols, as for a COPY reloc. */ -#define elf_machine_type_class(type) \ - ((((type) == R_ARM_JUMP_SLOT || (type) == R_ARM_TLS_DTPMOD32 \ + of the main executable's symbols, as for a COPY reloc. + + Avoid R_ARM_ABS32 to go through the PLT so that R_ARM_TARGET1 + translated to R_ARM_ABS32 doesn't use the PLT: otherwise, this + breaks init_array because functions are referenced through the + PLT. */ +#define elf_machine_type_class(type) \ + ((((type) == R_ARM_JUMP_SLOT || (type) == R_ARM_TLS_DTPMOD32 \ + || (type) == R_ARM_FUNCDESC_VALUE || (type) == R_ARM_FUNCDESC || (type) == R_ARM_ABS32 \ || (type) == R_ARM_TLS_DTPOFF32 || (type) == R_ARM_TLS_TPOFF32) \ - * ELF_RTYPE_CLASS_PLT) \ + * ELF_RTYPE_CLASS_PLT) \ | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY))
/* Return the link-time address of _DYNAMIC. Conveniently, this is the @@ -106,10 +125,22 @@ elf_machine_dynamic (void)
extern char __dl_start[] __asm__("_dl_start");
+/* We must force strings used early in the bootstrap into the data + segment. */ +#undef SEND_EARLY_STDERR +#define SEND_EARLY_STDERR(S) \ + do { /* FIXME: implement */; } while (0) + +#undef INIT_GOT +#include "../fdpic/dl-sysdep.h" + /* Return the run-time load address of the shared object. */ static __always_inline Elf32_Addr __attribute__ ((unused)) elf_machine_load_address (void) { +#if defined(__FDPIC__) + return 0; +#else Elf32_Addr got_addr = (Elf32_Addr) &__dl_start; Elf32_Addr pcrel_addr; #if defined __OPTIMIZE__ && !defined __thumb__ @@ -128,19 +159,29 @@ elf_machine_load_address (void) : "=r" (pcrel_addr), "=r" (tmp)); #endif return pcrel_addr - got_addr; +#endif }
static __always_inline void -elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr, +elf_machine_relative (DL_LOADADDR_TYPE load_off, const Elf32_Addr rel_addr, Elf32_Word relative_count) { - Elf32_Rel * rpnt = (void *) rel_addr; - --rpnt; - do { - Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset); +#if defined(__FDPIC__) + Elf32_Rel *rpnt = (void *) rel_addr; + + do { + unsigned long *reloc_addr = (unsigned long *) DL_RELOC_ADDR(load_off, rpnt->r_offset);
- *reloc_addr += load_off; - } while (--relative_count); + *reloc_addr = DL_RELOC_ADDR(load_off, *reloc_addr); + rpnt++; +#else + Elf32_Rel * rpnt = (void *) rel_addr; + --rpnt; + do { + Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset); + *reloc_addr += load_off; +#endif + } while(--relative_count); } #endif /* !_ARCH_DL_SYSDEP */
diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 96809a9..1435c2c 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -36,6 +36,11 @@ extern int _dl_linux_resolve(void);
unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) { +#if __FDPIC__ + /* FIXME: implement. */ + while(1) ; + return 0; +#else ELF_RELOC *this_reloc; char *strtab; char *symname; @@ -88,6 +93,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) #endif
return new_addr; +#endif }
static int @@ -181,7 +187,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct r_scope_elem *scope, struct elf_resolve *def_mod = 0; int goof = 0;
- reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_addr = (unsigned long *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset);
reloc_type = ELF_R_TYPE(rpnt->r_info); symtab_index = ELF_R_SYM(rpnt->r_info); @@ -191,25 +197,30 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct r_scope_elem *scope, symname = strtab + symtab[symtab_index].st_name;
if (symtab_index) { - symbol_addr = (unsigned long)_dl_find_hash(symname, scope, tpnt, - elf_machine_type_class(reloc_type), &sym_ref); - - /* - * We want to allow undefined references to weak symbols - this might - * have been intentional. We should not be linking local symbols - * here, so all bases should be covered. - */ - if (!symbol_addr && (ELF_ST_TYPE(symtab[symtab_index].st_info) != STT_TLS) - && (ELF_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK)) { - /* This may be non-fatal if called from dlopen. */ - return 1; - - } - if (_dl_trace_prelink) { - _dl_debug_lookup (symname, tpnt, &symtab[symtab_index], - &sym_ref, elf_machine_type_class(reloc_type)); + if (ELF_ST_BIND (symtab[symtab_index].st_info) == STB_LOCAL) { + symbol_addr = (unsigned long) DL_RELOC_ADDR(tpnt->loadaddr, symtab[symtab_index].st_value); + def_mod = tpnt; + } else { + symbol_addr = (unsigned long)_dl_find_hash(symname, scope, tpnt, + elf_machine_type_class(reloc_type), &sym_ref); + + /* + * We want to allow undefined references to weak symbols - this might + * have been intentional. We should not be linking local symbols + * here, so all bases should be covered. + */ + if (!symbol_addr && (ELF_ST_TYPE(symtab[symtab_index].st_info) != STT_TLS) + && (ELF_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK)) { + /* This may be non-fatal if called from dlopen. */ + return 1; + + } + if (_dl_trace_prelink) { + _dl_debug_lookup (symname, tpnt, &symtab[symtab_index], + &sym_ref, elf_machine_type_class(reloc_type)); + } + def_mod = sym_ref.tpnt; } - def_mod = sym_ref.tpnt; } else { /* * Relocs against STN_UNDEF are usually treated as using a @@ -267,12 +278,40 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct r_scope_elem *scope, *reloc_addr = symbol_addr; break; case R_ARM_RELATIVE: - *reloc_addr += (unsigned long) tpnt->loadaddr; + *reloc_addr = DL_RELOC_ADDR(tpnt->loadaddr, *reloc_addr); break; case R_ARM_COPY: _dl_memcpy((void *) reloc_addr, (void *) symbol_addr, symtab[symtab_index].st_size); break; + case R_ARM_FUNCDESC_VALUE: + { + struct funcdesc_value funcval; + struct funcdesc_value *dst = (struct funcdesc_value *) reloc_addr; + + funcval.entry_point = (void*)symbol_addr; + /* Add offset to section address for local symbols. */ + if (ELF_ST_BIND(symtab[symtab_index].st_info) == STB_LOCAL) + funcval.entry_point += *reloc_addr; + funcval.got_value = def_mod->loadaddr.got_value; + *dst = funcval; + } + break; + case R_ARM_FUNCDESC: + { + unsigned long reloc_value = *reloc_addr; + + if (symbol_addr) + reloc_value = (unsigned long) _dl_funcdesc_for(symbol_addr + reloc_value, sym_ref.tpnt->loadaddr.got_value); + else + /* Relocation against an + undefined weak symbol: + set funcdesc to zero. */ + reloc_value = 0; + + *reloc_addr = reloc_value; + } + break; #if defined USE_TLS && USE_TLS case R_ARM_TLS_DTPMOD32: *reloc_addr = def_mod->l_tls_modid; @@ -330,7 +369,6 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope,
#endif return 0; - }
void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt, @@ -345,3 +383,6 @@ int _dl_parse_relocation_information(struct dyn_elf *rpnt, return _dl_parse(rpnt->dyn, scope, rel_addr, rel_size, _dl_do_reloc); }
+#ifndef IS_IN_libdl +# include "../../libc/sysdeps/linux/arm/crtreloc.c" +#endif diff --git a/ldso/ldso/arm/resolve.S b/ldso/ldso/arm/resolve.S index 7e0058e..2a51643 100644 --- a/ldso/ldso/arm/resolve.S +++ b/ldso/ldso/arm/resolve.S @@ -102,6 +102,7 @@ .align 4 @ 16 byte boundary and there are 32 bytes below (arm case) #if 1 /*(!defined(__thumb__) || defined __THUMB_INTERWORK__) || defined(__thumb2__)*/ .arm + .hidden _dl_linux_resolve .globl _dl_linux_resolve .type _dl_linux_resolve,%function .align 4; diff --git a/ldso/ldso/fdpic/dl-inlines.h b/ldso/ldso/fdpic/dl-inlines.h index f590875..89e7a9a 100644 --- a/ldso/ldso/fdpic/dl-inlines.h +++ b/ldso/ldso/fdpic/dl-inlines.h @@ -7,6 +7,8 @@
#include <inline-hashtab.h>
+static __always_inline void htab_delete(struct funcdesc_ht *htab); + /* Initialize a DL_LOADADDR_TYPE given a got pointer and a complete load map. */ static __always_inline void __dl_init_loadaddr_map(struct elf32_fdpic_loadaddr *loadaddr, Elf32_Addr dl_boot_got_pointer, diff --git a/libc/sysdeps/linux/arm/bits/elf-fdpic.h b/libc/sysdeps/linux/arm/bits/elf-fdpic.h new file mode 100644 index 0000000..3d6db54 --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/elf-fdpic.h @@ -0,0 +1,114 @@ +/* Copyright 2003, 2004 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +In addition to the permissions in the GNU Lesser General Public +License, the Free Software Foundation gives you unlimited +permission to link the compiled version of this file with other +programs, and to distribute those programs without any restriction +coming from the use of this file. (The GNU Lesser General Public +License restrictions do apply in other respects; for example, they +cover modification of the file, and distribution when not linked +into another program.) + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, see http://www.gnu.org/licenses/. */ + +#ifndef _BITS_ELF_FDPIC_H +#define _BITS_ELF_FDPIC_H + +/* These data structures are described in the FDPIC ABI extension. + The kernel passes a process a memory map, such that for every LOAD + segment there is an elf32_fdpic_loadseg entry. A pointer to an + elf32_fdpic_loadmap is passed in r7 at start-up, and a pointer to + an additional such map is passed in r8 for the interpreter, when + there is one. */ + +#include <elf.h> + +/* This data structure represents a PT_LOAD segment. */ +struct elf32_fdpic_loadseg +{ + /* Core address to which the segment is mapped. */ + Elf32_Addr addr; + /* VMA recorded in the program header. */ + Elf32_Addr p_vaddr; + /* Size of this segment in memory. */ + Elf32_Word p_memsz; +}; + +struct elf32_fdpic_loadmap { + /* Protocol version number, must be zero. */ + Elf32_Half version; + /* Number of segments in this map. */ + Elf32_Half nsegs; + /* The actual memory map. */ + struct elf32_fdpic_loadseg segs[/*nsegs*/]; +}; + +struct elf32_fdpic_loadaddr { + struct elf32_fdpic_loadmap *map; + void *got_value; +}; + +/* Map a pointer's VMA to its corresponding address according to the + load map. */ +static __always_inline void * +__reloc_pointer (void *p, + const struct elf32_fdpic_loadmap *map) +{ + int c; + +#if 0 + if (map->version != 0) + /* Crash. */ + ((void(*)())0)(); +#endif + + /* No special provision is made for NULL. We don't want NULL + addresses to go through relocation, so they shouldn't be in + .rofixup sections, and, if they're present in dynamic + relocations, they shall be mapped to the NULL address without + undergoing relocations. */ + + for (c = 0; + /* Take advantage of the fact that the loadmap is ordered by + virtual addresses. In general there will only be 2 entries, + so it's not profitable to do a binary search. */ + c < map->nsegs && p >= (void*)map->segs[c].p_vaddr; + c++) + { + /* This should be computed as part of the pointer comparison + above, but we want to use the carry in the comparison, so we + can't convert it to an integer type beforehand. */ + unsigned long offset = p - (void*)map->segs[c].p_vaddr; + /* We only check for one-past-the-end for the last segment, + assumed to be the data segment, because other cases are + ambiguous in the absence of padding between segments, and + rofixup already serves as padding between text and data. + Unfortunately, unless we special-case the last segment, we + fail to relocate the _end symbol. */ + if (offset < map->segs[c].p_memsz + || (offset == map->segs[c].p_memsz && c + 1 == map->nsegs)) + return (char*)map->segs[c].addr + offset; + } + + /* We might want to crash instead. */ + return (void*)-1; +} + +# define __RELOC_POINTER(ptr, loadaddr) \ + (__reloc_pointer ((void*)(ptr), \ + (loadaddr).map)) + +#endif /* _BITS_ELF_FDPIC_H */ diff --git a/libc/sysdeps/linux/arm/crtreloc.c b/libc/sysdeps/linux/arm/crtreloc.c new file mode 100644 index 0000000..560b416 --- /dev/null +++ b/libc/sysdeps/linux/arm/crtreloc.c @@ -0,0 +1,144 @@ +/* Copyright (C) 2003, 2004 Free Software Foundation, Inc. + written by Alexandre Oliva aoliva@redhat.com +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +In addition to the permissions in the GNU Lesser General Public +License, the Free Software Foundation gives you unlimited +permission to link the compiled version of this file with other +programs, and to distribute those programs without any restriction +coming from the use of this file. (The GNU Lesser General Public +License restrictions do apply in other respects; for example, they +cover modification of the file, and distribution when not linked +into another program.) + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, see http://www.gnu.org/licenses/. */ + +#ifdef __FDPIC__ + +#include <sys/types.h> +#include <link.h> + +/* This file is to be compiled into crt object files, to enable + executables to easily self-relocate. */ + +union word { + char c[4]; + void *v; +}; + +/* Compute the runtime address of pointer in the range [p,e), and then + map the pointer pointed by it. */ +static __always_inline void *** +reloc_range_indirect (void ***p, void ***e, + const struct elf32_fdpic_loadmap *map) +{ + while (p < e) + { + if (*p != (void **)-1) + { + void *ptr = __reloc_pointer (*p, map); + if (ptr != (void *)-1) + { + void *pt; + if ((long)ptr & 3) + { + unsigned char *c = ptr; + int i; + unsigned long v = 0; + for (i = 0; i < 4; i++) + v |= c[i] << 8 * i; + pt = (void *)v; + } + else + pt = *(void**)ptr; + pt = __reloc_pointer (pt, map); + if ((long)ptr & 3) + { + unsigned char *c = ptr; + int i; + unsigned long v = (unsigned long)pt; + for (i = 0; i < 4; i++, v >>= 8) + c[i] = v; + } + else + *(void**)ptr = pt; + } + } + p++; + } + return p; +} + +/* Call __reloc_range_indirect for the given range except for the last + entry, whose contents are only relocated. It's expected to hold + the GOT value. */ +attribute_hidden void* +__self_reloc (const struct elf32_fdpic_loadmap *map, + void ***p, void ***e) +{ + p = reloc_range_indirect (p, e-1, map); + + if (p >= e) + return (void*)-1; + + return __reloc_pointer (*p, map); +} + +#if 0 +/* These are other functions that might be useful, but that we don't + need. */ + +/* Remap pointers in [p,e). */ +static __always_inline void** +reloc_range (void **p, void **e, + const struct elf32_fdpic_loadmap *map) +{ + while (p < e) + { + *p = __reloc_pointer (*p, map); + p++; + } + return p; +} + +/* Remap p, adjust e by the same offset, then map the pointers in the + range determined by them. */ +void attribute_hidden +__reloc_range (const struct elf32_fdpic_loadmap *map, + void **p, void **e) +{ + void **old = p; + + p = __reloc_pointer (p, map); + e += p - old; + reloc_range (p, e, map); +} + +/* Remap p, adjust e by the same offset, then map pointers referenced + by the (unadjusted) pointers in the range. Return the relocated + value of the last pointer in the range. */ +void* attribute_hidden +__reloc_range_indirect (const struct elf32_fdpic_loadmap *map, + void ***p, void ***e) +{ + void ***old = p; + + p = __reloc_pointer (p, map); + e += p - old; + return reloc_range_indirect (p, e, map); +} +#endif + +#endif /* __FDPIC__ */ diff --git a/libc/sysdeps/linux/arm/find_exidx.c b/libc/sysdeps/linux/arm/find_exidx.c index 679d90c..cd4d442 100644 --- a/libc/sysdeps/linux/arm/find_exidx.c +++ b/libc/sysdeps/linux/arm/find_exidx.c @@ -18,6 +18,23 @@ #include <link.h> #include <unwind.h>
+#if __FDPIC__ +#include <bits/elf-fdpic.h> +static __always_inline int +__dl_addr_in_loadaddr(void *p, struct elf32_fdpic_loadaddr loadaddr) +{ + struct elf32_fdpic_loadmap *map = loadaddr.map; + int c; + + for (c = 0; c < map->nsegs; c++) + if ((void *)map->segs[c].addr <= p && + (char *)p < (char *)map->segs[c].addr + map->segs[c].p_memsz) + return 1; + + return 0; +} +#endif + struct unw_eh_callback_data { _Unwind_Ptr pc; @@ -32,6 +49,26 @@ struct unw_eh_callback_data static int find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr) { +#if __FDPIC__ + struct unw_eh_callback_data * data; + const ElfW(Phdr) *phdr; + int i; + int match = 0; + + data = (struct unw_eh_callback_data *) ptr; + if (__dl_addr_in_loadaddr((void *) data->pc, info->dlpi_addr)) { + match = 1; + phdr = info->dlpi_phdr; + for (i = info->dlpi_phnum; i > 0; i--, phdr++) { + if (phdr->p_type == PT_ARM_EXIDX) { + data->exidx_start = (_Unwind_Ptr) __RELOC_POINTER(phdr->p_vaddr, info->dlpi_addr); + data->exidx_len = phdr->p_memsz; + } + } + } + + return match; +#else struct unw_eh_callback_data * data; const ElfW(Phdr) *phdr; int i; @@ -59,6 +96,7 @@ find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr) }
return match; +#endif }
* ldso/ldso/ldso.c (_start): Fix definition for __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 17818b5..c625757 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -109,7 +109,13 @@ static unsigned char *_dl_mmap_zero = NULL; /* Also used by _dl_malloc */ static struct elf_resolve **init_fini_list; static struct elf_resolve **scope_elem_list; static unsigned int nlist; /* # items in init_fini_list */ +#ifdef __FDPIC__ +/* We need to take the address of _start instead of its FUNCDESC: + declare it as void* to control the relocation emitted. */ +extern void *_start; +#else extern void _start(void); +#endif
#ifdef __UCLIBC_HAS_SSP__ # include <dl-osinfo.h>
Implement _start: compute parameters for __self_reloc, and give control to the user program.
* ldso/ldso/arm/dl-startup.h: Implement _start for __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/arm/dl-startup.h b/ldso/ldso/arm/dl-startup.h index d15264f..b5f7d73 100644 --- a/ldso/ldso/arm/dl-startup.h +++ b/ldso/ldso/arm/dl-startup.h @@ -8,6 +8,71 @@ #include <features.h> #include <bits/arm_bx.h>
+#if defined(__FDPIC__) +#if !defined(__thumb__) || defined(__thumb2__) +__asm__( + " .arm\n" + " .text\n" + " .globl _start\n" + " .type _start,%function\n" + "_start:\n" + /* We compute the parameters for __self_reloc: + - r0 is a pointer to the loadmap (either from r8 or r7 if rtld is + lauched in standalone mode) + - r1 is a pointer to the start of .rofixup section + - r2 is a pointer to the last word of .rofixup section + + __self_reloc will fix indirect addresses in .rofixup + section and will return the relocated GOT value. + */ + " sub r4, pc, #8\n" + " ldr r1, .L__ROFIXUP_LIST__\n" + " add r1, r1, r4\n" + " ldr r2, .L__ROFIXUP_END__\n" + " add r2, r2, r4\n" + " movs r0, r8\n" + " moveq r0, r7\n" + " push {r7, r8, r9, r10}\n" + " bl __self_reloc;\n" + " pop {r7, r8, r9, r10}\n" + /* We compute the parameters for dl_start(). See DL_START() + macro below. The address of the user entry point is + returned in dl_main_funcdesc (on stack). */ + " mov r1, r7\n" + " mov r2, r8\n" + " mov r3, r9\n" + " mov r4, sp\n" + " sub r5, sp, #8\n" + " sub sp, sp, #16\n" + " str r4, [sp, #4]\n" + " str r5, [sp, #0]\n" + " mov r9, r0\n" + /* Save r9 into r4, to preserve the GOT pointer. */ + " mov r4, r9\n" + " bl _dl_start;\n" + /* Now compute parameters for entry point according to FDPIC ABI. */ + " ldr r10, .L_dl_fini_gotofffuncdesc\n" + /* Save GOT value from r4. */ + " add r10, r10, r4\n" + " ldr r5, [sp, #8]\n" + " ldr r9, [sp, #12]\n" + " add sp, sp, #16\n" + " bx r5\n" + ".loopforever:\n" + " b .loopforever\n" + ".L__ROFIXUP_LIST__:\n" + " .word __ROFIXUP_LIST__ - _start\n" + ".L__ROFIXUP_END__:\n" + " .word __ROFIXUP_END__ - _start\n" + ".L_dl_fini_gotofffuncdesc:\n" + " .word _dl_fini(GOTOFFFUNCDESC)\n" + " .size _start,.-_start\n" + " .previous\n" +); +#else /* !defined(__thumb__) */ +#error Thumb-1 is not supported +#endif /* !defined(__thumb__) */ +#else /* defined(__FDPIC__) */ #if !defined(__thumb__) __asm__( " .text\n" @@ -121,7 +186,7 @@ __asm__( ".previous\n" ); #endif - +#endif /* defined(__FDPIC__) */
/* Get a pointer to the argv array. On many platforms this can be just * the address of the first argument, on other platforms we need to
Hello Christophe,
On Wed, 4 Jul 2018 17:55:19 +0200, Christophe Lyon wrote:
Implement _start: compute parameters for __self_reloc, and give control to the user program.
- ldso/ldso/arm/dl-startup.h: Implement _start for __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
This is very likely me not doing things correctly, but this change doesn't build, because it uses ARM instructions on Thumb2-only systems. I'm trying to build a Cortex-M4 FDPIC toolchain with your patches. My gcc has the following details (it is gcc 8.1.0 on top of which I have backported your ARM FDPIC patches):
/home/test/outputs/arm-fdpic/host/bin/arm-buildroot-uclinuxfdpiceabi-gcc -v Using built-in specs. COLLECT_GCC=/home/test/outputs/arm-fdpic/host/bin/arm-buildroot-uclinuxfdpiceabi-gcc.br_real COLLECT_LTO_WRAPPER=/home/test/outputs/arm-fdpic/host/libexec/gcc/arm-buildroot-uclinuxfdpiceabi/8.1.0/lto-wrapper Target: arm-buildroot-uclinuxfdpiceabi Configured with: ./configure --prefix=/home/test/outputs/arm-fdpic/host --sysconfdir=/home/test/outputs/arm-fdpic/host/etc --localstatedir=/home/test/outputs/arm-fdpic/host/var --enable-shared --disable-static --disable-gtk-doc --disable-gtk-doc-html --disable-doc --disable-docs --disable-documentation --disable-debug --with-xmlto=no --with-fop=no --disable-dependency-tracking --target=arm-buildroot-uclinuxfdpiceabi --with-sysroot=/home/test/outputs/arm-fdpic/host/arm-buildroot-uclinuxfdpiceabi/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/home/test/outputs/arm-fdpic/host --with-mpc=/home/test/outputs/arm-fdpic/host --with-mpfr=/home/test/outputs/arm-fdpic/host --with-pkgversion='Buildroot 2018.08-git-00602-g3ecd583' --with-bugurl=http://bugs.buildroot.net/ --disable-libquadmath --disable-libsanitizer --disable-tls --disable-libmudflap --enable-threads --without-isl --without-cloog --with-float=soft --disable-decimal-float --with-abi=aapcs-linux --with-cpu=cortex-m4 --with-float=soft --with-mode=thumb --enable-languages=c --disable-shared --without-headers --disable-threads --with-newlib --disable-largefile --disable-nls Thread model: single gcc version 8.1.0 (Buildroot 2018.08-git-00602-g3ecd583)
I.e, it generates code for Cortex-M4, soft-float, Thumb by default.
The dl-startup code fails to build with:
/home/test/outputs/arm-fdpic/host/bin/arm-buildroot-uclinuxfdpiceabi-gcc -c ldso/ldso/ldso.c -o ldso/ldso/ldso.oS -Wall -Wstrict-prototypes -Wstrict-aliasing -Wno-nonnull-compare -funsigned-char -fno-builtin -fno-asm -fmerge-all-constants -msoft-float -st d=gnu99 -mlittle-endian -fno-stack-protector -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. -Os -fstrict-aliasing -I./libpthread/linuxthreads/sysdeps/unix/ sysv/linux/arm -I./libpthread/linuxthreads/sysdeps/arm -I./libpthread/linuxthreads/sysdeps/unix/sysv/linux -I./libpthread/linuxthreads/sysdeps/pthread -I./libpthread/linuxthreads -I./libpthread -I./libc/sysdeps/linux/common -isystem /home/test/outputs/arm -fdpic/host/lib/gcc/arm-buildroot-uclinuxfdpiceabi/8.1.0/include-fixed -isystem /home/test/outputs/arm-fdpic/host/lib/gcc/arm-buildroot-uclinuxfdpiceabi/8.1.0/include -I/home/test/outputs/arm-fdpic/build/linux-headers-4.17.4/usr/include/ -DNDEBUG -DNOT_IN _libc -DIS_IN_rtld -fno-stack-protector -fno-omit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables -I./ldso/ldso/arm -I./ldso/include -I./ldso/ldso -DUCLIBC_RUNTIME_PREFIX="/" -DUCLIBC_LDSO="ld-uClibc.so.1" -DIN_LIB=rtld -mfdpic -DSHAR ED -DLDSO_ELFINTERP="arm/elfinterp.c" -DLDSO_MULTILIB_DIR="lib/" -MT ldso/ldso/ldso.oS -MD -MP -MF ldso/ldso/.ldso.oS.dep In file included from ./include/bits/waitstatus.h:72, from ./include/stdlib.h:44, from ./ldso/include/ldso.h:33, from ldso/ldso/ldso.c:32: ./ldso/include/dl-syscall.h: In function '_dl_pread': ./ldso/include/dl-syscall.h:169:69: warning: right shift count >= width of type [-Wshift-count-overflow] 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' # define __LONG_LONG_PAIR(HI, LO) LO, HI ^~ In file included from ./ldso/ldso/arm/dl-inlines.h:1, from ./ldso/include/ldso.h:183, from ldso/ldso/ldso.c:32: ./ldso/ldso/arm/../fdpic/dl-inlines.h: In function '_dl_funcdesc_for': ./ldso/ldso/arm/../fdpic/dl-inlines.h:180:8: warning: assignment to 'struct funcdesc_value **' from incompatible pointer type 'void **' [-Wincompatible-pointer-types] entry = htab_find_slot(ht, entry_point, 1, hash_pointer, eq_pointer); ^ In file included from ldso/ldso/ldso.c:45: ldso/ldso/arm/elfinterp.c: In function '_dl_linux_resolver': ldso/ldso/arm/elfinterp.c:95:9: warning: returning 'volatile struct funcdesc_value *' from a function with return type 'long unsigned int' makes integer from pointer without a cast [-Wint-conversion] return got_entry; ^~~~~~~~~ ldso/ldso/arm/elfinterp.c: In function '_dl_do_reloc': ldso/ldso/arm/elfinterp.c:364:65: warning: passing argument 1 of '_dl_funcdesc_for' makes pointer from integer without a cast [-Wint-conversion] reloc_value = (unsigned long) _dl_funcdesc_for(symbol_addr + reloc_value, sym_ref.tpnt->loadaddr.got_value); ~~~~~~~~~~~~^~~~~~~~~~~~~ In file included from ./ldso/ldso/arm/dl-inlines.h:1, from ./ldso/include/ldso.h:183, from ldso/ldso/ldso.c:32: ./ldso/ldso/arm/../fdpic/dl-inlines.h:165:25: note: expected 'void *' but argument is of type 'long unsigned int' _dl_funcdesc_for (void *entry_point, void *got_value) ~~~~~~^~~~~~~~~~~ In file included from ldso/ldso/ldso.c:45: ldso/ldso/arm/elfinterp.c: In function '_dl_do_lazy_reloc': ldso/ldso/arm/elfinterp.c:429:23: warning: assignment to 'void *' from 'unsigned int' makes pointer from integer without a cast [-Wint-conversion] dst->entry_point = DL_RELOC_ADDR(tpnt->loadaddr, dst->entry_point); ^ In file included from ldso/ldso/ldso.c:86: ldso/ldso/dl-startup.c: In function '_dl_start': ldso/ldso/dl-startup.c:313:13: warning: variable 'strtab' set but not used [-Wunused-but-set-variable] char *strtab; ^~~~~~ ldso/ldso/dl-startup.c:125:13: warning: variable 'got' set but not used [-Wunused-but-set-variable] ElfW(Addr) got; ^~~ In file included from ./ldso/ldso/arm/dl-sysdep.h:135, from ./ldso/include/dl-defs.h:77, from ./ldso/include/dl-string.h:15, from ./ldso/include/ldso.h:53, ...skipping... In file included from ./ldso/ldso/arm/dl-inlines.h:1, from ./ldso/include/ldso.h:183, from ldso/ldso/ldso.c:32: ./ldso/ldso/arm/../fdpic/dl-inlines.h:165:25: note: expected 'void *' but argument is of type 'long unsigned int' _dl_funcdesc_for (void *entry_point, void *got_value) ~~~~~~^~~~~~~~~~~ In file included from ldso/ldso/ldso.c:45: ldso/ldso/arm/elfinterp.c: In function '_dl_do_lazy_reloc': ldso/ldso/arm/elfinterp.c:429:23: warning: assignment to 'void *' from 'unsigned int' makes pointer from integer without a cast [-Wint-conversion] dst->entry_point = DL_RELOC_ADDR(tpnt->loadaddr, dst->entry_point); ^ In file included from ldso/ldso/ldso.c:86: ldso/ldso/dl-startup.c: In function '_dl_start': ldso/ldso/dl-startup.c:313:13: warning: variable 'strtab' set but not used [-Wunused-but-set-variable] char *strtab; ^~~~~~ ldso/ldso/dl-startup.c:125:13: warning: variable 'got' set but not used [-Wunused-but-set-variable] ElfW(Addr) got; ^~~ In file included from ./ldso/ldso/arm/dl-sysdep.h:135, from ./ldso/include/dl-defs.h:77, from ./ldso/include/dl-string.h:15, from ./ldso/include/ldso.h:53, from ldso/ldso/ldso.c:32: ldso/ldso/dl-hash.c: In function '_dl_find_hash': ./ldso/ldso/arm/../fdpic/dl-sysdep.h:111:4: warning: pointer/integer type mismatch in conditional expression : DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value)) ^ ldso/ldso/dl-hash.c:384:20: note: in expansion of macro 'DL_FIND_HASH_VALUE' return (char *)DL_FIND_HASH_VALUE(tpnt, type_class, sym); ^~~~~~~~~~~~~~~~~~ /tmp/cceTVltl.s: Assembler messages: /tmp/cceTVltl.s:14: Error: selected processor does not support ARM opcodes /tmp/cceTVltl.s:19: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r4,pc,#8' /tmp/cceTVltl.s:20: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r1,.L__ROFIXUP_LIST__' /tmp/cceTVltl.s:21: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r1,r1,r4' /tmp/cceTVltl.s:22: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r2,.L__ROFIXUP_END__' /tmp/cceTVltl.s:23: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r2,r2,r4' /tmp/cceTVltl.s:24: Error: attempt to use an ARM instruction on a Thumb-only processor -- `movs r0,r8' /tmp/cceTVltl.s:25: Error: attempt to use an ARM instruction on a Thumb-only processor -- `moveq r0,r7' /tmp/cceTVltl.s:26: Error: attempt to use an ARM instruction on a Thumb-only processor -- `push {r7,r8,r9,r10}' /tmp/cceTVltl.s:27: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl __self_reloc' /tmp/cceTVltl.s:28: Error: attempt to use an ARM instruction on a Thumb-only processor -- `pop {r7,r8,r9,r10}' /tmp/cceTVltl.s:29: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r1,r7' /tmp/cceTVltl.s:30: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r2,r8' /tmp/cceTVltl.s:31: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r3,r9' /tmp/cceTVltl.s:32: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,sp' /tmp/cceTVltl.s:33: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r5,sp,#8' /tmp/cceTVltl.s:34: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub sp,sp,#16' /tmp/cceTVltl.s:35: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r4,[sp,#4]' /tmp/cceTVltl.s:36: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r5,[sp,#0]' /tmp/cceTVltl.s:37: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r9,r0' /tmp/cceTVltl.s:38: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,r9' /tmp/cceTVltl.s:39: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl _dl_start' /tmp/cceTVltl.s:40: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r10,.L_dl_fini_gotofffuncdesc' /tmp/cceTVltl.s:41: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r10,r10,r4' /tmp/cceTVltl.s:42: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r5,[sp,#8]' /tmp/cceTVltl.s:43: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r9,[sp,#12]' /tmp/cceTVltl.s:44: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add sp,sp,#16' /tmp/cceTVltl.s:45: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bx r5' /tmp/cceTVltl.s:47: Error: attempt to use an ARM instruction on a Thumb-only processor -- `b .loopforever' make[2]: *** [ldso/ldso/ldso.oS] Error 1 make[1]: *** [/home/test/outputs/arm-fdpic/build/uclibc-1.0.30/.stamp_built] Error 2 make: *** [_all] Error 2
Any idea ?
Best regards,
Thomas Petazzoni
On Thu, 5 Jul 2018 at 10:37, Thomas Petazzoni thomas.petazzoni@bootlin.com wrote:
Hello Christophe,
On Wed, 4 Jul 2018 17:55:19 +0200, Christophe Lyon wrote:
Implement _start: compute parameters for __self_reloc, and give control to the user program.
* ldso/ldso/arm/dl-startup.h: Implement _start for __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
This is very likely me not doing things correctly, but this change doesn't build, because it uses ARM instructions on Thumb2-only systems. I'm trying to build a Cortex-M4 FDPIC toolchain with your patches. My gcc has the following details (it is gcc 8.1.0 on top of which I have backported your ARM FDPIC patches):
/home/test/outputs/arm-fdpic/host/bin/arm-buildroot-uclinuxfdpiceabi-gcc -v Using built-in specs. COLLECT_GCC=/home/test/outputs/arm-fdpic/host/bin/arm-buildroot-uclinuxfdpiceabi-gcc.br_real COLLECT_LTO_WRAPPER=/home/test/outputs/arm-fdpic/host/libexec/gcc/arm-buildroot-uclinuxfdpiceabi/8.1.0/lto-wrapper Target: arm-buildroot-uclinuxfdpiceabi Configured with: ./configure --prefix=/home/test/outputs/arm-fdpic/host --sysconfdir=/home/test/outputs/arm-fdpic/host/etc --localstatedir=/home/test/outputs/arm-fdpic/host/var --enable-shared --disable-static --disable-gtk-doc --disable-gtk-doc-html --disable-doc --disable-docs --disable-documentation --disable-debug --with-xmlto=no --with-fop=no --disable-dependency-tracking --target=arm-buildroot-uclinuxfdpiceabi --with-sysroot=/home/test/outputs/arm-fdpic/host/arm-buildroot-uclinuxfdpiceabi/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/home/test/outputs/arm-fdpic/host --with-mpc=/home/test/outputs/arm-fdpic/host --with-mpfr=/home/test/outputs/arm-fdpic/host --with-pkgversion='Buildroot 2018.08-git-00602-g3ecd583' --with-bugurl=http://bugs.buildroot.net/ --disable-libquadmath --disable-libsanitizer --disable-tls --disable-libmudflap --enable-threads --without-isl --without-cloog --with-float=soft --disable-decimal-float --with-abi=aapcs-linux --with-cpu=cortex-m4 --with-float=soft --with-mode=thumb --enable-languages=c --disable-shared --without-headers --disable-threads --with-newlib --disable-largefile --disable-nls Thread model: single gcc version 8.1.0 (Buildroot 2018.08-git-00602-g3ecd583)
I.e, it generates code for Cortex-M4, soft-float, Thumb by default.
The dl-startup code fails to build with:
/home/test/outputs/arm-fdpic/host/bin/arm-buildroot-uclinuxfdpiceabi-gcc -c ldso/ldso/ldso.c -o ldso/ldso/ldso.oS -Wall -Wstrict-prototypes -Wstrict-aliasing -Wno-nonnull-compare -funsigned-char -fno-builtin -fno-asm -fmerge-all-constants -msoft-float -st d=gnu99 -mlittle-endian -fno-stack-protector -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. -Os -fstrict-aliasing -I./libpthread/linuxthreads/sysdeps/unix/ sysv/linux/arm -I./libpthread/linuxthreads/sysdeps/arm -I./libpthread/linuxthreads/sysdeps/unix/sysv/linux -I./libpthread/linuxthreads/sysdeps/pthread -I./libpthread/linuxthreads -I./libpthread -I./libc/sysdeps/linux/common -isystem /home/test/outputs/arm -fdpic/host/lib/gcc/arm-buildroot-uclinuxfdpiceabi/8.1.0/include-fixed -isystem /home/test/outputs/arm-fdpic/host/lib/gcc/arm-buildroot-uclinuxfdpiceabi/8.1.0/include -I/home/test/outputs/arm-fdpic/build/linux-headers-4.17.4/usr/include/ -DNDEBUG -DNOT_IN _libc -DIS_IN_rtld -fno-stack-protector -fno-omit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables -I./ldso/ldso/arm -I./ldso/include -I./ldso/ldso -DUCLIBC_RUNTIME_PREFIX="/" -DUCLIBC_LDSO="ld-uClibc.so.1" -DIN_LIB=rtld -mfdpic -DSHAR ED -DLDSO_ELFINTERP="arm/elfinterp.c" -DLDSO_MULTILIB_DIR="lib/" -MT ldso/ldso/ldso.oS -MD -MP -MF ldso/ldso/.ldso.oS.dep In file included from ./include/bits/waitstatus.h:72, from ./include/stdlib.h:44, from ./ldso/include/ldso.h:33, from ldso/ldso/ldso.c:32: ./ldso/include/dl-syscall.h: In function '_dl_pread': ./ldso/include/dl-syscall.h:169:69: warning: right shift count >= width of type [-Wshift-count-overflow] 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' # define __LONG_LONG_PAIR(HI, LO) LO, HI ^~ In file included from ./ldso/ldso/arm/dl-inlines.h:1, from ./ldso/include/ldso.h:183, from ldso/ldso/ldso.c:32: ./ldso/ldso/arm/../fdpic/dl-inlines.h: In function '_dl_funcdesc_for': ./ldso/ldso/arm/../fdpic/dl-inlines.h:180:8: warning: assignment to 'struct funcdesc_value **' from incompatible pointer type 'void **' [-Wincompatible-pointer-types] entry = htab_find_slot(ht, entry_point, 1, hash_pointer, eq_pointer); ^ In file included from ldso/ldso/ldso.c:45: ldso/ldso/arm/elfinterp.c: In function '_dl_linux_resolver': ldso/ldso/arm/elfinterp.c:95:9: warning: returning 'volatile struct funcdesc_value *' from a function with return type 'long unsigned int' makes integer from pointer without a cast [-Wint-conversion] return got_entry; ^~~~~~~~~ ldso/ldso/arm/elfinterp.c: In function '_dl_do_reloc': ldso/ldso/arm/elfinterp.c:364:65: warning: passing argument 1 of '_dl_funcdesc_for' makes pointer from integer without a cast [-Wint-conversion] reloc_value = (unsigned long) _dl_funcdesc_for(symbol_addr + reloc_value, sym_ref.tpnt->loadaddr.got_value); ~~~~~~~~~~~~^~~~~~~~~~~~~ In file included from ./ldso/ldso/arm/dl-inlines.h:1, from ./ldso/include/ldso.h:183, from ldso/ldso/ldso.c:32: ./ldso/ldso/arm/../fdpic/dl-inlines.h:165:25: note: expected 'void *' but argument is of type 'long unsigned int' _dl_funcdesc_for (void *entry_point, void *got_value) ~~~~~~^~~~~~~~~~~ In file included from ldso/ldso/ldso.c:45: ldso/ldso/arm/elfinterp.c: In function '_dl_do_lazy_reloc': ldso/ldso/arm/elfinterp.c:429:23: warning: assignment to 'void *' from 'unsigned int' makes pointer from integer without a cast [-Wint-conversion] dst->entry_point = DL_RELOC_ADDR(tpnt->loadaddr, dst->entry_point); ^ In file included from ldso/ldso/ldso.c:86: ldso/ldso/dl-startup.c: In function '_dl_start': ldso/ldso/dl-startup.c:313:13: warning: variable 'strtab' set but not used [-Wunused-but-set-variable] char *strtab; ^~~~~~ ldso/ldso/dl-startup.c:125:13: warning: variable 'got' set but not used [-Wunused-but-set-variable] ElfW(Addr) got; ^~~ In file included from ./ldso/ldso/arm/dl-sysdep.h:135, from ./ldso/include/dl-defs.h:77, from ./ldso/include/dl-string.h:15, from ./ldso/include/ldso.h:53, ...skipping... In file included from ./ldso/ldso/arm/dl-inlines.h:1, from ./ldso/include/ldso.h:183, from ldso/ldso/ldso.c:32: ./ldso/ldso/arm/../fdpic/dl-inlines.h:165:25: note: expected 'void *' but argument is of type 'long unsigned int' _dl_funcdesc_for (void *entry_point, void *got_value) ~~~~~~^~~~~~~~~~~ In file included from ldso/ldso/ldso.c:45: ldso/ldso/arm/elfinterp.c: In function '_dl_do_lazy_reloc': ldso/ldso/arm/elfinterp.c:429:23: warning: assignment to 'void *' from 'unsigned int' makes pointer from integer without a cast [-Wint-conversion] dst->entry_point = DL_RELOC_ADDR(tpnt->loadaddr, dst->entry_point); ^ In file included from ldso/ldso/ldso.c:86: ldso/ldso/dl-startup.c: In function '_dl_start': ldso/ldso/dl-startup.c:313:13: warning: variable 'strtab' set but not used [-Wunused-but-set-variable] char *strtab; ^~~~~~ ldso/ldso/dl-startup.c:125:13: warning: variable 'got' set but not used [-Wunused-but-set-variable] ElfW(Addr) got; ^~~ In file included from ./ldso/ldso/arm/dl-sysdep.h:135, from ./ldso/include/dl-defs.h:77, from ./ldso/include/dl-string.h:15, from ./ldso/include/ldso.h:53, from ldso/ldso/ldso.c:32: ldso/ldso/dl-hash.c: In function '_dl_find_hash': ./ldso/ldso/arm/../fdpic/dl-sysdep.h:111:4: warning: pointer/integer type mismatch in conditional expression : DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value)) ^ ldso/ldso/dl-hash.c:384:20: note: in expansion of macro 'DL_FIND_HASH_VALUE' return (char *)DL_FIND_HASH_VALUE(tpnt, type_class, sym); ^~~~~~~~~~~~~~~~~~ /tmp/cceTVltl.s: Assembler messages: /tmp/cceTVltl.s:14: Error: selected processor does not support ARM opcodes /tmp/cceTVltl.s:19: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r4,pc,#8' /tmp/cceTVltl.s:20: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r1,.L__ROFIXUP_LIST__' /tmp/cceTVltl.s:21: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r1,r1,r4' /tmp/cceTVltl.s:22: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r2,.L__ROFIXUP_END__' /tmp/cceTVltl.s:23: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r2,r2,r4' /tmp/cceTVltl.s:24: Error: attempt to use an ARM instruction on a Thumb-only processor -- `movs r0,r8' /tmp/cceTVltl.s:25: Error: attempt to use an ARM instruction on a Thumb-only processor -- `moveq r0,r7' /tmp/cceTVltl.s:26: Error: attempt to use an ARM instruction on a Thumb-only processor -- `push {r7,r8,r9,r10}' /tmp/cceTVltl.s:27: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl __self_reloc' /tmp/cceTVltl.s:28: Error: attempt to use an ARM instruction on a Thumb-only processor -- `pop {r7,r8,r9,r10}' /tmp/cceTVltl.s:29: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r1,r7' /tmp/cceTVltl.s:30: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r2,r8' /tmp/cceTVltl.s:31: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r3,r9' /tmp/cceTVltl.s:32: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,sp' /tmp/cceTVltl.s:33: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r5,sp,#8' /tmp/cceTVltl.s:34: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub sp,sp,#16' /tmp/cceTVltl.s:35: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r4,[sp,#4]' /tmp/cceTVltl.s:36: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r5,[sp,#0]' /tmp/cceTVltl.s:37: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r9,r0' /tmp/cceTVltl.s:38: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,r9' /tmp/cceTVltl.s:39: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl _dl_start' /tmp/cceTVltl.s:40: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r10,.L_dl_fini_gotofffuncdesc' /tmp/cceTVltl.s:41: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r10,r10,r4' /tmp/cceTVltl.s:42: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r5,[sp,#8]' /tmp/cceTVltl.s:43: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r9,[sp,#12]' /tmp/cceTVltl.s:44: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add sp,sp,#16' /tmp/cceTVltl.s:45: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bx r5' /tmp/cceTVltl.s:47: Error: attempt to use an ARM instruction on a Thumb-only processor -- `b .loopforever' make[2]: *** [ldso/ldso/ldso.oS] Error 1 make[1]: *** [/home/test/outputs/arm-fdpic/build/uclibc-1.0.30/.stamp_built] Error 2 make: *** [_all] Error 2
Any idea ?
Thanks for checking that. I did build with a GCC defaulting to Thumb mode, but it still uses a CPU that supports ARM mode, so I missed these problems.
Best regards,
Thomas Petazzoni
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Hello,
On Thu, 5 Jul 2018 10:55:26 +0200, Christophe Lyon wrote:
/tmp/cceTVltl.s: Assembler messages: /tmp/cceTVltl.s:14: Error: selected processor does not support ARM opcodes /tmp/cceTVltl.s:19: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r4,pc,#8' /tmp/cceTVltl.s:20: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r1,.L__ROFIXUP_LIST__' /tmp/cceTVltl.s:21: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r1,r1,r4' /tmp/cceTVltl.s:22: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r2,.L__ROFIXUP_END__' /tmp/cceTVltl.s:23: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r2,r2,r4' /tmp/cceTVltl.s:24: Error: attempt to use an ARM instruction on a Thumb-only processor -- `movs r0,r8' /tmp/cceTVltl.s:25: Error: attempt to use an ARM instruction on a Thumb-only processor -- `moveq r0,r7' /tmp/cceTVltl.s:26: Error: attempt to use an ARM instruction on a Thumb-only processor -- `push {r7,r8,r9,r10}' /tmp/cceTVltl.s:27: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl __self_reloc' /tmp/cceTVltl.s:28: Error: attempt to use an ARM instruction on a Thumb-only processor -- `pop {r7,r8,r9,r10}' /tmp/cceTVltl.s:29: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r1,r7' /tmp/cceTVltl.s:30: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r2,r8' /tmp/cceTVltl.s:31: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r3,r9' /tmp/cceTVltl.s:32: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,sp' /tmp/cceTVltl.s:33: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r5,sp,#8' /tmp/cceTVltl.s:34: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub sp,sp,#16' /tmp/cceTVltl.s:35: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r4,[sp,#4]' /tmp/cceTVltl.s:36: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r5,[sp,#0]' /tmp/cceTVltl.s:37: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r9,r0' /tmp/cceTVltl.s:38: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,r9' /tmp/cceTVltl.s:39: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl _dl_start' /tmp/cceTVltl.s:40: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r10,.L_dl_fini_gotofffuncdesc' /tmp/cceTVltl.s:41: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r10,r10,r4' /tmp/cceTVltl.s:42: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r5,[sp,#8]' /tmp/cceTVltl.s:43: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r9,[sp,#12]' /tmp/cceTVltl.s:44: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add sp,sp,#16' /tmp/cceTVltl.s:45: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bx r5' /tmp/cceTVltl.s:47: Error: attempt to use an ARM instruction on a Thumb-only processor -- `b .loopforever' make[2]: *** [ldso/ldso/ldso.oS] Error 1 make[1]: *** [/home/test/outputs/arm-fdpic/build/uclibc-1.0.30/.stamp_built] Error 2 make: *** [_all] Error 2
Any idea ?
Thanks for checking that. I did build with a GCC defaulting to Thumb mode, but it still uses a CPU that supports ARM mode, so I missed these problems.
Thanks for your quick feedback.
So you mean that you tested building for a Cortex-A platform and not Cortex-M ?
Since this FDPIC work is mainly intended for noMMU platforms, my first test was to build a toolchain targeting Cortex-M, which only support Thumb 2.
Best regards,
Thomas
On Thu, 5 Jul 2018 at 10:59, Thomas Petazzoni thomas.petazzoni@bootlin.com wrote:
Hello,
On Thu, 5 Jul 2018 10:55:26 +0200, Christophe Lyon wrote:
/tmp/cceTVltl.s: Assembler messages: /tmp/cceTVltl.s:14: Error: selected processor does not support ARM opcodes /tmp/cceTVltl.s:19: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r4,pc,#8' /tmp/cceTVltl.s:20: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r1,.L__ROFIXUP_LIST__' /tmp/cceTVltl.s:21: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r1,r1,r4' /tmp/cceTVltl.s:22: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r2,.L__ROFIXUP_END__' /tmp/cceTVltl.s:23: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r2,r2,r4' /tmp/cceTVltl.s:24: Error: attempt to use an ARM instruction on a Thumb-only processor -- `movs r0,r8' /tmp/cceTVltl.s:25: Error: attempt to use an ARM instruction on a Thumb-only processor -- `moveq r0,r7' /tmp/cceTVltl.s:26: Error: attempt to use an ARM instruction on a Thumb-only processor -- `push {r7,r8,r9,r10}' /tmp/cceTVltl.s:27: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl __self_reloc' /tmp/cceTVltl.s:28: Error: attempt to use an ARM instruction on a Thumb-only processor -- `pop {r7,r8,r9,r10}' /tmp/cceTVltl.s:29: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r1,r7' /tmp/cceTVltl.s:30: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r2,r8' /tmp/cceTVltl.s:31: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r3,r9' /tmp/cceTVltl.s:32: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,sp' /tmp/cceTVltl.s:33: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub r5,sp,#8' /tmp/cceTVltl.s:34: Error: attempt to use an ARM instruction on a Thumb-only processor -- `sub sp,sp,#16' /tmp/cceTVltl.s:35: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r4,[sp,#4]' /tmp/cceTVltl.s:36: Error: attempt to use an ARM instruction on a Thumb-only processor -- `str r5,[sp,#0]' /tmp/cceTVltl.s:37: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r9,r0' /tmp/cceTVltl.s:38: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r4,r9' /tmp/cceTVltl.s:39: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bl _dl_start' /tmp/cceTVltl.s:40: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r10,.L_dl_fini_gotofffuncdesc' /tmp/cceTVltl.s:41: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add r10,r10,r4' /tmp/cceTVltl.s:42: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r5,[sp,#8]' /tmp/cceTVltl.s:43: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r9,[sp,#12]' /tmp/cceTVltl.s:44: Error: attempt to use an ARM instruction on a Thumb-only processor -- `add sp,sp,#16' /tmp/cceTVltl.s:45: Error: attempt to use an ARM instruction on a Thumb-only processor -- `bx r5' /tmp/cceTVltl.s:47: Error: attempt to use an ARM instruction on a Thumb-only processor -- `b .loopforever' make[2]: *** [ldso/ldso/ldso.oS] Error 1 make[1]: *** [/home/test/outputs/arm-fdpic/build/uclibc-1.0.30/.stamp_built] Error 2 make: *** [_all] Error 2
Any idea ?
Thanks for checking that. I did build with a GCC defaulting to Thumb mode, but it still uses a CPU that supports ARM mode, so I missed these problems.
Thanks for your quick feedback.
So you mean that you tested building for a Cortex-A platform and not Cortex-M ?
Yes, the original work was actually for Cortex-R.
Since this FDPIC work is mainly intended for noMMU platforms, my first test was to build a toolchain targeting Cortex-M, which only support Thumb 2.
That was a good thing to do :)
Best regards,
Thomas
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
In ARM_EABI mode, the pread64 syscall parameters are aligned on 64-bits. This syscall is used in rtld when processing FDPIC relocations.
* ldso/include/dl-syscall.h (__syscall_pread): Fix definition. (__dl_pread): Fix syscall invocation. * ldso/ldso/fdpic/dl-sysdep.h (__DL_PREAD): Handle __NR_pread64.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h index 5ba8c87..9d80c6a 100644 --- a/ldso/include/dl-syscall.h +++ b/ldso/include/dl-syscall.h @@ -159,14 +159,25 @@ static __always_inline _syscall4(int, _dl_readlink, int, id, const char *, path,
#ifdef __NR_pread64 #define __NR___syscall_pread __NR_pread64 +#ifdef __UCLIBC_SYSCALL_ALIGN_64BIT__ +static __always_inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf, size_t, dummy, + size_t, count, off_t, offset_hi, off_t, offset_lo) + +static __always_inline ssize_t +_dl_pread(int fd, void *buf, size_t count, off_t offset) +{ + return __syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR((offset >> 32), (offset & 0xffffffff))); +} +#else static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf, size_t, count, off_t, offset_hi, off_t, offset_lo)
static __always_inline ssize_t _dl_pread(int fd, void *buf, size_t count, off_t offset) { - return __syscall_pread(fd, buf, count, offset, offset >> 31); + return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset)); } +#endif #elif defined __NR_pread #define __NR___syscall_pread __NR_pread static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf, diff --git a/ldso/ldso/fdpic/dl-sysdep.h b/ldso/ldso/fdpic/dl-sysdep.h index 546811a..6ab303b 100644 --- a/ldso/ldso/fdpic/dl-sysdep.h +++ b/ldso/ldso/fdpic/dl-sysdep.h @@ -96,7 +96,7 @@ struct funcdesc_ht; elfinterp.c. */ #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
-#ifdef __NR_pread +#if defined(__NR_pread) || defined(__NR_pread64) #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \ (_dl_pread((FD), (BUF), (SIZE), (OFFSET))) #endif
* libc/sysdeps/linux/arm/crt1.S: Define _start for __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libc/sysdeps/linux/arm/crt1.S b/libc/sysdeps/linux/arm/crt1.S index ab3b0d2..f74cf3b 100644 --- a/libc/sysdeps/linux/arm/crt1.S +++ b/libc/sysdeps/linux/arm/crt1.S @@ -92,6 +92,71 @@ ARM register quick reference: pc r15 program counter */
+#if defined(__FDPIC__) +#include <features.h> +#include <bits/arm_asm.h> + +.text + .arm + .globl _start + +_start: + /* Start by self relocation. */ + sub r4, pc, #8 + ldr r1, .L__ROFIXUP_LIST__ + add r1, r1, r4 + ldr r2, .L__ROFIXUP_END__ + add r2, r2, r4 + mov r0, r7 + push {r9, r10} + bl __self_reloc + pop {r9, r10} + mov r9, r0 + + /* Clear the frame pointer since this is the outermost frame. */ + mov r3, #0 + mov fp, r3 + + /* Now fill __uClibc_main arguments. */ + sub sp, sp, #16 /* Reserve space for 3 args (keep aligment) */ + ldr r0, .L_main_got_funcdesc /* r0 GOT FUNCDESC of main */ + ldr r0, [r9, r0] + ldr r1, [sp, #16] /* argc */ + add r2, sp, #20 /* argv */ + ldr r3, .L_init_got_funcdesc /* r3 GOT init */ + ldr r3, [r9, r3] + ldr r4, .L_fini_got_funcdesc + ldr r4, [r9, r4] + str r4, [sp, #0] /* sp + 0 GOT fini */ + movs r4, r8 /* Test if static binary (r8 is 0 as there is no interpreter). */ + movne r4, r10 + moveq r4, #0 + str r4, [sp, #4] /* sp + 4 got rtld_fini */ + mov r4, r2 /* stack_end is unused.... */ + str r4, [sp, #8] /* sp + 8 got stack_end */ + bl __uClibc_main + /* We should never get here.... */ + bl abort +.L__ROFIXUP_LIST__: + .word __ROFIXUP_LIST__ - _start +.L__ROFIXUP_END__: + .word __ROFIXUP_END__ - _start +.L_main_got_funcdesc: + .word main(GOTFUNCDESC) +.L_init_got_funcdesc: + .word _init(GOTFUNCDESC) +.L_fini_got_funcdesc: + .word _fini(GOTFUNCDESC) + +/* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start + +#else /* defined(__FDPIC__) */ #include <features.h> #include <bits/arm_asm.h>
@@ -250,3 +315,4 @@ __data_start: .long 0 .weak data_start data_start = __data_start +#endif /* defined(__FDPIC__) */
Here v2 of this patch.
Implements __gnu_Unwind_Find_got(), which is called from libgcc while unwinding.
* libc/sysdeps/linux/arm/Makefile.arch (CSRC): Add find._got.c. * libc/sysdeps/linux/arm/find_got.c: New file.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libc/sysdeps/linux/arm/Makefile.arch b/libc/sysdeps/linux/arm/Makefile.arch index f9ac88b..40a0184 100644 --- a/libc/sysdeps/linux/arm/Makefile.arch +++ b/libc/sysdeps/linux/arm/Makefile.arch @@ -23,7 +23,7 @@ $(eval $(call cache-output-var,IS_EABI,$(CC_IS_EABI_CHECK) -x c - -E -dM </dev/n
CSRC-$(IS_EABI) += aeabi_assert.c aeabi_atexit.c aeabi_errno_addr.c \ aeabi_localeconv.c aeabi_memclr.c aeabi_memcpy.c \ - aeabi_memmove.c aeabi_memset.c find_exidx.c + aeabi_memmove.c aeabi_memset.c find_exidx.c find_got.c SSRC-$(IS_EABI) += syscall-eabi.S CSRC-$(if $(IS_EABI),,y)) += syscall.c ARCH_OBJ_FILTEROUT-$(IS_EABI) := syscall.c diff --git a/libc/sysdeps/linux/arm/find_got.c b/libc/sysdeps/linux/arm/find_got.c new file mode 100644 index 0000000..1292388 --- /dev/null +++ b/libc/sysdeps/linux/arm/find_got.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + http://www.gnu.org/licenses/. */ + +#include <link.h> +#include <unwind.h> + +#if __FDPIC__ +#include <bits/elf-fdpic.h> + +struct got_callback_data +{ + _Unwind_Ptr pc; + _Unwind_Ptr got; +}; + +static __always_inline int +__dl_addr_in_loadaddr(void *p, struct elf32_fdpic_loadaddr loadaddr) +{ + struct elf32_fdpic_loadmap *map = loadaddr.map; + int c; + + for (c = 0; c < map->nsegs; c++) + if ((void *)map->segs[c].addr <= p && + (char *)p < (char *)map->segs[c].addr + map->segs[c].p_memsz) + return 1; + + return 0; +} + +/* Callback to return the GOT value if the module contains PC. */ +static int +find_got_callback (struct dl_phdr_info * info, size_t size, void * ptr) +{ + int match = 0; + struct got_callback_data *data = (struct got_callback_data *) ptr; + + if (__dl_addr_in_loadaddr((void *) data->pc, info->dlpi_addr)) { + match = 1; + data->got = (_Unwind_Ptr) info->dlpi_addr.got_value; + } + + return match; +} + +/* Find the GOT that corresponds to the module containing PC. */ +_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc); +_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc) +{ + struct got_callback_data data; + + data.pc = pc; + if (dl_iterate_phdr (find_got_callback, &data) <= 0) + return 0; + + return data.got; +} +#endif +
* libc/misc/internals/__uClibc_main.c (funcdesc_value): New. (fdpic_init_array_jump): New. (__uClibc_fini): Support __FDPIC__. (__uClibc_main): Likewise.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index d80565e..d8286f2 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -48,6 +48,39 @@ int _pe_secure = 0; libc_hidden_data_def(_pe_secure)
+#if !defined(SHARED) && defined(__FDPIC__) +struct funcdesc_value +{ + void *entry_point; + void *got_value; +} __attribute__((__aligned__(8))); + + +/* Prevent compiler optimization that removes GOT assignment. + + Due to optimization passes (block split and move), in the rare case + where use r9 is the single instruction in a block we can have the + following behaviour: + - this block is marked as a forward block since use is not + considered as an active instruction after reload pass. + + - In this case a jump in this block can be moved to the start of the + next one and so remove use in this flow of instructions which can + lead to a removal of r9 restoration after a call. */ +#define _dl_stabilize_funcdesc(val) \ + ({ __asm__ ("" : "+m" (*(val))); (val); }) + +static void fdpic_init_array_jump(void *addr) +{ + struct funcdesc_value *fm = (struct funcdesc_value *) fdpic_init_array_jump; + struct funcdesc_value fd = {addr, fm->got_value}; + + void (*pf)(void) = (void*) _dl_stabilize_funcdesc(&fd); + + (*pf)(); +} +#endif + #ifndef SHARED void *__libc_stack_end = NULL;
@@ -307,7 +340,11 @@ void __uClibc_fini(void) # elif !defined (__UCLIBC_FORMAT_SHARED_FLAT__) size_t i = __fini_array_end - __fini_array_start; while (i-- > 0) +#if !defined(SHARED) && defined(__FDPIC__) + fdpic_init_array_jump(__fini_array_start[i]); +#else (*__fini_array_start [i]) (); +#endif # endif if (__app_fini != NULL) (__app_fini)(); @@ -436,7 +473,11 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, const size_t size = __preinit_array_end - __preinit_array_start; size_t i; for (i = 0; i < size; i++) +#if !defined(SHARED) && defined(__FDPIC__) + fdpic_init_array_jump(__preinit_array_start[i]); +#else (*__preinit_array_start [i]) (); +#endif } # endif /* Run all the application's ctors now. */ @@ -452,7 +493,11 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, const size_t size = __init_array_end - __init_array_start; size_t i; for (i = 0; i < size; i++) +#if !defined(SHARED) && defined(__FDPIC__) + fdpic_init_array_jump(__init_array_start[i]); +#else (*__init_array_start [i]) (); +#endif } # endif #endif
Add support for R_ARM_FUNCDESC_VALUE and implement _dl_linux_resolver for FDPIC on ARM.
* ldso/ldso/arm/elfinterp.c (_dl_linux_resolver): Support __FDPIC__. (_dl_do_lazy_reloc): Likewise. * ldso/ldso/arm/resolve.S (_dl_linux_resolve): Likewise.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 1435c2c..3bcd675 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -34,13 +34,69 @@
extern int _dl_linux_resolve(void);
-unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) -{ #if __FDPIC__ - /* FIXME: implement. */ - while(1) ; - return 0; +unsigned long _dl_linux_resolver (struct elf_resolve *tpnt, int reloc_offet) +{ + ELF_RELOC *this_reloc; + char *strtab; + ElfW(Sym) *symtab; + int symtab_index; + char *rel_addr; + char *new_addr; + struct funcdesc_value funcval; + struct funcdesc_value volatile *got_entry; + char *symname; + struct symbol_ref sym_ref; + + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL]; + + this_reloc = (ELF_RELOC *)(intptr_t)(rel_addr + reloc_offet); + symtab_index = ELF_R_SYM(this_reloc->r_info); + + symtab = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *) tpnt->dynamic_info[DT_STRTAB]; + sym_ref.sym = &symtab[symtab_index]; + sym_ref.tpnt = NULL; + symname= strtab + symtab[symtab_index].st_name; + + /* Address of GOT entry fix up */ + got_entry = (struct funcdesc_value *) DL_RELOC_ADDR(tpnt->loadaddr, this_reloc->r_offset); + + /* Get the address to be used to fill in the GOT entry. */ + new_addr = _dl_find_hash(symname, &_dl_loaded_modules->symbol_scope, NULL, 0, &sym_ref); + if (!new_addr) { + new_addr = _dl_find_hash(symname, NULL, NULL, 0, &sym_ref); + if (!new_addr) { + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, symname); + _dl_exit(1); + } + } + + funcval.entry_point = new_addr; + funcval.got_value = sym_ref.tpnt->loadaddr.got_value; + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_bindings) { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); + if (_dl_debug_detail) + _dl_dprintf(_dl_debug_file, + "\n\tpatched (%x,%x) ==> (%x,%x) @ %x\n", + got_entry->entry_point, got_entry->got_value, + funcval.entry_point, funcval.got_value, + got_entry); + } + if (1 || !_dl_debug_nofixups) { + *got_entry = funcval; + } +#else + *got_entry = funcval; +#endif + + return got_entry; +} #else +unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) +{ ELF_RELOC *this_reloc; char *strtab; char *symname; @@ -93,8 +149,8 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) #endif
return new_addr; -#endif } +#endif
static int _dl_parse(struct elf_resolve *tpnt, struct r_scope_elem *scope, @@ -346,7 +402,7 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope, int reloc_type; unsigned long *reloc_addr;
- reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_addr = (unsigned long *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset); reloc_type = ELF_R_TYPE(rpnt->r_info);
#if defined (__SUPPORT_LD_DEBUG__) @@ -356,8 +412,17 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope, switch (reloc_type) { case R_ARM_NONE: break; + case R_ARM_JUMP_SLOT: - *reloc_addr += (unsigned long) tpnt->loadaddr; + *reloc_addr = DL_RELOC_ADDR(tpnt->loadaddr, *reloc_addr); + break; + case R_ARM_FUNCDESC_VALUE: + { + struct funcdesc_value *dst = (struct funcdesc_value *) reloc_addr; + + dst->entry_point = DL_RELOC_ADDR(tpnt->loadaddr, dst->entry_point); + dst->got_value = tpnt->loadaddr.got_value; + } break; default: return -1; /*call _dl_exit(1) */ diff --git a/ldso/ldso/arm/resolve.S b/ldso/ldso/arm/resolve.S index 2a51643..039a6b7 100644 --- a/ldso/ldso/arm/resolve.S +++ b/ldso/ldso/arm/resolve.S @@ -107,6 +107,27 @@ .type _dl_linux_resolve,%function .align 4;
+#if __FDPIC__ +/* + * _dl_linux_resolve() FDPIC version receives the following parameters from + * lazy PLT entry: + * R12: GOT address for the resolver GOT + * SP[0]: funcdesc_value_reloc_offset(foo) + * R9: GOT address for the caller GOT + * _dl_linux_resolver() will return a function descriptor address in R0. + */ +_dl_linux_resolve: + push {r0, r1, r2, r3, r14} + ldr r0, [r9, #8] + ldr r1, [sp, #20] + mov r9, r12 + blx _dl_linux_resolver + ldr r9, [r0, #4] + ldr r12, [r0] + pop {r0, r1, r2, r3, r14} + add sp, sp, #4 + bx r12 +#else _dl_linux_resolve: @ _dl_linux_resolver is a standard subroutine call, therefore it @ preserves everything except r0-r3 (a1-a4), ip and lr. This @@ -129,6 +150,7 @@ _dl_linux_resolve: ldmia sp!, {r0, r1, r2, r3, r4, lr}
BX(ip) +#endif /* __FDPIC__ */ #else @ In the thumb case _dl_linux_resolver is thumb. If a bl is used @ from arm code the linker will insert a stub call which, with
* ldso/ldso/dl-elf.c (_dl_load_elf_shared_library): Fix l_tls_initimage computation. * ldso/ldso/ldso.c (_dl_get_ready_to_run): Likewise.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 1768b5b..9cb46de 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -863,11 +863,11 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned int rflags, { # ifdef __SUPPORT_LD_DEBUG_EARLY__ char *tmp = (char *) tpnt->l_tls_initimage; - tpnt->l_tls_initimage = (char *) tlsppnt->p_vaddr + tpnt->loadaddr; + tpnt->l_tls_initimage = (char *) DL_RELOC_ADDR(tpnt->loadaddr, tlsppnt->p_vaddr; _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", tmp, tpnt->l_tls_initimage, tpnt->l_tls_initimage_size); tmp = 0; # else - tpnt->l_tls_initimage = (char *) tlsppnt->p_vaddr + tpnt->loadaddr; + tpnt->l_tls_initimage = (char *) DL_RELOC_ADDR(tpnt->loadaddr, tlsppnt->p_vaddr); # endif } } diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index c625757..06b0ac8 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -772,7 +772,7 @@ of this helper program; chances are you did not intend to run this program.\n\ char *tmp attribute_unused = (char *) app_tpnt->l_tls_initimage; app_tpnt->l_tls_initimage = - (char *) app_tpnt->l_tls_initimage + app_tpnt->loadaddr; + (char *) DL_RELOC_ADDR(app_tpnt->loadaddr, app_tpnt->l_tls_initimage); _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", tmp, app_tpnt->l_tls_initimage, app_tpnt->l_tls_initimage_size); }
Otherwise we have link errors because of unresolved refs in libgcc.a:
ld: /lib/gcc/arm-none-uclinuxfdpiceabi/9.0.0/libgcc.a(pr-support.o): in function `_Unwind_GetDataRelBase': /libgcc/config/arm/pr-support.c:378: undefined reference to `abort' ld: /lib/gcc/arm-none-uclinuxfdpiceabi/9.0.0/libgcc.a(unwind-arm.o): in function `unwind_phase2_forced': /libgcc/unwind-arm-common.inc:511: undefined reference to `memcpy'
* ldso/ldso/Makefile.in (CFLAGS-rtld): Always use -fno-unwind-tables -fno-asynchronous-unwind-tables on arm
Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/Makefile.in b/ldso/ldso/Makefile.in index acb1a5b..4f2a184 100644 --- a/ldso/ldso/Makefile.in +++ b/ldso/ldso/Makefile.in @@ -14,12 +14,10 @@ ifneq ($(TARGET_ARCH),arc) CFLAGS-rtld += -fno-omit-frame-pointer endif
-ifeq ($(DODEBUG),y) ifeq ($(TARGET_ARCH),arm) # This stuff will not work with -funwind-tables / -fasynchronous-unwind-tables CFLAGS-rtld += -fno-unwind-tables -fno-asynchronous-unwind-tables endif -endif
CFLAGS-rtld += -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) -I$(top_srcdir)ldso/include -I$(top_srcdir)ldso/ldso CFLAGS-rtld += -DUCLIBC_RUNTIME_PREFIX="$(RUNTIME_PREFIX)" -DUCLIBC_LDSO="$(UCLIBC_LDSO)"
Change clone.S so that in FDPIC case we take into account the fact that we are given a function descriptor.
* libc/sysdeps/linux/arm/clone.S (__clone): Support __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libc/sysdeps/linux/arm/clone.S b/libc/sysdeps/linux/arm/clone.S index 8ca50fc..eacf3db 100644 --- a/libc/sysdeps/linux/arm/clone.S +++ b/libc/sysdeps/linux/arm/clone.S @@ -130,8 +130,20 @@ PSEUDO_END (__clone) .cantunwind @ pick the function arg and call address off the stack and execute ldr r0, [sp, #4] +#if defined(__FDPIC__) + ldr r12, [sp] + mov r4, r9 + ldr r9, [r12, #4] + mov lr, pc + ldr pc, [r12] +#else mov lr, pc ldr pc, [sp] +#endif + +#if defined(__FDPIC__) + mov r9, r4 +#endif
@ and we are done, passing the return value through r0 b HIDDEN_JUMPTARGET(_exit)
* extra/Configs/Config.in: enable UCLIBC_HAS_THREADS_NATIVE on TARGET_arm.
Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 7443903..f96511f 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -541,7 +541,7 @@ config UCLIBC_HAS_THREADS_NATIVE !TARGET_h8300 && \ !TARGET_hppa && \ !TARGET_ia64 && \ - ARCH_USE_MMU + (ARCH_USE_MMU || TARGET_arm) help If you want to compile uClibc with NPTL support, then answer Y.
rtld must call _dl_find_hash() with ELF_RTYPE_CLASS_DLSYM since we want a function descriptor.
* ldso/ldso/ldso.c (_dl_get_ready_to_run): Support __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 06b0ac8..b335476 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -444,6 +444,11 @@ void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, size_t relro_size = 0; struct r_scope_elem *global_scope; struct elf_resolve **local_scope; +#if defined(__FDPIC__) + int rtype_class = ELF_RTYPE_CLASS_DLSYM; +#else + int rtype_class = ELF_RTYPE_CLASS_PLT; +#endif
#if defined(USE_TLS) && USE_TLS void *tcbp = NULL; @@ -1422,21 +1427,21 @@ of this helper program; chances are you did not intend to run this program.\n\
/* Find the real malloc function and make ldso functions use that from now on */ _dl_malloc_function = (void* (*)(size_t)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "malloc", - global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + global_scope, NULL, rtype_class, NULL);
#if defined(USE_TLS) && USE_TLS /* Find the real functions and make ldso functions use them from now on */ _dl_calloc_function = (void* (*)(size_t, size_t)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "calloc", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "calloc", global_scope, NULL, rtype_class, NULL);
_dl_realloc_function = (void* (*)(void *, size_t)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "realloc", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "realloc", global_scope, NULL, rtype_class, NULL);
_dl_free_function = (void (*)(void *)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "free", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "free", global_scope, NULL, rtype_class, NULL);
_dl_memalign_function = (void* (*)(size_t, size_t)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "memalign", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "memalign", global_scope, NULL, rtype_class, NULL);
#endif
Make _dl_initial_error_catch_tsd hidden, such that we do not need a FUNCDESC relocation when initializing _dl_error_catch_tsd.
* ldso/ldso/dl-tls.c (_dl_initial_error_catch_tsd): Declare hidden.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/ldso/dl-tls.c b/ldso/ldso/dl-tls.c index 2d21242..80da815 100644 --- a/ldso/ldso/dl-tls.c +++ b/ldso/ldso/dl-tls.c @@ -957,6 +957,7 @@ _dl_add_to_slotinfo (struct link_map *l) /* Taken from glibc/elf/rtld.c */ static bool tls_init_tp_called;
+rtld_hidden_proto(_dl_initial_error_catch_tsd) /* _dl_error_catch_tsd points to this for the single-threaded case. It's reset by the thread library for multithreaded programs. */ void ** __attribute__ ((const))
Since mprotect does not work on MMU-less systems, disable it if __ARCH_USE_MMU__ is not defined.
* libpthread/nptl/allocatestack.c (change_stack_perm): Call mprotect only if __ARCH_USE_MMU__ is defined. (allocate_stack): Likewise.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c index 2900517..1379795 100644 --- a/libpthread/nptl/allocatestack.c +++ b/libpthread/nptl/allocatestack.c @@ -328,8 +328,10 @@ change_stack_perm (struct pthread *pd #else # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" #endif +#ifdef __ARCH_USE_MMU__ if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) return errno; +#endif
return 0; } @@ -593,6 +595,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #elif defined _STACK_GROWS_UP char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1); #endif +#ifdef __ARCH_USE_MMU__ if (mprotect (guard, guardsize, PROT_NONE) != 0) { int err; @@ -618,6 +621,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
return err; } +#endif
pd->guardsize = guardsize; } @@ -630,6 +634,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1); char *oldguard = mem + (((size - pd->guardsize) / 2) & ~pagesize_m1);
+#ifdef __ARCH_USE_MMU__ if (oldguard < guard && mprotect (oldguard, guard - oldguard, prot) != 0) goto mprot_error; @@ -647,6 +652,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, pd->guardsize - guardsize, prot) != 0) goto mprot_error; #endif +#endif
pd->guardsize = guardsize; }
They do not work on MMU-less systems.
For atfork, implement a hidden function that always returns EPERM.
* libpthread/nptl/sysdeps/unix/sysv/linux/fork.c: Disable if __ARCH_USE_MMU__ is not defined. * libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c (__libc_pthread_init): Handle __ARCH_USE_MMU__. * libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c: Likewise. * libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c: Likewise.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c index 9b96152..429fb90 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c @@ -28,6 +28,7 @@ #include <atomic.h> #include <errno.h>
+#ifdef __ARCH_USE_MMU__ unsigned long int *__fork_generation_pointer;
@@ -206,3 +207,5 @@ fork (void) return pid; } libc_hidden_def(fork) + +#endif /* __ARCH_USE_MMU__ */ diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c b/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c index 0df9951..0cdbcfe 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c @@ -40,10 +40,14 @@ __libc_pthread_init ( void (*reclaim) (void)) { /* Remember the pointer to the generation counter in libpthread. */ +#ifdef __ARCH_USE_MMU__ __fork_generation_pointer = ptr; +#endif
/* Called by a child after fork. */ +#ifdef __ARCH_USE_MMU__ __register_atfork (NULL, NULL, reclaim, NULL); +#endif
#ifndef TLS_MULTIPLE_THREADS_IN_TCB return &__libc_multiple_threads; diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c index b745f9d..55835e5 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c @@ -24,6 +24,7 @@ #include <tls.h>
+#ifdef __ARCH_USE_MMU__ /* Lock to protect allocation and deallocation of fork handlers. */ int __fork_lock = LLL_LOCK_INITIALIZER;
@@ -118,6 +119,18 @@ __linkin_atfork (struct fork_handler *newp) while (catomic_compare_and_exchange_bool_acq (&__fork_handlers, newp, newp->next) != 0); } +#else +int +__register_atfork ( + void (*prepare) (void), + void (*parent) (void), + void (*child) (void), + void *dso_handle) +{ + return EPERM; +} +libc_hidden_def (__register_atfork) +#endif
#if 0 libc_freeres_fn (free_mem) @@ -145,4 +158,3 @@ libc_freeres_fn (free_mem) } } #endif - diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c index 69e2621..e958e71 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c @@ -22,7 +22,7 @@ #include <atomic.h> #include <tls.h>
- +#ifdef __ARCH_USE_MMU__ void __unregister_atfork ( void *dso_handle) @@ -120,3 +120,11 @@ __unregister_atfork ( deleted = deleted->next; } } +#else +void +__unregister_atfork ( + void *dso_handle) +{ + /* Nothing to do. */ +} +#endif
start_thread() uses it, but it is not supported on MMU-less systems.
* libpthread/nptl/pthread_create.c (start_thread): Call madvise only if __ARCH_USE_MMU__ is defined.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/pthread_create.c b/libpthread/nptl/pthread_create.c index 3064b40..5a7957d 100644 --- a/libpthread/nptl/pthread_create.c +++ b/libpthread/nptl/pthread_create.c @@ -373,8 +373,12 @@ start_thread (void *arg) size_t freesize = ((char *) pd->stackblock - sp) & ~pagesize_m1; #endif assert (freesize < pd->stackblock_size); + + /* madvise is not supported on MMU-less systems. */ +#ifdef __ARCH_USE_MMU__ if (freesize > PTHREAD_STACK_MIN) madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED); +#endif
/* If the thread is detached free the TCB. */ if (IS_DETACHED (pd))
phdr->p_vaddr of TLS segment is not a valid value for FDPIC so we can either translate phdr->p_vaddr using loadmap (not easy here) or use a new linker script defined symbol, whih this patch does.
* libpthread/nptl/sysdeps/generic/libc-tls.c (__tdata_start): Declare. (__libc_setup_tls): Support __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index 58e77ff..725f3df 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -36,6 +36,11 @@ extern ElfW(Phdr) *_dl_phdr; extern size_t _dl_phnum;
+#ifdef __FDPIC__ +/* phdr->p_vaddr is not valid in FDPIC mode. To find tdata start we + use the linker script defined symbol __tdata_start. */ +extern int __tdata_start; +#endif
static dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS];
@@ -130,7 +135,11 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) /* Remember the values we need. */ memsz = phdr->p_memsz; filesz = phdr->p_filesz; +#ifdef __FDPIC__ + initimage = (void *) &__tdata_start; +#else initimage = (void *) phdr->p_vaddr; +#endif align = phdr->p_align; if (phdr->p_align > max_align) max_align = phdr->p_align;
Allow both tmpfs and ramfs for shm devices.
* libpthread/nptl/linux_fsinfo.h (SHMFS_SUPER_MAGIC_WITH_MMU): Define. (SHMFS_SUPER_MAGIC_WITHOUT_MMU): Define. * libpthread/nptl/sem_open.c (__where_is_shmfs): Add support for SHMFS_SUPER_MAGIC_WITHOUT_MMU.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/linux_fsinfo.h b/libpthread/nptl/linux_fsinfo.h index 8537581..4abe792 100644 --- a/libpthread/nptl/linux_fsinfo.h +++ b/libpthread/nptl/linux_fsinfo.h @@ -126,7 +126,10 @@ #define XENIX_SUPER_MAGIC 0x012ff7b4
/* Constant that identifies the `shm' filesystem. */ -#define SHMFS_SUPER_MAGIC 0x01021994 +/* Mount as tmpfs. */ +#define SHMFS_SUPER_MAGIC_WITH_MMU 0x01021994 +/* The kernel uses a ramfs file system for tmpfs. */ +#define SHMFS_SUPER_MAGIC_WITHOUT_MMU 0x858458f6
/* Constants that identify the `xfs' filesystem. */ #define XFS_SUPER_MAGIC 0x58465342 diff --git a/libpthread/nptl/sem_open.c b/libpthread/nptl/sem_open.c index d811ec5..2746da1 100644 --- a/libpthread/nptl/sem_open.c +++ b/libpthread/nptl/sem_open.c @@ -72,7 +72,9 @@ __where_is_shmfs (void)
/* The canonical place is /dev/shm. This is at least what the documentation tells everybody to do. */ - if (__statfs (defaultmount, &f) == 0 && f.f_type == SHMFS_SUPER_MAGIC) + if (__statfs (defaultmount, &f) == 0 + && (f.f_type == SHMFS_SUPER_MAGIC_WITH_MMU + || f.f_type == SHMFS_SUPER_MAGIC_WITHOUT_MMU)) { /* It is in the normal place. */ mountpoint.dir = (char *) defaultdir; @@ -106,7 +108,9 @@ __where_is_shmfs (void) /* First make sure this really is the correct entry. At least some versions of the kernel give wrong information because of the implicit mount of the shmfs for SysV IPC. */ - if (__statfs (mp->mnt_dir, &f) != 0 || f.f_type != SHMFS_SUPER_MAGIC) + if (__statfs (mp->mnt_dir, &f) != 0 + || (f.f_type != SHMFS_SUPER_MAGIC_WITH_MMU + && f.f_type != SHMFS_SUPER_MAGIC_WITHOUT_MMU)) continue;
namelen = strlen (mp->mnt_dir);
* libpthread/nptl/Makefile.in (libpthread-routines-): Remove pthread_mutex_getprioceiling.c and pthread_mutex_setprioceiling.c.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/Makefile.in b/libpthread/nptl/Makefile.in index a2f30ac..bd220ba 100644 --- a/libpthread/nptl/Makefile.in +++ b/libpthread/nptl/Makefile.in @@ -18,7 +18,6 @@ libpthread-shared-only-routines-y = version.c libpthread-static-only-routines-y = pthread_atfork.c libpthread-routines- += $(notdir $(wildcard $(libpthread_DIR)/gen_*.c)) # dummy generated files libpthread-routines- += allocatestack.c # dummy included by pthread_create.c -libpthread-routines- += pthread_mutex_getprioceiling.c pthread_mutex_setprioceiling.c # XXX: delete those or use them! libpthread-routines-$(UCLIBC_SUSV4_LEGACY) += pthread_getconcurrency.c \ pthread_setconcurrency.c libpthread_CSRC = $(filter-out $(libpthread-routines-) \
* libc/stdlib/system.c (FORK): Map to vfork if __ARCH_USE_MMU__ is defined.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libc/stdlib/system.c b/libc/stdlib/system.c index 771c30e..4c010bb 100644 --- a/libc/stdlib/system.c +++ b/libc/stdlib/system.c @@ -81,6 +81,7 @@ out: libc_hidden_proto(sigaction) libc_hidden_proto(waitpid)
+#ifdef __ARCH_USE_MMU__ #if defined __ia64__ # define FORK() \ INLINE_SYSCALL (clone2, 6, CLONE_PARENT_SETTID | SIGCHLD, NULL, 0, \ @@ -92,6 +93,10 @@ libc_hidden_proto(waitpid) # define FORK() \ INLINE_SYSCALL (clone, 3, CLONE_PARENT_SETTID | SIGCHLD, 0, &pid) #endif +#else +# define FORK() \ + vfork() +#endif
static void cancel_handler (void *arg);
busybox init checks it has pid 1, but getpid() returns another value when building busybox statically. This is because the corresponding area is not cleared when allocated (it is allocated with MAP_UNINITIALIZED, whose behavior depends on the Linux kernel's CONFIG_MMAP_ALLOW_UNINITIALIZED).
This patch fixes the problem by explicitly clearing the memory area.
* libpthread/nptl/sysdeps/generic/libc-tls.c (__libc_tls_setup): Clear tlsblock.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index 725f3df..5f89c91 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -162,6 +162,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) tcb_offset = roundup (tcbsize, align ?: 1); tlsblock = sbrk (tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); + memset(tlsblock, '\0', tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); tlsblock += TLS_PRE_TCB_SIZE; # else /* In case a model with a different layout for the TCB and DTV
Replace sbrk with mmap since this commit disables sbrk area for FDPIC MMU-less platform: fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/bi...
* libpthread/nptl/sysdeps/generic/libc-tls.c (__libc_setup_tls): Handle __FDPIC__.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index 5f89c91..a6df4cd 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -26,7 +26,7 @@ #include <link.h> #include <string.h> #include <stdlib.h> - +#include <sys/mman.h>
#ifdef SHARED #error makefile bug, this file is for static only @@ -155,13 +155,28 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) The initialized value of _dl_tls_static_size is provided by dl-open.c to request some surplus that permits dynamic loading of modules with IE-model TLS. */ + /* Use mmap instead of sbrk since this commit disables sbrk area + for FDPIC MMU-less platforms: + fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU + https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/bi... + */ # if defined(TLS_TCB_AT_TP) tcb_offset = roundup (memsz + GL(dl_tls_static_size), tcbalign); +# if defined(__FDPIC__) + tlsblock = mmap (NULL, tcb_offset + tcbsize + max_align, + PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +# else tlsblock = sbrk (tcb_offset + tcbsize + max_align); +# endif # elif defined(TLS_DTV_AT_TP) tcb_offset = roundup (tcbsize, align ?: 1); +# if defined(__FDPIC__) + tlsblock = mmap (NULL, tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size), + PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +# else tlsblock = sbrk (tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); +# endif memset(tlsblock, '\0', tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); tlsblock += TLS_PRE_TCB_SIZE; # else
In case __nptl_nthreads is not defined in the final binary then avoid dereferencing the address since it's null. Anyway this means there is no other thread and so we must exit.
* libc/misc/internals/__uClibc_main.c (__uClibc_main): Handle case where &__nptl_nthreads is null.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index d8286f2..849bca8 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -544,7 +544,7 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, result = 0; unsigned int *const ptr = &__nptl_nthreads;
- if (! atomic_decrement_and_test (ptr)) + if (ptr && ! atomic_decrement_and_test (ptr)) /* Not much left to do but to exit the thread, not the process. */ __exit_thread_inline (0); }
dlclose can crash or stuck the system:
When calling dlclose() then system can crash or freeze, because htab_delete() in ldso/ldso/fdpic/dl-inlines.h uses size_t for i which is a typedef to unsigned int. We exit the loop on negative value of i which can never occur since i is an unsigned int. This leads to random free of various pointers that kill the system.
* ldso/include/inline-hashtab.h (htab_delete): Change type of 'i' to int.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/ldso/include/inline-hashtab.h b/ldso/include/inline-hashtab.h index 4a48120..c6c584b 100644 --- a/ldso/include/inline-hashtab.h +++ b/ldso/include/inline-hashtab.h @@ -107,7 +107,7 @@ htab_create(void) static __always_inline void htab_delete(struct funcdesc_ht *htab) { - size_t i; + int i;
for (i = htab->size - 1; i >= 0; i--) if (htab->entries[i])
* libm/s_isnan.c: Add isnan weak alias.
Signed-off-by: Mickaël Guêné mickael.guene@st.com Signed-off-by: Christophe Lyon christophe.lyon@st.com
diff --git a/libm/s_isnan.c b/libm/s_isnan.c index 1bc49cb..1aabb74 100644 --- a/libm/s_isnan.c +++ b/libm/s_isnan.c @@ -26,4 +26,5 @@ int __isnan(double x) hx = 0x7ff00000 - hx; return (int)(((u_int32_t)hx)>>31); } +weak_alias(__isnan, isnan) libm_hidden_def(__isnan)
Hello Christophe,
Thanks for this work on ARM FDPIC support. I'm starting to look at integrating this in Buildroot. However, I have one question below.
On Wed, 4 Jul 2018 17:55:13 +0200, Christophe Lyon wrote:
On ARM, the FDPIC register is r9 [1], and the target name is arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another
The arm-uclinuxfdpiceabi tuple looks weird. Indeed, most architecture tuples have the form:
<arch>-<vendor>-<os>-<libc/abi>
Where the "vendor" part is optional.
However, with arm-uclinuxfdpiceabi there is no dash separating the OS ("uclinux") from the libc/abi part of the tuple.
Is this expected ?
Best regards,
Thomas
On Thu, 5 Jul 2018 at 09:49, Thomas Petazzoni thomas.petazzoni@bootlin.com wrote:
Hello Christophe,
Thanks for this work on ARM FDPIC support. I'm starting to look at integrating this in Buildroot. However, I have one question below.
On Wed, 4 Jul 2018 17:55:13 +0200, Christophe Lyon wrote:
On ARM, the FDPIC register is r9 [1], and the target name is arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another
The arm-uclinuxfdpiceabi tuple looks weird. Indeed, most architecture tuples have the form:
<arch>-<vendor>-<os>-<libc/abi>
Where the "vendor" part is optional.
However, with arm-uclinuxfdpiceabi there is no dash separating the OS ("uclinux") from the libc/abi part of the tuple.
Is this expected ?
Yes, this was discussed when I submitted the binutils patches: https://sourceware.org/ml/binutils/2018-03/msg00324.html
Best regards,
Thomas
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Hello,
On Thu, 5 Jul 2018 10:51:01 +0200, Christophe Lyon wrote:
However, with arm-uclinuxfdpiceabi there is no dash separating the OS ("uclinux") from the libc/abi part of the tuple.
Is this expected ?
Yes, this was discussed when I submitted the binutils patches: https://sourceware.org/ml/binutils/2018-03/msg00324.html
It seems like a strange choice. Why not arm-uclinux-fdpiceabi ? Anyway, I guess this is now fixed in stone :)
Also, side question: do you support both EABI and EABIhf, i.e is arm-uclinuxfdpiceabihf supported ?
Best regards,
Thomas
On Thu, 5 Jul 2018 at 10:57, Thomas Petazzoni thomas.petazzoni@bootlin.com wrote:
Hello,
On Thu, 5 Jul 2018 10:51:01 +0200, Christophe Lyon wrote:
However, with arm-uclinuxfdpiceabi there is no dash separating the OS ("uclinux") from the libc/abi part of the tuple.
Is this expected ?
Yes, this was discussed when I submitted the binutils patches: https://sourceware.org/ml/binutils/2018-03/msg00324.html
It seems like a strange choice. Why not arm-uclinux-fdpiceabi ? Anyway,
I don't know, I trusted Joseph :)
I guess this is now fixed in stone :)
Probably not, there are no official releases yet (but I think the next binutils one will happen very soon)
Also, side question: do you support both EABI and EABIhf, i.e is arm-uclinuxfdpiceabihf supported ?
I didn't test the hf version. But given the nature of the changes, I think it should work. Are you worried about something in particular?
Best regards,
Thomas
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Hi,
I'd like to ping the whole series.
For those anxious about Cortex-M support, I'd prefer to have the current patch series merged, and then add the missing parts for Cortex-M: I have a simple patch to enable the uclibc-ng build for such a target, but then there are further problems with binutils and GCC. So for me it would be much more convenient to have Cortex-A/Cortex-R support merged, so that I can focus later on smaller improvements.
Thanks,
Christophe
On Wed, 4 Jul 2018 at 17:56, Christophe Lyon christophe.lyon@st.com wrote:
Hello,
This patch series implements the uClibc-ng contribution of the FDPIC ABI for ARM targets.
This ABI enables to run Linux on ARM MMU-less cores and supports shared libraries to reduce the memory footprint.
Without MMU, text and data segments relative distances are different from one process to another, hence the need for a dedicated FDPIC register holding the start address of the data segment. One of the side effects is that function pointers require two words to be represented: the address of the code, and the data segment start address. These two words are designated as "Function Descriptor", hence the "FD PIC" name.
On ARM, the FDPIC register is r9 [1], and the target name is arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another ABI and the BFLAT file format; it does not support code sharing.
This work was developed some time ago by STMicroelectronics, and was presented during Linaro Connect SFO15 (September 2015). You can watch the discussion and read the slides [2]. This presentation was related to the toolchain published on github [3], which is based on binutils-2.22, gcc-4.7, uclibc-0.9.33.2, gdb-7.5.1 and qemu-2.3.0, and for which pre-built binaries are available [3].
The ABI itself is described in details in [1].
Our Linux kernel patches have been updated and committed by Nicolas Pitre (Linaro) in July 2017. They are required so that the loader is able to handle this new file type. Indeed, the ELF files are tagged with ELFOSABI_ARM_FDPIC. This new tag has been allocated by ARM, as well as the new relocations involved.
The binutils and QEMU patch series have been merged recently. [4][5]
The GCC patch series has been submitted and is under discussion. [6]
This patch series consists in the original uClibc-based patches, which I have rebased and updated for uClibc-ng. Most of them are strictly related to FDPIC on ARM, while a few others address generic issues.
Are the uClibc-ng patches OK for inclusion in master?
Thanks,
Christophe.
[1] https://github.com/mickael-guene/fdpic_doc/blob/master/abi.txt [2] http://connect.linaro.org/resource/sfo15/sfo15-406-arm-fdpic-toolset-kernel-... [3] https://github.com/mickael-guene/fdpic_manifest [4] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=f1ac0afe... [5] https://git.qemu.org/?p=qemu.git;a=commit;h=e8fa72957419c11984608062c7dcb204... [6] https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01439.html
Christophe Lyon (32): [ARM][FDPIC] Allow to select FDPIC ELF for arm architecture [FDPIC] rtld: Do not protect RELRO segments when we don't use an MMU. [ARM][FDPIC] rtld: Add #if defined (__FDPIC__) [ARM][FDPIC] rtld: Add FDPIC code for arm [ARM][FDPIC] rtld: Avoid FUNCDESC relocation on _start [ARM][FDPIC] rtld: Add startup code [ARM] Fix bug in _dl_pread when using pread64 syscall [ARM][FDPIC] Add application startup code for FDPIC [ARM][FDPIC] Add runtime support needed for C++ exceptions [ARM][FDPIC] Allow to generate PIE 'static' binary [ARM][FDPIC] rtld: Add lazy binding support [ARM][FDPIC] TLS: fix relocation computation [ARM][FDPIC] rtld: Compile with -fno-unwind-tables -fno-asynchronous-unwind-tables [ARM][FDPIC] arm/clone.S: Fix threading support [ARM][FDPIC] enable NPTL on TARGET_arm [ARM][FDPIC] rtld: Use ELF_RTYPE_CLASS_DLSYM [FDPIC] rtld: Initialize _dl_error_catch_tsd without FUNCDESC relocation [FDPIC] nptl: disable mprotect usage in stack protection [FDPIC] nptl: Disable fork and atfork on MMU-less systems. [FDPIC] nptl: Do not use madvise [ARM][FDPIC] nptl: Use linker-defined symbol to find start of .tdata section. [FDPIC] nptl: Allow sem_open to work on MMU-less systems [FDPIC] nptl: Add pthread_mutex_getprioceiling and pthread_mutex_setprioceiling support [FDPIC] nptl: Use vfork on MMU-less for system() nptl: Clear TLS area for static binaries. [FDPIC] nptl: Replace sbrk with mmap nptl threads: Fix bug in using a weak variable. Fix htab_delete loop counter isnan: Add isnan weak alias to __isnan mbtowc: Fix non compliant behavior for end of string Fix shm_open posix compliance error code [ARM] rtld: Avoid crash on R_ARM_NONE relocation
extra/Configs/Config.in | 2 +- extra/Configs/Config.in.arch | 2 +- include/elf.h | 2 + include/link.h | 6 +- ldso/include/dl-elf.h | 2 +- ldso/include/dl-hash.h | 2 +- ldso/include/dl-string.h | 3 +- ldso/include/dl-syscall.h | 13 +- ldso/include/inline-hashtab.h | 2 +- ldso/ldso/Makefile.in | 2 - ldso/ldso/arm/dl-inlines.h | 1 + ldso/ldso/arm/dl-startup.h | 112 +++++++++++++- ldso/ldso/arm/dl-sysdep.h | 63 ++++++-- ldso/ldso/arm/elfinterp.c | 166 +++++++++++++++++---- ldso/ldso/arm/resolve.S | 23 +++ ldso/ldso/dl-elf.c | 6 +- ldso/ldso/dl-hash.c | 4 +- ldso/ldso/dl-tls.c | 1 + ldso/ldso/fdpic/dl-inlines.h | 2 + ldso/ldso/fdpic/dl-sysdep.h | 2 +- ldso/ldso/ldso.c | 23 ++- libc/misc/elf/dl-iterate-phdr.c | 2 +- libc/misc/internals/__uClibc_main.c | 47 +++++- libc/stdlib/stdlib.c | 6 +- libc/stdlib/system.c | 5 + libc/sysdeps/linux/arm/Makefile.arch | 2 +- libc/sysdeps/linux/arm/bits/elf-fdpic.h | 114 ++++++++++++++ libc/sysdeps/linux/arm/clone.S | 12 ++ libc/sysdeps/linux/arm/crt1.S | 66 ++++++++ libc/sysdeps/linux/arm/crtreloc.c | 144 ++++++++++++++++++ libc/sysdeps/linux/arm/find_exidx.c | 38 +++++ libc/sysdeps/linux/arm/find_got.c | 72 +++++++++ libm/s_isnan.c | 1 + libpthread/nptl/Makefile.in | 1 - libpthread/nptl/allocatestack.c | 6 + libpthread/nptl/linux_fsinfo.h | 5 +- libpthread/nptl/pthread_create.c | 4 + libpthread/nptl/sem_open.c | 8 +- libpthread/nptl/sysdeps/generic/libc-tls.c | 27 +++- libpthread/nptl/sysdeps/unix/sysv/linux/fork.c | 3 + .../sysdeps/unix/sysv/linux/libc_pthread_init.c | 4 + .../nptl/sysdeps/unix/sysv/linux/register-atfork.c | 14 +- .../sysdeps/unix/sysv/linux/unregister-atfork.c | 10 +- librt/shm.c | 3 + 44 files changed, 958 insertions(+), 75 deletions(-) create mode 100644 ldso/ldso/arm/dl-inlines.h create mode 100644 libc/sysdeps/linux/arm/bits/elf-fdpic.h create mode 100644 libc/sysdeps/linux/arm/crtreloc.c create mode 100644 libc/sysdeps/linux/arm/find_got.c
-- 2.6.3
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
best regards Waldemar
Am 13.07.2018 um 17:43 schrieb Christophe Lyon christophe.lyon@linaro.org:
Hi,
I'd like to ping the whole series.
For those anxious about Cortex-M support, I'd prefer to have the current patch series merged, and then add the missing parts for Cortex-M: I have a simple patch to enable the uclibc-ng build for such a target, but then there are further problems with binutils and GCC. So for me it would be much more convenient to have Cortex-A/Cortex-R support merged, so that I can focus later on smaller improvements.
Thanks,
Christophe
On Wed, 4 Jul 2018 at 17:56, Christophe Lyon christophe.lyon@st.com wrote:
Hello,
This patch series implements the uClibc-ng contribution of the FDPIC ABI for ARM targets.
This ABI enables to run Linux on ARM MMU-less cores and supports shared libraries to reduce the memory footprint.
Without MMU, text and data segments relative distances are different from one process to another, hence the need for a dedicated FDPIC register holding the start address of the data segment. One of the side effects is that function pointers require two words to be represented: the address of the code, and the data segment start address. These two words are designated as "Function Descriptor", hence the "FD PIC" name.
On ARM, the FDPIC register is r9 [1], and the target name is arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another ABI and the BFLAT file format; it does not support code sharing.
This work was developed some time ago by STMicroelectronics, and was presented during Linaro Connect SFO15 (September 2015). You can watch the discussion and read the slides [2]. This presentation was related to the toolchain published on github [3], which is based on binutils-2.22, gcc-4.7, uclibc-0.9.33.2, gdb-7.5.1 and qemu-2.3.0, and for which pre-built binaries are available [3].
The ABI itself is described in details in [1].
Our Linux kernel patches have been updated and committed by Nicolas Pitre (Linaro) in July 2017. They are required so that the loader is able to handle this new file type. Indeed, the ELF files are tagged with ELFOSABI_ARM_FDPIC. This new tag has been allocated by ARM, as well as the new relocations involved.
The binutils and QEMU patch series have been merged recently. [4][5]
The GCC patch series has been submitted and is under discussion. [6]
This patch series consists in the original uClibc-based patches, which I have rebased and updated for uClibc-ng. Most of them are strictly related to FDPIC on ARM, while a few others address generic issues.
Are the uClibc-ng patches OK for inclusion in master?
Thanks,
Christophe.
Hi Christophe, Waldemar Brodkorb wrote,
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
best regards Waldemar
On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi Christophe, Waldemar Brodkorb wrote,
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
I am on holidays atm, so I may not respond timely for a while.
Thanks,
Christophe
best regards Waldemar
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi Christophe, Waldemar Brodkorb wrote,
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
I am on holidays atm, so I may not respond timely for a while.
Okay, thanks for the info.
best regards Waldemar
On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi Christophe, Waldemar Brodkorb wrote,
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
OK, here is an updated version of the previous patch.
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
I am on holidays atm, so I may not respond timely for a while.
Okay, thanks for the info.
best regards Waldemar
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi Christophe, Waldemar Brodkorb wrote,
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones). You can do on a failure: cd openadk make v
best regards Waldemar
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi Christophe, Waldemar Brodkorb wrote,
Hi Christophe,
i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones).
OK... I use git trees for binutils, gcc and linux ;(
You can do on a failure: cd openadk make v
best regards Waldemar
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
Will you sent a complete patch with sob for the previous error?
best regards
Waldemar
Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi Christophe, Waldemar Brodkorb wrote,
> Hi Christophe, > > i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >
ARM v5 soft eabi arm mode fails to compile, see the attached error log. You can check with embedded-test.sh if you like.
Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones).
OK... I use git trees for binutils, gcc and linux ;(
You can do on a failure: cd openadk make v
best regards Waldemar
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is arm-uclinuxfdpiceabi. This will configure GCC is the right mode, no need to use flags such as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi, Christophe Lyon wrote,
> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: > > Hi Christophe, > Waldemar Brodkorb wrote, > >> Hi Christophe, >> >> i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >> > > ARM v5 soft eabi arm mode fails to compile, see the attached error > log. You can check with embedded-test.sh if you like. > > Any idea? All patches appliend on top of master,
Thanks for testing this configuration.
I left FDPIC-only code activated unconditionally.
Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
I have an embedded-test.sh build running now. Sorry, I didn't know about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones).
OK... I use git trees for binutils, gcc and linux ;(
You can do on a failure: cd openadk make v
best regards Waldemar
Hi,
sorry for the confusion. I take care about the last failure. The build runs further so, I give you feedback once it is finished.
I can squash the patch before pushing,
best regards Waldemar
Am 20.07.2018 um 10:06 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is arm-uclinuxfdpiceabi. This will configure GCC is the right mode, no need to use flags such as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote:
Hi, Christophe Lyon wrote,
On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi, Christophe Lyon wrote,
>> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >> >> Hi Christophe, >> Waldemar Brodkorb wrote, >> >>> Hi Christophe, >>> >>> i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >>> >> >> ARM v5 soft eabi arm mode fails to compile, see the attached error >> log. You can check with embedded-test.sh if you like. >> >> Any idea? All patches appliend on top of master, > > Thanks for testing this configuration. > > I left FDPIC-only code activated unconditionally. > > Can you try the attached small patch?
Even fixing this small typo in #endf it errors out.
OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
> I have an embedded-test.sh build running now. Sorry, I didn't know > about this script, I have used armv5 as arch, is it the one you meant?
somthing like this, uclibc-ng is a directory including all patches: mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones).
OK... I use git trees for binutils, gcc and linux ;(
You can do on a failure: cd openadk make v
best regards Waldemar
Hi,
the toolchain tests are finished successfully, but the armv5 runtime tests showing some problems with getty and argv handling.
Can be seen with --test=libc in embedded-test.sh.
So there is still some regression for arm and ELF.
Any idea?
best regards Waldemar
Am 20.07.2018 um 10:25 schrieb Waldemar Brodkorb wbx@uclibc-ng.org:
Hi,
sorry for the confusion. I take care about the last failure. The build runs further so, I give you feedback once it is finished.
I can squash the patch before pushing,
best regards Waldemar
Am 20.07.2018 um 10:06 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is arm-uclinuxfdpiceabi. This will configure GCC is the right mode, no need to use flags such as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote:
Hi, Christophe Lyon wrote,
> On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: > > Hi, > Christophe Lyon wrote, > >>> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >>> >>> Hi Christophe, >>> Waldemar Brodkorb wrote, >>> >>>> Hi Christophe, >>>> >>>> i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >>>> >>> >>> ARM v5 soft eabi arm mode fails to compile, see the attached error >>> log. You can check with embedded-test.sh if you like. >>> >>> Any idea? All patches appliend on top of master, >> >> Thanks for testing this configuration. >> >> I left FDPIC-only code activated unconditionally. >> >> Can you try the attached small patch? > > Even fixing this small typo in #endf it errors out. > OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
>> I have an embedded-test.sh build running now. Sorry, I didn't know >> about this script, I have used armv5 as arch, is it the one you meant? > > somthing like this, uclibc-ng is a directory including all patches: > mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose
Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones).
OK... I use git trees for binutils, gcc and linux ;(
You can do on a failure: cd openadk make v
best regards Waldemar
devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
On Wed, 25 Jul 2018 at 07:20, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
the toolchain tests are finished successfully, but the armv5 runtime tests showing some problems with getty and argv handling.
Can be seen with --test=libc in embedded-test.sh.
It looks like tests are looping with getty error messages, is that what you saw?
So there is still some regression for arm and ELF.
Any idea?
Not yet.
How can I run embedded-test.sh twice with different uclibc-ng version? (the original one, and the one with my patches) Should I restart from a new directory?
best regards Waldemar
Am 20.07.2018 um 10:25 schrieb Waldemar Brodkorb wbx@uclibc-ng.org:
Hi,
sorry for the confusion. I take care about the last failure. The build runs further so, I give you feedback once it is finished.
I can squash the patch before pushing,
best regards Waldemar
Am 20.07.2018 um 10:06 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is arm-uclinuxfdpiceabi. This will configure GCC is the right mode, no need to use flags such as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote:
Hi, Christophe Lyon wrote,
>> On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >> >> Hi, >> Christophe Lyon wrote, >> >>>> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >>>> >>>> Hi Christophe, >>>> Waldemar Brodkorb wrote, >>>> >>>>> Hi Christophe, >>>>> >>>>> i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >>>>> >>>> >>>> ARM v5 soft eabi arm mode fails to compile, see the attached error >>>> log. You can check with embedded-test.sh if you like. >>>> >>>> Any idea? All patches appliend on top of master, >>> >>> Thanks for testing this configuration. >>> >>> I left FDPIC-only code activated unconditionally. >>> >>> Can you try the attached small patch? >> >> Even fixing this small typo in #endf it errors out. >> > OK, here is an updated version of the previous patch.
Works for the ldso, but I think we need a symbol to differentiate between ELF and FDPIC. See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
>>> I have an embedded-test.sh build running now. Sorry, I didn't know >>> about this script, I have used armv5 as arch, is it the one you meant? >> >> somthing like this, uclibc-ng is a directory including all patches: >> mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose > > Is there a way to avoid (re)creating all the source tarballs? It's taking ages
It only recreates uclibc-ng tarball. (or any git ones).
OK... I use git trees for binutils, gcc and linux ;(
You can do on a failure: cd openadk make v
best regards Waldemar
devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
Hi,
Am 30.07.2018 um 15:50 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Wed, 25 Jul 2018 at 07:20, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
the toolchain tests are finished successfully, but the armv5 runtime tests showing some problems with getty and argv handling.
Can be seen with --test=libc in embedded-test.sh.
It looks like tests are looping with getty error messages, is that what you saw?
Yes.
So there is still some regression for arm and ELF.
Any idea?
Not yet.
How can I run embedded-test.sh twice with different uclibc-ng version? (the original one, and the one with my patches) Should I restart from a new directory?
exactly.
best regards Waldemar
best regards Waldemar
Am 20.07.2018 um 10:25 schrieb Waldemar Brodkorb wbx@uclibc-ng.org:
Hi,
sorry for the confusion. I take care about the last failure. The build runs further so, I give you feedback once it is finished.
I can squash the patch before pushing,
best regards Waldemar
Am 20.07.2018 um 10:06 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is arm-uclinuxfdpiceabi. This will configure GCC is the right mode, no need to use flags such as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb mail@waldemar-brodkorb.de wrote: > > Hi, > Christophe Lyon wrote, > >>> On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >>> >>> Hi, >>> Christophe Lyon wrote, >>> >>>>> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >>>>> >>>>> Hi Christophe, >>>>> Waldemar Brodkorb wrote, >>>>> >>>>>> Hi Christophe, >>>>>> >>>>>> i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >>>>>> >>>>> >>>>> ARM v5 soft eabi arm mode fails to compile, see the attached error >>>>> log. You can check with embedded-test.sh if you like. >>>>> >>>>> Any idea? All patches appliend on top of master, >>>> >>>> Thanks for testing this configuration. >>>> >>>> I left FDPIC-only code activated unconditionally. >>>> >>>> Can you try the attached small patch? >>> >>> Even fixing this small typo in #endf it errors out. >>> >> OK, here is an updated version of the previous patch. > > Works for the ldso, but I think we need a symbol to differentiate > between ELF and FDPIC. > See attached error.
Strange, the build succeeded for me. I don't understand where this -mfdpic option comes from? It is not part of the patches I sent, unless I'm mistaken: it would be "embedded" in GCC if configured for FDPIC, which is not the case in this build for armv5.
> >>>> I have an embedded-test.sh build running now. Sorry, I didn't know >>>> about this script, I have used armv5 as arch, is it the one you meant? >>> >>> somthing like this, uclibc-ng is a directory including all patches: >>> mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose >> >> Is there a way to avoid (re)creating all the source tarballs? It's taking ages > > It only recreates uclibc-ng tarball. (or any git ones). OK... I use git trees for binutils, gcc and linux ;(
> You can do on a failure: > cd openadk > make v > > best regards > Waldemar
devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
On Tue, 31 Jul 2018 at 14:58, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
Am 30.07.2018 um 15:50 schrieb Christophe Lyon <
christophe.lyon@linaro.org>:
On Wed, 25 Jul 2018 at 07:20, Waldemar Brodkorb wbx@uclibc-ng.org
wrote:
Hi,
the toolchain tests are finished successfully, but the armv5 runtime
tests showing some problems with getty and argv handling.
Can be seen with --test=libc in embedded-test.sh.
It looks like tests are looping with getty error messages, is that what
you saw?
Yes.
So there is still some regression for arm and ELF.
Any idea?
Not yet.
How can I run embedded-test.sh twice with different uclibc-ng version? (the original one, and the one with my patches) Should I restart from a new directory?
exactly.
Too bad, It's taking ages to regenerate the gcc and linux tarballs from
the git trees I provide (I saw tar+xz taking ~30 minutes during a 50 minutes full run of the script)
I wish I could run: embedded-test.sh --libc=uclibc-ng --os=linux --arch=armv5 --gcc-source=XXX --binutils-source=YYY --kernel-source=ZZZ --test=libc embedded-test.sh --libc=uclibc-ng --os=linux --arch=armv5 --libc-source=UUU --libc-version=fdpic --gcc-source=XXX --binutils-source=YYY --kernel-source=ZZZ --verbose --test=libc where the 2nd step would only build the new version of uclibc-ng and run the corresponding tests.
best regards Waldemar
best regards Waldemar
Am 20.07.2018 um 10:25 schrieb Waldemar Brodkorb wbx@uclibc-ng.org:
Hi,
sorry for the confusion. I take care about the last failure. The build runs further so, I give you feedback once it is finished.
I can squash the patch before pushing,
best regards Waldemar
Am 20.07.2018 um 10:06 schrieb Christophe Lyon <
christophe.lyon@linaro.org>:
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org
wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is
fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your
script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is
arm-uclinuxfdpiceabi.
This will configure GCC is the right mode, no need to use flags such
as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
> Am 19.07.2018 um 18:31 schrieb Christophe Lyon <
christophe.lyon@linaro.org>:
> > On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb > mail@waldemar-brodkorb.de wrote: >> >> Hi, >> Christophe Lyon wrote, >> >>>> On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb <
wbx@uclibc-ng.org> wrote:
>>>> >>>> Hi, >>>> Christophe Lyon wrote, >>>> >>>>>> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb <
wbx@uclibc-ng.org> wrote:
>>>>>> >>>>>> Hi Christophe, >>>>>> Waldemar Brodkorb wrote, >>>>>> >>>>>>> Hi Christophe, >>>>>>> >>>>>>> i am doing a large testrun for the global changes and
hopefully push on monday or at least have some news. i am afk atm with just little access to a computer.
>>>>>>> >>>>>> >>>>>> ARM v5 soft eabi arm mode fails to compile, see the attached
error
>>>>>> log. You can check with embedded-test.sh if you like. >>>>>> >>>>>> Any idea? All patches appliend on top of master, >>>>> >>>>> Thanks for testing this configuration. >>>>> >>>>> I left FDPIC-only code activated unconditionally. >>>>> >>>>> Can you try the attached small patch? >>>> >>>> Even fixing this small typo in #endf it errors out. >>>> >>> OK, here is an updated version of the previous patch. >> >> Works for the ldso, but I think we need a symbol to differentiate >> between ELF and FDPIC. >> See attached error. > > Strange, the build succeeded for me. I don't understand where this > -mfdpic option comes from? > It is not part of the patches I sent, unless I'm mistaken: it would
be
> "embedded" in GCC if configured for FDPIC, which is not the case in > this build for armv5. > > >> >>>>> I have an embedded-test.sh build running now. Sorry, I didn't
know
>>>>> about this script, I have used armv5 as arch, is it the one you
meant?
>>>> >>>> somthing like this, uclibc-ng is a directory including all
patches:
>>>> mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng
--arch=armv5 --verbose
>>> >>> Is there a way to avoid (re)creating all the source tarballs?
It's taking ages
>> >> It only recreates uclibc-ng tarball. (or any git ones). > OK... I use git trees for binutils, gcc and linux ;( > >> You can do on a failure: >> cd openadk >> make v >> >> best regards >> Waldemar >
devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
On 31/07/2018 14:58, Waldemar Brodkorb wrote:
Hi,
Am 30.07.2018 um 15:50 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Wed, 25 Jul 2018 at 07:20, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
the toolchain tests are finished successfully, but the armv5 runtime tests showing some problems with getty and argv handling.
Can be seen with --test=libc in embedded-test.sh.
It looks like tests are looping with getty error messages, is that what you saw?
Yes.
I have just posted version 2 of patches 4, 8 and 11. I fixed them in such a way that they do not introduce regressions when FDPIC is not activated (embedded-test.sh --arch=armv5)
I guess the next step would be to add a new configuration to embedded-test.sh/openadk, such as "armv7_fdpic" that would exercise FDPIC in ARM mode. As mentioned earlier, this requires recent binutils, GCC trunk+patches and using the right target name: arm-uclinuxfdpiceabi
How easy is it to add such a config in openadk?
Thanks,
Christophe
So there is still some regression for arm and ELF.
Any idea?
Not yet.
How can I run embedded-test.sh twice with different uclibc-ng version? (the original one, and the one with my patches) Should I restart from a new directory?
exactly.
best regards Waldemar
best regards Waldemar
Am 20.07.2018 um 10:25 schrieb Waldemar Brodkorb wbx@uclibc-ng.org:
Hi,
sorry for the confusion. I take care about the last failure. The build runs further so, I give you feedback once it is finished.
I can squash the patch before pushing,
best regards Waldemar
Am 20.07.2018 um 10:06 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Thu, 19 Jul 2018 at 20:15, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
okay, that was already the next test armv5-nommu-arm, which OpenADK needs to learn, as the default is fdpic now.
I'm not sure to understand; if by "now" you mean with my uclibc-ng patch series, then no. At least not yet. As said in the cover letter this patch series supports only armv7. And as noticed by Thomas, it doesn't yet support armv7m. The plan is definitely to support armv7m.
So you probably want to create a new config armv7-nommu-arm in your script.
Since I'm not familiar with this script nor openadk, I don't know what this implies.
I thought you wanted to first make sure my uclibc-ng patch series didn't break existing configs.
If you want to try fdpic mode, you'll need a recent GCC trunk + my GCC patches (see link in cover letter). You also need recent binutils. I don't know if/how your script handles that since I noticed "7.3.0" in the GCC error messages you shared, which seems to indicate you are not using the most recent GCC.
And also note that the GCC/binutils target name is arm-uclinuxfdpiceabi. This will configure GCC is the right mode, no need to use flags such as -mfdpic.
Will you sent a complete patch with sob for the previous error?
Which previous error? If you mean the latest you reported involving -mfdpic, then I hope my answer just above clarifies.
If you mean the broken armv5 build, then yes, but the patch I sent recently only needs to be squashed with patch 4/32 "rtld: Add FDPIC code for arm"
What the practice on this list? Shall I send v2 of patch 4/32 asap, on rather wait for feedback on other patches and then send a v2 of the whole series?
Thanks,
Christophe
best regards
Waldemar
> Am 19.07.2018 um 18:31 schrieb Christophe Lyon christophe.lyon@linaro.org: > > On Thu, 19 Jul 2018 at 14:33, Waldemar Brodkorb > mail@waldemar-brodkorb.de wrote: >> Hi, >> Christophe Lyon wrote, >> >>>> On Wed, 18 Jul 2018 at 18:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >>>> >>>> Hi, >>>> Christophe Lyon wrote, >>>> >>>>>> On Wed, 18 Jul 2018 at 09:37, Waldemar Brodkorb wbx@uclibc-ng.org wrote: >>>>>> >>>>>> Hi Christophe, >>>>>> Waldemar Brodkorb wrote, >>>>>> >>>>>>> Hi Christophe, >>>>>>> >>>>>>> i am doing a large testrun for the global changes and hopefully push on monday or at least have some news. i am afk atm with just little access to a computer. >>>>>>> >>>>>> ARM v5 soft eabi arm mode fails to compile, see the attached error >>>>>> log. You can check with embedded-test.sh if you like. >>>>>> >>>>>> Any idea? All patches appliend on top of master, >>>>> Thanks for testing this configuration. >>>>> >>>>> I left FDPIC-only code activated unconditionally. >>>>> >>>>> Can you try the attached small patch? >>>> Even fixing this small typo in #endf it errors out. >>>> >>> OK, here is an updated version of the previous patch. >> Works for the ldso, but I think we need a symbol to differentiate >> between ELF and FDPIC. >> See attached error. > Strange, the build succeeded for me. I don't understand where this > -mfdpic option comes from? > It is not part of the patches I sent, unless I'm mistaken: it would be > "embedded" in GCC if configured for FDPIC, which is not the case in > this build for armv5. > > >>>>> I have an embedded-test.sh build running now. Sorry, I didn't know >>>>> about this script, I have used armv5 as arch, is it the one you meant? >>>> somthing like this, uclibc-ng is a directory including all patches: >>>> mksh embedded-test.sh --libc=uclibc-ng --libc-source=uclibc-ng --arch=armv5 --verbose >>> Is there a way to avoid (re)creating all the source tarballs? It's taking ages >> It only recreates uclibc-ng tarball. (or any git ones). > OK... I use git trees for binutils, gcc and linux ;( > >> You can do on a failure: >> cd openadk >> make v >> >> best regards >> Waldemar
devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
Hi, Christophe Lyon wrote,
On 31/07/2018 14:58, Waldemar Brodkorb wrote:
Hi,
Am 30.07.2018 um 15:50 schrieb Christophe Lyon christophe.lyon@linaro.org:
On Wed, 25 Jul 2018 at 07:20, Waldemar Brodkorb wbx@uclibc-ng.org wrote:
Hi,
the toolchain tests are finished successfully, but the armv5 runtime tests showing some problems with getty and argv handling.
Can be seen with --test=libc in embedded-test.sh.
It looks like tests are looping with getty error messages, is that what you saw?
Yes.
I have just posted version 2 of patches 4, 8 and 11. I fixed them in such a way that they do not introduce regressions when FDPIC is not activated (embedded-test.sh --arch=armv5)
I guess the next step would be to add a new configuration to embedded-test.sh/openadk, such as "armv7_fdpic" that would exercise FDPIC in ARM mode. As mentioned earlier, this requires recent binutils, GCC trunk+patches and using the right target name: arm-uclinuxfdpiceabi
How easy is it to add such a config in openadk?
Depends, I will start adding something like that, so you can concentrate in gcc upstreaming.
The patch series is pushed, thanks.
Waldemar