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