Module Name:    othersrc
Committed By:   agc
Date:           Sat Dec  4 01:54:51 UTC 2021

Modified Files:
        othersrc/external/bsd/agcre/dist: agcre.c agcre.h

Log Message:
Add visibility definitions for agcre.

For any sources embedding these routines, simply define HIDE_AGCRE,
before including the agcre.h header file, and the routines will have
the hidden visibility attribute set on them.  For more information on
that, see

        https://gcc.gnu.org/wiki/Visibility

To stop agcre routines being exported in a .so, simply define
HIDE_AGCRE - I've been doing this successfully in library Makefiles,
for example, this is from elex/lib/Makefile (elex is a library that
calls the agcre functions):

        # set symbol visibility for .so
        CPPFLAGS+=      -DHIDE_AGCRE

and the agcre symbols will be found just fine when linking and
running, but will not be exported by the linker.  This can save
headaches, and weird crashes, especially when combined with ASLR (when
two libraries define the same symbol, but with different structs or
arguments).

BEFORE:
        [2021/12/03 Fri 17:47:19] agc@netbsd-002 ~/local/elex-20211115 [13781] 
> nm -D lib/libelex.so
                         w _Jv_RegisterClasses
                         w __cxa_finalize
                         w __deregister_frame_info
                         U __fstat50
                         w __register_frame_info
                         U __sF
        000000000020f198 D _end
        000000000000c240 T _fini
        0000000000000ea0 T _init
        000000000000aa13 T agcre_new
        000000000000bc48 T agcre_regasub
        000000000000aa28 T agcre_regcomp
        000000000000adde T agcre_regerror
        000000000000ae48 T agcre_regexec
        000000000000b8fd T agcre_regfree
        000000000000b9a2 T agcre_regnsub
        000000000000b7e8 T agcre_rev_regexec
                         U asprintf
                         U calloc
        00000000000027f6 T elex_dispose
        0000000000002b6a T elex_exec
        0000000000002f5b T elex_exec_str
        0000000000002982 T elex_make_new_rule
        00000000000027bb T elex_new
                         U fclose
                         U fopen
                         U fprintf
                         U free
                         U fwrite
                         U memchr
                         U memcmp
                         U memcpy
                         U memmove
                         U memset
                         U mmap
                         U munmap
                         U printf
                         U putchar
                         U realloc
                         U snprintf
                         U strchr
                         U strcmp
                         U strdup
        000000000000c10c T striter_dispose
        000000000000c165 T striter_exec
        000000000000c1da T striter_exec_mem
        000000000000c0f7 T striter_new
                         U strlen
                         U strtol
                         U strtoul
                         U vsnprintf
                         U warn
                         U warnx
        [2021/12/03 Fri 17:47:22] agc@netbsd-002 ~/local/elex-20211115 [13782] >

AFTER adding HIDE_AGCRE (and HIDE_STRITER) to elex/lib/Makefile:
        [2021/12/03 Fri 17:47:45] agc@netbsd-002 ~/local/elex-20211115 [13774] 
