Subject: Re: Fwd: locale patch repository is moved.
To: None <dolecek@ics.muni.cz>
From: MINOURA Makoto <minoura@netbsd.org>
List: tech-userlevel
Date: 04/02/2000 00:56:47
|> In <38E4B7BC.DEB20F06@per4mance.cz>
|>   "PER4MANCE, J. Dolecek" <jdolecek@per4mance.cz> wrote:

> My point it - does it really break binary compatibility if 
> the functions would be moved to libc (and crt0.o won't
> contain them at all) ? Once the program is started,
> libc is already loaded, so it should not make any 
> difference to the application whether it get's the
> functions from crt0.o or libc. Or am I too confused here ?

Perhaps I (and Takuya) am too conservative, but it does
break compatibility when libc is linked statically, or libc
is not linked.

Here's my patch.

Index: lib/csu/common_elf/Makefile.inc
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/lib/csu/common_elf/Makefile.inc,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- lib/csu/common_elf/Makefile.inc	2000/04/01 01:40:05	1.1.1.2
+++ lib/csu/common_elf/Makefile.inc	2000/04/01 15:36:58	1.2
@@ -7,6 +7,7 @@
 CPPFLAGS+=	-DLIBC_SCCS -DPIC -DDYNAMIC -DELFSIZE=${ELFSIZE}
 CPPFLAGS+=	-I${.CURDIR}/../../../libexec/ld.elf_so
 CPPFLAGS+=	-I${.CURDIR}/../common_elf
+CPPFLAGS+=	-I${.CURDIR}/../../libc/dlfcn
 COPTS+=		-fPIC
 
 .PATH:		${.CURDIR}/../common_elf
Index: lib/csu/common_elf/common.c
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/lib/csu/common_elf/common.c,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -u -r1.1.1.4 -r1.2
--- lib/csu/common_elf/common.c	2000/02/11 17:34:43	1.1.1.4
+++ lib/csu/common_elf/common.c	2000/04/01 15:36:58	1.2
@@ -56,13 +56,6 @@
 #endif
 
 #ifdef DYNAMIC
-#ifdef __weak_alias
-__weak_alias(dlopen,_dlopen);
-__weak_alias(dlclose,_dlclose);
-__weak_alias(dlsym,_dlsym);
-__weak_alias(dlerror,_dlerror);
-__weak_alias(dladdr,_dladdr);
-#endif
 
 void
 _rtld_setup(cleanup, obj)
@@ -78,67 +71,14 @@
 	__mainprog_obj = obj;
 	atexit(cleanup);
 }
-
-void *
-dlopen(name, mode)
-	const char *name;
-	int mode;
-{
-
-	if (__mainprog_obj == NULL)
-		return NULL;
-	return (__mainprog_obj->dlopen)(name, mode);
-}
 
-int
-dlclose(fd)
-	void *fd;
-{
-
-	if (__mainprog_obj == NULL)
-		return -1;
-	return (__mainprog_obj->dlclose)(fd);
-}
-
-void *
-dlsym(fd, name)
-	void *fd;
-	const char *name;
-{
-
-	if (__mainprog_obj == NULL)
-		return NULL;
-	return (__mainprog_obj->dlsym)(fd, name);
-}
-
-#if 0 /* not supported for ELF shlibs, apparently */
-int
-dlctl(fd, cmd, arg)
-	void *fd, *arg;
-	int cmd;
-{
-
-	if (__mainprog_obj == NULL)
-		return -1;
-	return (__mainprog_obj->dlctl)(fd, cmd, arg);
-}
+#ifdef __weak_alias
+__weak_alias(dlopen,_dlopen);
+__weak_alias(dlclose,_dlclose);
+__weak_alias(dlsym,_dlsym);
+__weak_alias(dlerror,_dlerror);
+__weak_alias(dladdr,_dladdr);
 #endif
-
-__aconst char *
-dlerror()
-{
-
-	if (__mainprog_obj == NULL)
-		return ("Dynamic linker interface not available");
-	return (__mainprog_obj->dlerror)();
-}
-
-int
-dladdr(const void *addr, Dl_info *dli)
-{
 
-	if (__mainprog_obj == NULL)
-		return -1;
-	return (__mainprog_obj->dladdr)(addr, dli);
-}
+#include <dlfcn_stubs.c>
 #endif /* DYNAMIC */
Index: lib/libc/Makefile
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/lib/libc/Makefile,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- lib/libc/Makefile	2000/04/01 01:40:32	1.1.1.2
+++ lib/libc/Makefile	2000/04/01 15:36:52	1.2
@@ -17,6 +17,8 @@
 # The Hesiod functions are always in libc. To choose that getpwent() and friends
 # actually call the Hesiod functions, put -DHESIOD on the CPPFLAGS line below.
 
+.include <bsd.own.mk>
+
 LIB=		c
 CPPFLAGS+=	-D_LIBC -DNLS -DYP -DHESIOD -DLIBC_SCCS -DSYSLIBC_SCCS \
 		-D_REENTRANT -I${.CURDIR}/include
