]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't assume __secure_getenv is available
authorJanne Blomqvist <jb@gcc.gnu.org>
Fri, 19 May 2017 13:30:45 +0000 (16:30 +0300)
committerJanne Blomqvist <jb@gcc.gnu.org>
Fri, 19 May 2017 13:30:45 +0000 (16:30 +0300)
Glibc 2.17 made __secure_getenv an officially supported function, and
renamed it secure_getenv. The libgfortran configure has checked for
both of these, per
https://sourceware.org/glibc/wiki/Tips_and_Tricks/secure_getenv.

Unfortunately, while the dynamical library (libc.so) retains the
__secure_getenv symbol for backwards compatibility, the static library
(libc.a) does not. This means that a libgfortran.a compiled against an
older glibc will not work if one tries to link against a newer
libc.a. This creates problems for providing gfortran binary
distributions that work on as many target systems as possible.

Thus, retain the support for __secure_getenv but call it only via a
weak reference.

Backported from trunk.

2017-05-19  Janne Blomqvist  <jb@gcc.gnu.org>

* libgfortran.h: HAVE_SECURE_GETENV: Don't check
HAVE___SECURE_GETENV.
* environ/runtime.c (secure_getenv): Use __secure_getenv via a
        weak reference.

From-SVN: r248275

libgfortran/ChangeLog
libgfortran/libgfortran.h
libgfortran/runtime/environ.c

index a0471221cc83c1def71bda4a666b95849d94dccb..472cb1db0460feb994be419d82603a5dad7027ff 100644 (file)
@@ -1,3 +1,11 @@
+2017-05-19  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       Backport from trunk
+       * libgfortran.h: HAVE_SECURE_GETENV: Don't check
+       HAVE___SECURE_GETENV.
+       * environ/runtime.c (secure_getenv): Use __secure_getenv via a
+        weak reference.
+
 2017-01-31  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/79305
index 39e5e4ae6421eb75ee606f97847e8e16250a06f6..d3e99e5c0009655c06ab3e1ba74a6290b9d5365c 100644 (file)
@@ -809,9 +809,7 @@ internal_proto(get_unformatted_convert);
 
 /* Secure getenv() which returns NULL if running as SUID/SGID.  */
 #ifndef HAVE_SECURE_GETENV
-#ifdef HAVE___SECURE_GETENV
-#define secure_getenv __secure_getenv
-#elif defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
+#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
   && defined(HAVE_GETGID) && defined(HAVE_GETEGID)
 #define FALLBACK_SECURE_GETENV
 extern char *secure_getenv (const char *);
index 4f6408f8ef056fd28ad03d572dac59ac9d82c495..6e8b2036471c70d5ac5d7ffe29d133f003d2805b 100644 (file)
@@ -61,9 +61,20 @@ static void init_unformatted (variable *);
 
 
 #ifdef FALLBACK_SECURE_GETENV
+
+#if SUPPORTS_WEAKREF && defined(HAVE___SECURE_GETENV)
+static char* weak_secure_getenv (const char*)
+  __attribute__((__weakref__("__secure_getenv")));
+#endif
+
 char *
 secure_getenv (const char *name)
 {
+#if SUPPORTS_WEAKREF && defined(HAVE___SECURE_GETENV)
+  if (weak_secure_getenv)
+    return weak_secure_getenv (name);
+#endif
+
   if ((getuid () == geteuid ()) && (getgid () == getegid ()))
     return getenv (name);
   else