[PATCH] pch: Add support for PCH for relocatable executables

Jakub Jelinek jakub@redhat.com
Tue Nov 9 09:50:19 GMT 2021

On Mon, Nov 08, 2021 at 04:03:09PM -0500, John David Anglin wrote:
> On 2021-11-08 2:48 p.m., Jakub Jelinek wrote:
> > Not really sure about PA or IA-64 function descriptors, are any of those
> > allocated by the dynamic linker rather than created by the static linker?
> On PA, the static linker creates all function descriptors.  The dynamic linker is responsible for
> resolving descriptors when lazy binding is used.
> The primary difference between 32 and 64-bit descriptors is that there can be multiple descriptors
> that resolve to the same function in the 32-bit run time.  In the 64-bit case, there is one official
> procedure descriptor for each function.

What I (or the PCH patch I've posted) cares about is if one does:
int foo () { return 1; }
int bar () { return 2; }
int v1, v2;
main ()
  __builtin_printf ("%p %p %p %p\n", (void *) &foo, (void *) &bar, &v1, &v2);
  return 0;
whether either the addresses are always the same (non-relocatable binary),
or they differ, but the differences between say the first address and the
other addresses are the same all the time (i.e. if one does what the patch
is doing,
+  if (pch_save != &gt_pch_save)
+    {
+      uintptr_t bias = (uintptr_t) &gt_pch_save - (uintptr_t) pch_save;
+      void **ptrs = XNEWVEC (void *, num_callbacks);
+      unsigned i;
+      if (fread (ptrs, sizeof (void *), num_callbacks, f) != num_callbacks)
+       fatal_error (input_location, "cannot read PCH file: %m");
+      for (i = 0; i < num_callbacks; ++i)
+       {
+         memcpy (&pch_save, ptrs[i], sizeof (pch_save));
+         pch_save = (void (*) (FILE *)) ((uintptr_t) pch_save + bias);
+         memcpy (ptrs[i], &pch_save, sizeof (pch_save));
+       }
+      XDELETE (ptrs);
+    }
whether it will work correctly.
If there are any hosts where it wouldn't, we'd need to disable PCH or at
least PCH with different load bias on such host.


More information about the Gcc-patches mailing list