@@ -38,6 +40,7 @@
 .include "${ARCHDIR}/Makefile.inc"
 .endif
 
+.include "${.CURDIR}/dlfcn/Makefile.inc"
 .include "${.CURDIR}/db/Makefile.inc"
 .include "${.CURDIR}/compat-43/Makefile.inc"
 .include "${.CURDIR}/gen/Makefile.inc"
Index: lib/libc/dlfcn/Makefile.inc
===================================================================
RCS file: Makefile.inc
diff -N Makefile.inc
--- /dev/null	Sun Apr  2 00:44:37 2000
+++ /tmp/cvs08081ag	Sun Apr  2 00:47:30 2000
@@ -0,0 +1,9 @@
+#       $NetBSD:$
+
+.PATH: ${.CURDIR}/dlfcn
+
+.if ${OBJECT_FMT} == "ELF"
+CPPFLAGS+=	-I${.CURDIR}/../../libexec/ld.elf_so
+CPPFLAGS+=	-I${.CURDIR}/dlfcn
+SRCS+=		dlfcn_elf.c
+.endif
Index: lib/libc/dlfcn/dlfcn_elf.c
===================================================================
RCS file: dlfcn_elf.c
diff -N dlfcn_elf.c
--- /dev/null	Sun Apr  2 00:44:37 2000
+++ /tmp/cvs08081ah	Sun Apr  2 00:47:30 2000
@@ -0,0 +1,53 @@
+/*	$NetBSD$	*/
+
+/*
+ * Copyright (c) 2000 Takuya SHIOZAKI
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD:$");
+#endif /* LIBC_SCCS and not lint */
+
+#if defined(PIC) || defined(lint)
+#include "namespace.h"
+
+#define ELFSIZE ARCH_ELFSIZE
+#include "rtld.h"
+
+#ifdef __weak_extern
+__weak_extern(__mainprog_obj)
+#endif
+extern const Obj_Entry *__mainprog_obj;
+
+#ifdef __weak_alias
+__weak_alias(dlopen,__dlopen);
+__weak_alias(dlclose,__dlclose);
+__weak_alias(dlsym,__dlsym);
+__weak_alias(dlerror,__dlerror);
+__weak_alias(dladdr,__dladdr);
+#endif
+
+#include <dlfcn_stubs.c>
+#endif /* PIC */
Index: lib/libc/dlfcn/dlfcn_stubs.c
===================================================================
RCS file: dlfcn_stubs.c
diff -N dlfcn_stubs.c
--- /dev/null	Sun Apr  2 00:44:37 2000
+++ /tmp/cvs08081ai	Sun Apr  2 00:47:30 2000
@@ -0,0 +1,99 @@
+/*	$NetBSD$	*/
+
+/*
+ * Copyright (c) 1995 Christopher G. Demetriou
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christopher G. Demetriou
+ *	for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * NOT A STANDALONE FILE!
+ */
+
+void *
+dlopen(name, mode)
+	const char *name;
+	int mode;
+{
+
+	if (__mainprog_obj == NULL)
+		return NULL;
+	return (__mainprog_obj->dlopen)(name, mode);
+}
+
+int
+dlclose(fd)
+	void *fd;
+{
+
+	if (__mainprog_obj == NULL)
+		return -1;
+	return (__mainprog_obj->dlclose)(fd);
+}
+
+void *
+dlsym(fd, name)
+	void *fd;
+	const char *name;
+{
+
+	if (__mainprog_obj == NULL)
+		return NULL;
+	return (__mainprog_obj->dlsym)(fd, name);
+}
+
+#if 0 /* not supported for ELF shlibs, apparently */
+int
+dlctl(fd, cmd, arg)
+	void *fd, *arg;
+	int cmd;
+{
+
+	if (__mainprog_obj == NULL)
+		return -1;
+	return (__mainprog_obj->dlctl)(fd, cmd, arg);
+}
+#endif
+
+__aconst char *
+dlerror()
+{
+
+	if (__mainprog_obj == NULL)
+		return ("Dynamic linker interface not available");
+	return (__mainprog_obj->dlerror)();
+}
+
+int
+dladdr(const void *addr, Dl_info *dli)
+{
+
+	if (__mainprog_obj == NULL)
+		return -1;
+	return (__mainprog_obj->dladdr)(addr, dli);
+}
Index: lib/libc/include/namespace.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/lib/libc/include/namespace.h,v
retrieving revision 1.1.1.3
retrieving revision 1.2
diff -u -r1.1.1.3 -r1.2
--- lib/libc/include/namespace.h	2000/03/13 15:40:58	1.1.1.3
+++ lib/libc/include/namespace.h	2000/04/01 15:36:57	1.2
@@ -502,6 +502,11 @@
 #define yp_unbind		_yp_unbind
 #define yperr_string		_yperr_string
 #define ypprot_err		_ypprot_err
