From bd7de94d7fe8a0ba7742e90b1d6a09baa468bb58 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 8 Oct 2015 10:22:50 -0700 Subject: [PATCH] cmd/link: pass -Wl,-z,nodelete when creating an ELF shared library Go shared libraries do not support dlclose, and there is no likelihood that they will suppose dlclose in the future. Set the DF_1_NODELETE flag to tell the dynamic linker to not attempt to remove them from memory. This makes the shared library act as though every call to dlopen passed the RTLD_NODELETE flag. Fixes #12582. Update #11100. Update #12873. Change-Id: Id4b6e90a1b54e2e6fc8355b5fb22c5978fc762b4 Reviewed-on: https://go-review.googlesource.com/15605 Reviewed-by: Michael Hudson-Doyle --- src/cmd/link/internal/ld/lib.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 23fd44b6a8..3ce22017cf 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -982,11 +982,14 @@ func hostlink() { if HEADTYPE == obj.Hdarwin { argv = append(argv, "-dynamiclib") } else { + // ELF. argv = append(argv, "-Wl,-Bsymbolic") if UseRelro() { argv = append(argv, "-Wl,-z,relro") } - argv = append(argv, "-shared") + // Pass -z nodelete to mark the shared library as + // non-closeable: a dlclose will do nothing. + argv = append(argv, "-shared", "-Wl,-z,nodelete") } case BuildmodeShared: // TODO(mwhudson): unless you do this, dynamic relocations fill