> nm -D lib/libelex.so
                         w _Jv_RegisterClasses
                         w __cxa_finalize
                         w __deregister_frame_info
                         U __fstat50
                         w __register_frame_info
                         U __sF
        000000000020e160 D _end
        000000000000bf30 T _fini
        0000000000000c00 T _init
                         U asprintf
                         U calloc
        00000000000024e6 T elex_dispose
        000000000000285a T elex_exec
        0000000000002c4b T elex_exec_str
        0000000000002672 T elex_make_new_rule
        00000000000024ab T elex_new
                         U fclose
                         U fopen
                         U fprintf
                         U free
                         U fwrite
                         U memchr
                         U memcmp
                         U memcpy
                         U memmove
                         U memset
                         U mmap
                         U munmap
                         U printf
                         U putchar
                         U realloc
                         U snprintf
                         U strchr
                         U strcmp
                         U strdup
                         U strlen
                         U strtol
                         U strtoul
                         U vsnprintf
                         U warn
                         U warnx


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 othersrc/external/bsd/agcre/dist/agcre.c
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/agcre/dist/agcre.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/agcre/dist/agcre.c
diff -u othersrc/external/bsd/agcre/dist/agcre.c:1.1 othersrc/external/bsd/agcre/dist/agcre.c:1.2
--- othersrc/external/bsd/agcre/dist/agcre.c:1.1	Tue Oct  5 01:23:39 2021
+++ othersrc/external/bsd/agcre/dist/agcre.c	Sat Dec  4 01:54:51 2021
@@ -2658,14 +2658,14 @@ growspace(char **buf, size_t *size, size
 /***********************************************************/
 
 /* allocate a new structure and return it */
-agcre_regex_t *
+AGCRE_EXPORT agcre_regex_t *
 agcre_new(void)
 {
 	return calloc(1, sizeof(agcre_regex_t));
 }
 
 /* compile regular expression */
-int
+AGCRE_EXPORT int
 agcre_regcomp(agcre_regex_t *agcre, const void *vs, uint32_t flags)
 {
 	retoken_t	*tok;
@@ -2737,7 +2737,7 @@ agcre_regcomp(agcre_regex_t *agcre, cons
 #endif
 
 /* format the error nicely */
-size_t
+AGCRE_EXPORT size_t
 agcre_regerror(int errcode, const agcre_regex_t *agcre, char *errbuf, size_t size)
 {
 	re_t	*re;
@@ -2751,7 +2751,7 @@ agcre_regerror(int errcode, const agcre_
 }
 
 /* execute the regular expression */
-int
+AGCRE_EXPORT int
 agcre_regexec(agcre_regex_t *agcre, const void *vs, size_t matchc, agcre_regmatch_t *m, uint32_t flags)
 {
 	threadlist_t	*current;
@@ -2917,7 +2917,7 @@ break_for:
 }
 
 /* execute the regular expression backwards */
-int
+AGCRE_EXPORT int
 agcre_rev_regexec(agcre_regex_t *agcre, const void *vs, size_t matchc, agcre_regmatch_t *m, uint32_t flags)
 {
 	int64_t	from;
@@ -2949,7 +2949,7 @@ agcre_rev_regexec(agcre_regex_t *agcre, 
 }
 
 /* free the regular expression */
-void
+AGCRE_EXPORT void
 agcre_regfree(agcre_regex_t *agcre)
 {
 	uint32_t	 i;
@@ -2969,7 +2969,7 @@ agcre_regfree(agcre_regex_t *agcre)
 }
 
 /* do regexp sed-style substitution */
-ssize_t
+AGCRE_EXPORT ssize_t
 agcre_regnsub(char *buf, size_t size, const char *repl, const agcre_regmatch_t *rm, const char *str)
 {
 	const char	*i;
@@ -3022,7 +3022,7 @@ agcre_regnsub(char *buf, size_t size, co
 }
 
 /* do regexp sed-style substitution */
-ssize_t
+AGCRE_EXPORT ssize_t
 agcre_regasub(char **buf, const char *repl, const agcre_regmatch_t *rm, const char *str)
 {
 	const char	*i;

Index: othersrc/external/bsd/agcre/dist/agcre.h
diff -u othersrc/external/bsd/agcre/dist/agcre.h:1.2 othersrc/external/bsd/agcre/dist/agcre.h:1.3
--- othersrc/external/bsd/agcre/dist/agcre.h:1.2	Tue Oct  5 01:23:39 2021
+++ othersrc/external/bsd/agcre/dist/agcre.h	Sat Dec  4 01:54:51 2021
@@ -111,6 +111,32 @@ typedef struct agcre_regex_t {
 	void		*re_g;		/* internals */
 } agcre_regex_t;
 
+#ifndef USE_VISIBILITY
+#  if defined(__GNUC__)
+#    if __GNUC__ >= 4
+#    define USE_VISIBILITY	1
+#    else
+#    define USE_VISIBILITY	0
+#    endif
+#  else
+#    define USE_VISIBILITY	0
+#  endif
+#endif
+
+#if USE_VISIBILITY
+#  define DLL_PUBLIC __attribute__ ((visibility ("default")))
+#  define DLL_LOCAL  __attribute__ ((visibility ("hidden")))
+#else
+#  define DLL_PUBLIC
+#  define DLL_LOCAL
+#endif
+
+#ifdef HIDE_AGCRE
+#define AGCRE_EXPORT	DLL_LOCAL
+#else
+#define AGCRE_EXPORT	DLL_PUBLIC
+#endif
+
 #ifndef __BEGIN_DECLS
 #  if defined(__cplusplus)
 #  define __BEGIN_DECLS           extern "C" {
@@ -123,18 +149,18 @@ typedef struct agcre_regex_t {
 
 __BEGIN_DECLS
 
-agcre_regex_t *agcre_new(void);
-int agcre_regcomp(agcre_regex_t */*re*/, const void */*s*/, uint32_t /*flags*/);
-int agcre_regexec(agcre_regex_t */*re*/, const void */*vs*/, size_t /*mc*/,
+AGCRE_EXPORT agcre_regex_t *agcre_new(void);
+AGCRE_EXPORT int agcre_regcomp(agcre_regex_t */*re*/, const void */*s*/, uint32_t /*flags*/);
+AGCRE_EXPORT int agcre_regexec(agcre_regex_t */*re*/, const void */*vs*/, size_t /*mc*/,
 		agcre_regmatch_t */*m*/, uint32_t /*flags*/);
-int agcre_rev_regexec(agcre_regex_t */*agcre*/, const void */*vs*/,
+AGCRE_EXPORT int agcre_rev_regexec(agcre_regex_t */*agcre*/, const void */*vs*/,
 		size_t /*matchc*/, agcre_regmatch_t */*m*/, uint32_t /*flags*/);
-void agcre_regfree(agcre_regex_t */*re*/);
-size_t agcre_regerror(int /*errcode*/, const agcre_regex_t */*agcre*/,
+AGCRE_EXPORT void agcre_regfree(agcre_regex_t */*re*/);
+AGCRE_EXPORT size_t agcre_regerror(int /*errcode*/, const agcre_regex_t */*agcre*/,
 		char */*errbuf*/, size_t /*size*/);
-ssize_t agcre_regnsub(char */*buf*/, size_t /*size*/, const char */*repl*/,
+AGCRE_EXPORT ssize_t agcre_regnsub(char */*buf*/, size_t /*size*/, const char */*repl*/,
 		const agcre_regmatch_t */*rm*/, const char */*str*/);
-ssize_t agcre_regasub(char **/*buf*/, const char */*repl*/,
+AGCRE_EXPORT ssize_t agcre_regasub(char **/*buf*/, const char */*repl*/,
 		const agcre_regmatch_t */*rm*/, const char */*str*/);
 
 __END_DECLS

Reply via email to