Silent relocation truncations considered harmful

Mark Geisert
Tue Feb 16 02:23:00 GMT 2016

This follows up from my msg re GMP-ECM failing its 'make check' on the 
main list .

There's an error that ought to be reported during dynamic linking if 
the linked-to address is too far from the relocation site.  However the 
error is not reported if __OPTIMIZE__ was #defined when building the 
Cygwin DLL.  I can't see why optimization settings should affect this,
so I suggest:

/oss/src/winsup/cygwin diff -u
---        2016-01-26 20:08:06.000000000 -0800
+++     2016-02-15 17:54:20.475963800 -0800
@@ -342,7 +342,7 @@
           __write_memory ((void *) reloc_target, &reldata, 2);
         case 32:
-#if defined (__CYGWIN__) && defined (__x86_64__) && !defined (__OPTIMIZE__)
+#if defined (__CYGWIN__) && defined (__x86_64__)
           if (reldata > (ptrdiff_t) __INT32_MAX__
               || reldata < -((ptrdiff_t) __INT32_MAX__) - 1)
             __report_error ("Invalid relocation.  Offset %p at address %p "

If the truncation is not reported here, which kills the program with a 
Cygwin runtime error, you get hard to diagnose SIGSEGVs at some later time 
when the app tries to call a function at an address relocated off in the 
weeds somewhere.


More information about the Cygwin-developers mailing list