446cf2
commit dcbc6b83eff5b9238170bdfed834ba934150895f
446cf2
Author: Florian Weimer <fweimer@redhat.com>
446cf2
Date:   Thu May 28 10:20:56 2020 +0200
446cf2
446cf2
    elf: Do not read hwcaps from the vDSO in ld.so
446cf2
    
446cf2
    This was only ever used for the "nosegneg" flag.  This approach for
446cf2
    passing hardware capability information creates a subtle dependency
446cf2
    between the kernel and userspace, and ld.so.cache contents.  It seems
446cf2
    inappropriate for toady, where people expect to be able to run
446cf2
    system images which very different kernel versions.
446cf2
    
446cf2
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
446cf2
446cf2
diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
446cf2
index ecf00b457760e517..ae2e4ca7fe91d407 100644
446cf2
--- a/elf/dl-hwcaps.c
446cf2
+++ b/elf/dl-hwcaps.c
446cf2
@@ -26,12 +26,6 @@
446cf2
 #include <dl-procinfo.h>
446cf2
 #include <dl-hwcaps.h>
446cf2
 
446cf2
-#ifdef _DL_FIRST_PLATFORM
446cf2
-# define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT)
446cf2
-#else
446cf2
-# define _DL_FIRST_EXTRA _DL_HWCAP_COUNT
446cf2
-#endif
446cf2
-
446cf2
 /* Return an array of useful/necessary hardware capability names.  */
446cf2
 const struct r_strlenpair *
446cf2
 _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
446cf2
@@ -52,116 +46,12 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
446cf2
     if ((masked & (1ULL << n)) != 0)
446cf2
       ++cnt;
446cf2
 
446cf2
-#ifdef NEED_DL_SYSINFO_DSO
446cf2
-  /* The system-supplied DSO can contain a note of type 2, vendor "GNU".
446cf2
-     This gives us a list of names to treat as fake hwcap bits.  */
446cf2
-
446cf2
-  const char *dsocaps = NULL;
446cf2
-  size_t dsocapslen = 0;
446cf2
-  if (GLRO(dl_sysinfo_map) != NULL)
446cf2
-    {
446cf2
-      const ElfW(Phdr) *const phdr = GLRO(dl_sysinfo_map)->l_phdr;
446cf2
-      const ElfW(Word) phnum = GLRO(dl_sysinfo_map)->l_phnum;
446cf2
-      for (uint_fast16_t i = 0; i < phnum; ++i)
446cf2
-	if (phdr[i].p_type == PT_NOTE)
446cf2
-	  {
446cf2
-	    const ElfW(Addr) start = (phdr[i].p_vaddr
446cf2
-				      + GLRO(dl_sysinfo_map)->l_addr);
446cf2
-	    /* NB: Some PT_NOTE segment may have alignment value of 0
446cf2
-	       or 1.  gABI specifies that PT_NOTE segments should be
446cf2
-	       aligned to 4 bytes in 32-bit objects and to 8 bytes in
446cf2
-	       64-bit objects.  As a Linux extension, we also support
446cf2
-	       4 byte alignment in 64-bit objects.  If p_align is less
446cf2
-	       than 4, we treate alignment as 4 bytes since some note
446cf2
-	       segments have 0 or 1 byte alignment.   */
446cf2
-	    ElfW(Addr) align = phdr[i].p_align;
446cf2
-	    if (align < 4)
446cf2
-	      align = 4;
446cf2
-	    else if (align != 4 && align != 8)
446cf2
-	      continue;
446cf2
-	    /* The standard ELF note layout is exactly as the anonymous struct.
446cf2
-	       The next element is a variable length vendor name of length
446cf2
-	       VENDORLEN (with a real length rounded to ElfW(Word)), followed
446cf2
-	       by the data of length DATALEN (with a real length rounded to
446cf2
-	       ElfW(Word)).  */
446cf2
-	    const struct
446cf2
-	    {
446cf2
-	      ElfW(Word) vendorlen;
446cf2
-	      ElfW(Word) datalen;
446cf2
-	      ElfW(Word) type;
446cf2
-	    } *note = (const void *) start;
446cf2
-	    while ((ElfW(Addr)) (note + 1) - start < phdr[i].p_memsz)
446cf2
-	      {
446cf2
-		/* The layout of the type 2, vendor "GNU" note is as follows:
446cf2
-		   .long <Number of capabilities enabled by this note>
446cf2
-		   .long <Capabilities mask> (as mask >> _DL_FIRST_EXTRA).
446cf2
-		   .byte <The bit number for the next capability>
446cf2
-		   .asciz <The name of the capability>.  */
446cf2
-		if (note->type == NT_GNU_HWCAP
446cf2
-		    && note->vendorlen == sizeof "GNU"
446cf2
-		    && !memcmp ((note + 1), "GNU", sizeof "GNU")
446cf2
-		    && note->datalen > 2 * sizeof (ElfW(Word)) + 2)
446cf2
-		  {
446cf2
-		    const ElfW(Word) *p
446cf2
-		      = ((const void *) note
446cf2
-			 + ELF_NOTE_DESC_OFFSET (sizeof "GNU", align));
446cf2
-		    cnt += *p++;
446cf2
-		    ++p;	/* Skip mask word.  */
446cf2
-		    dsocaps = (const char *) p; /* Pseudo-string "name"  */
446cf2
-		    dsocapslen = note->datalen - sizeof *p * 2;
446cf2
-		    break;
446cf2
-		  }
446cf2
-		note = ((const void *) note
446cf2
-			+ ELF_NOTE_NEXT_OFFSET (note->vendorlen,
446cf2
-						note->datalen, align));
446cf2
-	      }
446cf2
-	    if (dsocaps != NULL)
446cf2
-	      break;
446cf2
-	  }
446cf2
-    }
446cf2
-#endif
446cf2
-
446cf2
   /* For TLS enabled builds always add 'tls'.  */
