Subject: multibyte LC_CTYPE locales (Re: dlopen() twists)
To: None <>
From: None <>
List: tech-userlevel
Date: 01/02/2001 20:13:49
	i'd like to integrate citrus multibyte LC_CTYPE support into NetBSD-
	current, however, because of dlopen() twists presented in the original
	article, i am unable to do that.

	the problem is like this:
	- we plan to use dlopen() from within setlocale(LC_CTYPE), so that
	  we can dynamically load multibyte LC_CTYPE locale code from, like
	- if we do that, will effectively pull dlopen() into
	  its binary.  this causes chicken-and-egg problem.

	i can think of couple of workarounds for now:
	- do not use dlopen() from within setlocale(LC_CTYPE), have LC_CTYPE
	  locale code inside libc.
	  pros: libc build gets simple.  setuid binary issues go simple.
		we can use LC_CTYPE locale handling code from /sbin/* too.
	  cons: libc gets much bigger.  everyone calls printf() would need to
		pull iso2022/utf8/whatever support code, even if they
		do not really need locale code.
	- use dlopen() from within setlocale(LC_CTYPE).  compile
	  directly with special singlebyte-only setlocale code.
	  pros: we can add new locale handling code on the fly, by adding
		*.so under /usr/lib/localemod.  libc is kept small, and
		when LC_CTYPE is set to something other than C, we pull in
		locale handling code dynamically.
	  cons: is it really only problem?  dlopen() cannot be used
		from non-dynamic binaries so we cannot use localized
		characters from /sbin/*.
	- make dlopen() available everywhere, including non-shared binaries.
	  for we may still need some hack.

	attached is the patch to do the 2nd bullet.  or, we may want to supply
	/usr/lib/libnolocale.a (or libsinglebytelocale.a) for use with special
	binaries like ld.elf_so.


Index: Makefile
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/Makefile,v
retrieving revision 1.34
diff -u -r1.34 Makefile
--- Makefile	2000/11/10 21:31:30	1.34
+++ Makefile	2001/01/02 11:11:20
@@ -33,6 +33,12 @@
 #DBG=	-g
+# always use singlebyte locale.
+SRCS+=	multibyte_sb.c iswctype_sb.c setlocale.c
+CPPFLAGS+=	-UWITH_RUNE -I${.CURDIR}/../../lib/libc/locale \
+		-I${.CURDIR}/../../lib/libc/include
+.PATH:	${.CURDIR}/../../lib/libc/locale
 LDADD+=	-non_shared -L${DESTDIR}/${LIBDIR} -lc_pic