b1dca6
commit 647103ea3a2aae2e6791b3bebe9e33eedc168102
b1dca6
Author: Florian Weimer <fweimer@redhat.com>
b1dca6
Date:   Fri Oct 9 10:13:14 2020 +0200
b1dca6
b1dca6
    elf: Enhance ld.so --help to print HWCAP subdirectories
b1dca6
    
b1dca6
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
b1dca6
b1dca6
diff --git a/elf/dl-usage.c b/elf/dl-usage.c
b1dca6
index 8d39bc9d5442bc59..c07f43835bd771cf 100644
b1dca6
--- a/elf/dl-usage.c
b1dca6
+++ b/elf/dl-usage.c
b1dca6
@@ -22,6 +22,8 @@
b1dca6
 #include <unistd.h>
b1dca6
 #include "version.h"
b1dca6
 
b1dca6
+#include <dl-hwcaps.h>
b1dca6
+
b1dca6
 void
b1dca6
 _dl_usage (const char *argv0, const char *wrong_option)
b1dca6
 {
b1dca6
@@ -101,6 +103,65 @@ print_search_path_for_help (struct dl_main_state *state)
b1dca6
   print_search_path_for_help_1 (__rtld_search_dirs.dirs);
b1dca6
 }
b1dca6
 
b1dca6
+/* Helper function for printing flags associated with a HWCAP name.  */
b1dca6
+static void
b1dca6
+print_hwcap_1 (bool *first, bool active, const char *label)
b1dca6
+{
b1dca6
+  if (active)
b1dca6
+    {
b1dca6
+      if (*first)
b1dca6
+        {
b1dca6
+          _dl_printf (" (");
b1dca6
+          *first = false;
b1dca6
+        }
b1dca6
+      else
b1dca6
+        _dl_printf (", ");
b1dca6
+      _dl_printf ("%s", label);
b1dca6
+    }
b1dca6
+}
b1dca6
+
b1dca6
+/* Called after a series of print_hwcap_1 calls to emit the line
b1dca6
+   terminator.  */
b1dca6
+static void
b1dca6
+print_hwcap_1_finish (bool *first)
b1dca6
+{
b1dca6
+  if (*first)
b1dca6
+    _dl_printf ("\n");
b1dca6
+  else
b1dca6
+    _dl_printf (")\n");
b1dca6
+}
b1dca6
+
b1dca6
+/* Write a list of hwcap subdirectories to standard output.  See
b1dca6
+ _dl_important_hwcaps in dl-hwcaps.c.  */
b1dca6
+static void
b1dca6
+print_legacy_hwcap_directories (void)
b1dca6
+{
b1dca6
+  _dl_printf ("\n\
b1dca6
+Legacy HWCAP subdirectories under library search path directories:\n");
b1dca6
+
b1dca6
+  const char *platform = GLRO (dl_platform);
b1dca6
+  if (platform != NULL)
b1dca6
+    _dl_printf ("  %s (AT_PLATFORM; supported, searched)\n", platform);
b1dca6
+
b1dca6
+  _dl_printf ("  tls (supported, searched)\n");
b1dca6
+
b1dca6
+  uint64_t hwcap_mask = GET_HWCAP_MASK();
b1dca6
+  uint64_t searched = GLRO (dl_hwcap) & hwcap_mask;
b1dca6
+  for (int n = 63; n >= 0; --n)
b1dca6
+    {
b1dca6
+      uint64_t bit = 1ULL << n;
b1dca6
+      if (HWCAP_IMPORTANT & bit)
b1dca6
+        {
b1dca6
+          _dl_printf ("  %s", _dl_hwcap_string (n));
b1dca6
+          bool first = true;
b1dca6
+          print_hwcap_1 (&first, GLRO (dl_hwcap) & bit, "supported");
b1dca6
+          print_hwcap_1 (&first, !(hwcap_mask & bit), "masked");
b1dca6
+          print_hwcap_1 (&first, searched & bit, "searched");
b1dca6
+          print_hwcap_1_finish (&first);
b1dca6
+        }
b1dca6
+    }
b1dca6
+}
b1dca6
+
b1dca6
 void
b1dca6
 _dl_help (const char *argv0, struct dl_main_state *state)
b1dca6
 {
b1dca6
@@ -136,5 +197,6 @@ This program interpreter self-identifies as: " RTLD "\n\
b1dca6
 ",
b1dca6
               argv0);
b1dca6
   print_search_path_for_help (state);
b1dca6
+  print_legacy_hwcap_directories ();
b1dca6
   _exit (EXIT_SUCCESS);
b1dca6
 }