446cf2
   ++cnt;
446cf2
 
446cf2
   /* Create temporary data structure to generate result table.  */
446cf2
   struct r_strlenpair temp[cnt];
446cf2
   m = 0;
446cf2
-#ifdef NEED_DL_SYSINFO_DSO
446cf2
-  if (dsocaps != NULL)
446cf2
-    {
446cf2
-      /* dsocaps points to the .asciz string, and -1 points to the mask
446cf2
-         .long just before the string.  */
446cf2
-      const ElfW(Word) mask = ((const ElfW(Word) *) dsocaps)[-1];
446cf2
-      GLRO(dl_hwcap) |= (uint64_t) mask << _DL_FIRST_EXTRA;
446cf2
-      /* Note that we add the dsocaps to the set already chosen by the
446cf2
-	 LD_HWCAP_MASK environment variable (or default HWCAP_IMPORTANT).
446cf2
-	 So there is no way to request ignoring an OS-supplied dsocap
446cf2
-	 string and bit like you can ignore an OS-supplied HWCAP bit.  */
446cf2
-      hwcap_mask |= (uint64_t) mask << _DL_FIRST_EXTRA;
446cf2
-#if HAVE_TUNABLES
446cf2
-      TUNABLE_SET (glibc, cpu, hwcap_mask, uint64_t, hwcap_mask);
446cf2
-#else
446cf2
-      GLRO(dl_hwcap_mask) = hwcap_mask;
446cf2
-#endif
446cf2
-      size_t len;
446cf2
-      for (const char *p = dsocaps; p < dsocaps + dsocapslen; p += len + 1)
446cf2
-	{
446cf2
-	  uint_fast8_t bit = *p++;
446cf2
-	  len = strlen (p);
446cf2
-
446cf2
-	  /* Skip entries that are not enabled in the mask word.  */
446cf2
-	  if (__glibc_likely (mask & ((ElfW(Word)) 1 << bit)))
446cf2
-	    {
446cf2
-	      temp[m].str = p;
446cf2
-	      temp[m].len = len;
446cf2
-	      ++m;
446cf2
-	    }
446cf2
-	  else
446cf2
-	    --cnt;
446cf2
-	}
446cf2
-    }
446cf2
-#endif
446cf2
   for (n = 0; masked != 0; ++n)
446cf2
     if ((masked & (1ULL << n)) != 0)
446cf2
       {