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