Hi,
The libedit build system is unusual in so far as it compiles almost
all C files (but not all of them) as a single compilation unit,
editline.c, that #includes most of the other *.c files.
The main motivation for this quirk was to make sure that symbols
of the internal interfaces between the various modules of the library
are not externally visible to programs using the library, by making
all these internal interfaces static. But that comes at a high
price: All modules risk accidentally trampling on each other's
internal data, and almost all internal headers are visible to almost
all code, giving away most benefits of modularization. With a
codebase of about twenty thousand lines, i do feel uneasy about
that, in particular when refactoring, and there is still quite some
need for cleanup...
I'd prefer compiling all modules seperately, like we do it for most
other libraries. To preserve the benefit of hiding internal
interfaces from the public interface, i'd like to use
__attribute__((visibility("hidden"))) as suggested by Philip
Guenther@.
I verified on i386 with nm(1) that visibility of the internal symbols
doesn't change (it's "t" before and after), but i'd appreciate
confirmation from somebody more experienced with rarer platforms
that this change looks reasonable. And if your fear that it might
break your favourite platform, please compile-test and provide an OK.
A side benefit is that an option in the Makefile can go away that
was rarely tested and hence probably not very reliable. And we can
delete one file, editline.c.
On systems other than OpenBSD, if a platform doesn't support
__attribute__((visibility("hidden"))), you can simply #define
"protected" to be empty. Sure, that makes the internal symbols
externally visible, but everything still works, and such platforms
ought to be exceedingly rare nowadays.
Comments? OKs?
Ingo
Index: Makefile
===================================================================
RCS file: /cvs/src/lib/libedit/Makefile,v
retrieving revision 1.24
diff -u -p -r1.24 Makefile
--- Makefile 6 May 2016 13:12:52 -0000 1.24
+++ Makefile 9 May 2016 20:48:07 -0000
@@ -4,18 +4,12 @@
LIB= edit
-OSRCS= chared.c common.c el.c eln.c emacs.c filecomplete.c \
- hist.c keymacro.c map.c chartype.c \
- parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c
+SRCS = chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \
+ hist.c history.c historyn.c keymacro.c map.c \
+ parse.c prompt.c read.c readline.c refresh.c search.c sig.c \
+ terminal.c tokenizer.c tokenizern.c tty.c vi.c
MAN= editline.3 editrc.5 editline.7
-
-# For speed and debugging
-#SRCS= ${OSRCS}
-# For protection
-SRCS= editline.c
-
-SRCS += history.c historyn.c tokenizer.c tokenizern.c readline.c
LIBEDITDIR?=${.CURDIR}
Index: editline.c
===================================================================
RCS file: editline.c
diff -N editline.c
--- editline.c 6 May 2016 13:12:52 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,21 +0,0 @@
-#define protected static
-#define SCCSID
-#include "chared.c"
-#include "common.c"
-#include "el.c"
-#include "eln.c"
-#include "emacs.c"
-#include "filecomplete.c"
-#include "hist.c"
-#include "keymacro.c"
-#include "map.c"
-#include "chartype.c"
-#include "parse.c"
-#include "prompt.c"
-#include "read.c"
-#include "refresh.c"
-#include "search.c"
-#include "sig.c"
-#include "terminal.c"
-#include "tty.c"
-#include "vi.c"
Index: sys.h
===================================================================
RCS file: /cvs/src/lib/libedit/sys.h,v
retrieving revision 1.17
diff -u -p -r1.17 sys.h
--- sys.h 11 Apr 2016 21:17:29 -0000 1.17
+++ sys.h 9 May 2016 20:48:08 -0000
@@ -59,10 +59,8 @@
# endif
#endif
-#ifndef protected
-# define protected /* Redefined from elsewhere to "static" */
- /* When we want to hide everything */
-#endif
+/* If your compiler does not support this, define it to be empty. */
+#define protected __attribute__((visibility("hidden")))
#ifndef __arraycount
# define __arraycount(a) (sizeof(a) / sizeof(*(a)))