+#define dlopen			__dlopen
+#define dlclose			__dlclose
+#define dlsym			__dlsym
+#define dlerror			__dlerror
+#define dladdr			__dladdr
 #endif
 
 #endif
Index: sys/arch/alpha/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/alpha/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/alpha/include/elf_machdep.h	2000/04/01 01:52:31	1.1.1.2
+++ sys/arch/alpha/include/elf_machdep.h	2000/04/01 15:36:59	1.2
@@ -10,6 +10,8 @@
 		case EM_ALPHA_EXP:					\
 			break;
 
+#define ARCH_ELFSIZE		64	/* MD native binary size */
+
 /*
  * Alpha Relocation Types
  */
Index: sys/arch/i386/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/i386/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/i386/include/elf_machdep.h	2000/04/01 01:55:25	1.1.1.2
+++ sys/arch/i386/include/elf_machdep.h	2000/04/01 15:37:06	1.2
@@ -10,6 +10,8 @@
 #define	ELF64_MACHDEP_ID_CASES						\
 		/* no 64-bit ELF machine types supported */
 
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+
 /* i386 relocations */
 #define	R_386_NONE	0
 #define	R_386_32	1
Index: sys/arch/m68k/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/m68k/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/m68k/include/elf_machdep.h	2000/04/01 01:55:59	1.1.1.2
+++ sys/arch/m68k/include/elf_machdep.h	2000/04/01 15:37:10	1.2
@@ -9,6 +9,8 @@
 #define	ELF64_MACHDEP_ID_CASES						\
 		/* no 64-bit ELF machine types supported */
 
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+
 /* m68k relocation types */
 #define	R_68K_NONE	0
 #define	R_68K_32	1
Index: sys/arch/mips/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/mips/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/mips/include/elf_machdep.h	2000/04/01 01:56:30	1.1.1.2
+++ sys/arch/mips/include/elf_machdep.h	2000/04/01 15:37:11	1.2
@@ -8,6 +8,8 @@
 		/* no 64-bit ELF machine types supported */
 
 
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+
 /* mips relocs.  */
 
 #define R_MIPS_NONE		0
Index: sys/arch/powerpc/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/powerpc/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/powerpc/include/elf_machdep.h	2000/04/01 01:58:11	1.1.1.2
+++ sys/arch/powerpc/include/elf_machdep.h	2000/04/01 15:37:14	1.2
@@ -9,6 +9,8 @@
 #define	ELF64_MACHDEP_ID_CASES						\
 		/* no 64-bit ELF machine types supported */
 
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+
 #include <machine/reloc.h>		/* XXX */
 
 #define R_TYPE(name) __CONCAT(RELOC_,name)
Index: sys/arch/sh3/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/sh3/include/elf_machdep.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- sys/arch/sh3/include/elf_machdep.h	1999/10/25 13:55:09	1.1.1.1
+++ sys/arch/sh3/include/elf_machdep.h	2000/04/01 15:37:16	1.2
@@ -8,3 +8,5 @@
 #define	ELF64_MACHDEP_ENDIANNESS	XXX	/* break compilation */
 #define	ELF64_MACHDEP_ID_CASES						\
 		/* no 64-bit ELF machine types supported */
+
+#define ARCH_ELFSIZE		32	/* MD native binary size */
Index: sys/arch/sparc/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/sparc/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/sparc/include/elf_machdep.h	2000/04/01 01:58:28	1.1.1.2
+++ sys/arch/sparc/include/elf_machdep.h	2000/04/01 15:37:16	1.2
@@ -12,6 +12,8 @@
 		case EM_SPARCV9:					\
 		/* no 64-bit ELF machine types supported */
 
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+
 #define R_SPARC_NONE		0
 #define R_SPARC_8		1
 #define R_SPARC_16		2
Index: sys/arch/sparc64/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/sparc64/include/elf_machdep.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- sys/arch/sparc64/include/elf_machdep.h	2000/04/01 01:58:45	1.1.1.2
+++ sys/arch/sparc64/include/elf_machdep.h	2000/04/01 15:37:17	1.2
@@ -12,6 +12,8 @@
 		case EM_SPARCV9:					\
 			break;
 
+#define ARCH_ELFSIZE		64	/* MD native binary size */
+
 #define R_SPARC_NONE		0
 #define R_SPARC_8		1
 #define R_SPARC_16		2
Index: sys/arch/vax/include/elf_machdep.h
===================================================================
RCS file: /proj/CVSROOT/netbsd/src/sys/arch/vax/include/elf_machdep.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- sys/arch/vax/include/elf_machdep.h	1999/10/25 13:55:10	1.1.1.1
+++ sys/arch/vax/include/elf_machdep.h	2000/04/01 15:37:18	1.2
@@ -9,6 +9,8 @@
 #define	ELF64_MACHDEP_ID_CASES						\
 		/* no 64-bit ELF machine types supported */
 
+#define ARCH_ELFSIZE		32	/* MD native binary size */
+
 /* VAX relocations */
 #define	R_VAX_NONE	0
 #define	R_VAX_8		1	/* S + A */