Discussion:
Silent relocation truncations considered harmful
Mark Geisert
2016-02-16 02:23:30 UTC
Permalink
This follows up from my msg re GMP-ECM failing its 'make check' on the
main list https://cygwin.com/ml/cygwin/2016-02/msg00147.html .

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 pseudo-reloc.cc.safe pseudo-reloc.cc
--- pseudo-reloc.cc.safe 2016-01-26 20:08:06.000000000 -0800
+++ pseudo-reloc.cc 2016-02-15 17:54:20.475963800 -0800
@@ -342,7 +342,7 @@
__write_memory ((void *) reloc_target, &reldata, 2);
break;
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.

..mark
Corinna Vinschen
2016-02-16 16:29:33 UTC
Permalink
Hi Mark,
This follows up from my msg re GMP-ECM failing its 'make check' on the main
list https://cygwin.com/ml/cygwin/2016-02/msg00147.html .
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,
/oss/src/winsup/cygwin diff -u pseudo-reloc.cc.safe pseudo-reloc.cc
--- pseudo-reloc.cc.safe 2016-01-26 20:08:06.000000000 -0800
+++ pseudo-reloc.cc 2016-02-15 17:54:20.475963800 -0800
@@ -342,7 +342,7 @@
__write_memory ((void *) reloc_target, &reldata, 2);
break;
-#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.
Patch is ok, but it doesn't apply cleanly. Can you please send the
patch as created by `git format-patch' or at least in git diff format?


Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Mark Geisert
2016-02-16 19:53:12 UTC
Permalink
Sorry for the wrong patch format. That was intended for discussion only :).
I've appended a 'git diff' for the update.

..mark

diff --git a/winsup/cygwin/pseudo-reloc.cc b/winsup/cygwin/pseudo-reloc.cc
index f374d22..c250fdc 100644
--- a/winsup/cygwin/pseudo-reloc.cc
+++ b/winsup/cygwin/pseudo-reloc.cc
@@ -342,7 +342,7 @@ do_pseudo_reloc (void * start, void * end, void * base)
__write_memory ((void *) reloc_target, &reldata, 2);
break;
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 "
Corinna Vinschen
2016-02-17 09:59:51 UTC
Permalink
Hi Mark,
Post by Mark Geisert
Sorry for the wrong patch format. That was intended for discussion only :).
I've appended a 'git diff' for the update.
..mark
diff --git a/winsup/cygwin/pseudo-reloc.cc b/winsup/cygwin/pseudo-reloc.cc
index f374d22..c250fdc 100644
--- a/winsup/cygwin/pseudo-reloc.cc
+++ b/winsup/cygwin/pseudo-reloc.cc
@@ -342,7 +342,7 @@ do_pseudo_reloc (void * start, void * end, void * base)
__write_memory ((void *) reloc_target, &reldata, 2);
break;
-#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 "
Thanks, but this patch still doesn't apply. The problem is that the
white spaces are wrong. Did your mailer convert TABs to spaces or is
that a copy/paste problem?

To avoid that problem, I suggest to commit your patch to a local
branch, create a patch file using `git format-patch' and attach it
to your mail. That should work all the time (and allows the lazy
maintainer to apply the patch with a simple `git am' call ;))

Never mind that for this patch. I applied it manually.


Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Loading...