[RFC,01/19] Inhibit early libcalls before ifunc support is ready

Message ID 20230207001618.458947-2-christoph.muellner@vrull.eu
State New
Headers
Series riscv: ifunc support with optimized mem*/str*/cpu_relax routines |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Christoph Müllner Feb. 7, 2023, 12:16 a.m. UTC
  From: Christoph Müllner <christoph.muellner@vrull.eu>

One of the few tasks in __libc_start_main_impl, before
ifunc support is ready on many architectures is to process
the AUX vector. GCC is able to detect libcall routines in
this code, which will result in invocations of uninitialized
ifunc pointers.

Let's set the proper attributes to these early functions
to avoid avoid libcalls.

This was observed to be an issue (endless loop) in combination with:
- GCC upstream/master
- glibc upstream/master
- glibc built with -O3
- target arch RISC-V (RV64)
- experimental RISC-V ifunc support patches
Other combinations/architectures might be affected as well.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
---
 csu/libc-start.c | 1 +
 elf/dl-support.c | 1 +
 2 files changed, 2 insertions(+)
  

Patch

diff --git a/csu/libc-start.c b/csu/libc-start.c
index c3bb6d09bc..8566a54df5 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -231,6 +231,7 @@  STATIC int LIBC_START_MAIN (int (*main) (int, char **, char **
    locate constructors and destructors.  For statically linked
    executables, the relevant symbols are access directly.  */
 STATIC int
+inhibit_loop_to_libcall
 LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
 		 int argc, char **argv,
 #ifdef LIBC_START_MAIN_AUXVEC_ARG
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 9714f75db0..b0e9e1636a 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -242,6 +242,7 @@  __rtld_lock_define_initialized_recursive (, _dl_load_tls_lock)
 int _dl_clktck;
 
 void
+inhibit_loop_to_libcall
 _dl_aux_init (ElfW(auxv_t) *av)
 {
 #ifdef NEED_DL_SYSINFO