[PATCH v9 6/6] elf: Add test for THP alignment of large load segments

Wilco Dijkstra Wilco.Dijkstra@arm.com
Tue Apr 14 16:34:59 GMT 2026


Hi Rui,

See below for a few minor issues (you can just send an updated version of
this patch rather than the whole series - everything else looks good).

+static void
+check_align (void)
+{
+  unsigned long int thp_size = get_thp_size ();
+  enum thp_mode_t thp_mode = get_thp_mode ();
+
+  if (thp_size == 0)
+    {
+      printf ("Skipping test: unable to get THP size.\n");
+      return;
+    }

Since we want to skip, this should use FAIL_UNSUPPORTED instead of printf.

+
+  if (thp_mode != thp_mode_always)
+    {
+      printf ("Skipping test: THP mode is not always.\n");
+      return;
+    }

Same here.

Also I think we should skip if thp_size > 32 * 1024 * 1024 since we won't do
the alignment in that case.

+  FILE *f = xfopen ("/proc/self/maps", "r");
+  char *line = NULL;
+  size_t len;
+
+  while (xgetline (&line, &len, f))
+    {
+      uintptr_t from, to;
+      char *prot = NULL, *path = NULL;
+      int r = sscanf (line, "%" SCNxPTR "-%" SCNxPTR "%ms%*s%*s%*s%ms",
+                      &from, &to, &prot, &path);
+
+      TEST_VERIFY (r == 3 || r == 4);
+
+      if (strstr (prot, "x") && strstr (path, THP_SIZE_MOD_NAME))
+        TEST_COMPARE (from % thp_size, 0);
+
+      free (path);
+    }
+
+  free (line);
+  xfclose (f);
+}
+
+static int
+do_test (void)
+{
+  void *dl;
+
+  dl = xdlopen (THP_SIZE_MOD_NAME, RTLD_NOW);
+  check_align ();
+  xdlclose (dl);
+
+  return 0;
+}

Cheers,
Wilco


More information about the Libc-alpha mailing list