c5d972
Added $(objpfx)tst-dlmopen-gethostbyname: $(libdl) in elf/Makefile since
c5d972
we still have $(libdl) in RHEL8.
c5d972
c5d972
commit c2059edce20c124d1a99f1a94cc52e83b77a917a
c5d972
Author: Florian Weimer <fweimer@redhat.com>
c5d972
Date:   Thu Jun 17 15:06:43 2021 +0200
c5d972
c5d972
    elf: Use _dl_catch_error from base namespace in dl-libc.c [BZ #27646]
c5d972
    
c5d972
    dlerrror_run in elf/dl-libc.c needs to call GLRO (dl_catch_error)
c5d972
    from the base namespace, just like the exported dlerror
c5d972
    implementation.
c5d972
    
c5d972
    Fixes commit b2964eb1d9a6b8ab1250e8a881cf406182da5875 ("dlfcn:
c5d972
    Failures after dlmopen should not terminate process [BZ #24772]").
c5d972
    
c5d972
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
c5d972
c5d972
Conflicts:
c5d972
	elf/Makefile
c5d972
c5d972
diff --git a/elf/Makefile b/elf/Makefile
c5d972
index e0919486a14cab1a..30417c3ce15abcb4 100644
c5d972
--- a/elf/Makefile
c5d972
+++ b/elf/Makefile
c5d972
@@ -217,6 +217,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
c5d972
 	 tst-tls20 tst-tls21 \
c5d972
 	 tst-rtld-run-static \
c5d972
 	 tst-dlmopen-dlerror \
c5d972
+	 tst-dlmopen-gethostbyname \
c5d972
 #	 reldep9
c5d972
 tests-internal += loadtest unload unload2 circleload1 \
c5d972
 	 neededtest neededtest2 neededtest3 neededtest4 \
c5d972
@@ -351,6 +352,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
c5d972
 		libmarkermod5-1 libmarkermod5-2 libmarkermod5-3 libmarkermod5-4 \
c5d972
 		libmarkermod5-5 tst-tls20mod-bad tst-tls21mod \
c5d972
 		tst-dlmopen-dlerror-mod \
c5d972
+		tst-dlmopen-gethostbyname-mod \
c5d972
 
c5d972
 # Most modules build with _ISOMAC defined, but those filtered out
c5d972
 # depend on internal headers.
c5d972
@@ -1935,3 +1937,5 @@ $(objpfx)tst-tls21.out: $(objpfx)tst-tls21mod.so
c5d972
 $(objpfx)tst-tls21mod.so: $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so)
c5d972
 
c5d972
 $(objpfx)tst-rtld-run-static.out: $(objpfx)/ldconfig
c5d972
+$(objpfx)tst-dlmopen-gethostbyname: $(libdl)
c5d972
+$(objpfx)tst-dlmopen-gethostbyname.out: $(objpfx)tst-dlmopen-gethostbyname-mod.so
c5d972
diff --git a/elf/dl-libc.c b/elf/dl-libc.c
c5d972
index fc01f5514d4f656c..3a242d219756dac6 100644
c5d972
--- a/elf/dl-libc.c
c5d972
+++ b/elf/dl-libc.c
c5d972
@@ -43,8 +43,8 @@ dlerror_run (void (*operate) (void *), void *args)
c5d972
   const char *last_errstring = NULL;
c5d972
   bool malloced;
c5d972
 
c5d972
-  int result = (_dl_catch_error (&objname, &last_errstring, &malloced,
c5d972
-				operate, args)
c5d972
+  int result = (GLRO (dl_catch_error) (&objname, &last_errstring, &malloced,
c5d972
+				       operate, args)
c5d972
 		?: last_errstring != NULL);
c5d972
 
c5d972
   if (result && malloced)
c5d972
diff --git a/elf/tst-dlmopen-gethostbyname-mod.c b/elf/tst-dlmopen-gethostbyname-mod.c
c5d972
new file mode 100644
c5d972
index 0000000000000000..9a68ea5050c3060b
c5d972
--- /dev/null
c5d972
+++ b/elf/tst-dlmopen-gethostbyname-mod.c
c5d972
@@ -0,0 +1,29 @@
c5d972
+/* Exercise dlerror_run in elf/dl-libc.c after dlmopen, via NSS.  Helper module.
c5d972
+   Copyright (C) 2021 Free Software Foundation, Inc.
c5d972
+   This file is part of the GNU C Library.
c5d972
+
c5d972
+   The GNU C Library is free software; you can redistribute it and/or
c5d972
+   modify it under the terms of the GNU Lesser General Public
c5d972
+   License as published by the Free Software Foundation; either
c5d972
+   version 2.1 of the License, or (at your option) any later version.
c5d972
+
c5d972
+   The GNU C Library is distributed in the hope that it will be useful,
c5d972
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
c5d972
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c5d972
+   Lesser General Public License for more details.
c5d972
+
c5d972
+   You should have received a copy of the GNU Lesser General Public
c5d972
+   License along with the GNU C Library; if not, see
c5d972
+   <https://www.gnu.org/licenses/>.  */
c5d972
+
c5d972
+#include <netdb.h>
c5d972
+#include <nss.h>
c5d972
+
c5d972
+void
c5d972
+call_gethostbyname (void)
c5d972
+{
c5d972
+  __nss_configure_lookup ("hosts", "files");
c5d972
+  /* This should not terminate the process due to a missing
c5d972
+     _nss_files_getcanonname_r symbol.  */
c5d972
+  gethostbyname ("localhost");
c5d972
+}
c5d972
diff --git a/elf/tst-dlmopen-gethostbyname.c b/elf/tst-dlmopen-gethostbyname.c
c5d972
new file mode 100644
c5d972
index 0000000000000000..12deb29900731c20
c5d972
--- /dev/null
c5d972
+++ b/elf/tst-dlmopen-gethostbyname.c
c5d972
@@ -0,0 +1,31 @@
c5d972
+/* Exercise dlerror_run in elf/dl-libc.c after dlmopen, via NSS (bug 27646).
c5d972
+   Copyright (C) 2021 Free Software Foundation, Inc.
c5d972
+   This file is part of the GNU C Library.
c5d972
+
c5d972
+   The GNU C Library is free software; you can redistribute it and/or
c5d972
+   modify it under the terms of the GNU Lesser General Public
c5d972
+   License as published by the Free Software Foundation; either
c5d972
+   version 2.1 of the License, or (at your option) any later version.
c5d972
+
c5d972
+   The GNU C Library is distributed in the hope that it will be useful,
c5d972
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
c5d972
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c5d972
+   Lesser General Public License for more details.
c5d972
+
c5d972
+   You should have received a copy of the GNU Lesser General Public
c5d972
+   License along with the GNU C Library; if not, see
c5d972
+   <https://www.gnu.org/licenses/>.  */
c5d972
+
c5d972
+#include <support/xdlfcn.h>
c5d972
+
c5d972
+static int
c5d972
+do_test (void)
c5d972
+{
c5d972
+  void *handle = xdlmopen (LM_ID_NEWLM, "tst-dlmopen-gethostbyname-mod.so",
c5d972
+                           RTLD_NOW);
c5d972
+  void (*call_gethostbyname) (void) = xdlsym (handle, "call_gethostbyname");
c5d972
+  call_gethostbyname ();
c5d972
+  return 0;
c5d972
+}
c5d972
+
c5d972
+#include <support/test-driver.c>