[Git][NTPsec/ntpsec][master] Address GitLab issue #365: linking fails on OSX 10.13 with Xcode 9

Eric S. Raymond gitlab at mg.gitlab.com
Wed Aug 16 22:50:44 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
63301f3f by Eric S. Raymond at 2017-08-16T18:49:46-04:00
Address GitLab issue #365: linking fails on OSX 10.13 with Xcode 9

Move the macro LIB_GETBUF to be an actual function lib_getbuf() and
stop playing games with edge cases in the linker. OS X lost patience
with our screwing around after 10.12.

- - - - -


21 changed files:

- attic/sht.c
- include/lib_strbuf.h
- include/ntp_stdlib.h
- libntp/authreadkeys.c
- libntp/dolfptoa.c
- libntp/humandate.c
- libntp/lib_strbuf.c
- libntp/numtoa.c
- libntp/prettydate.c
- libntp/socktoa.c
- libntp/ssl_init.c
- libntp/statestr.c
- libntp/timetoa.c
- libparse/ieee754io.c
- ntpd/ntp_control.c
- ntpd/ntp_refclock.c
- ntpd/ntp_util.c
- ntpd/ntpd.c
- tests/common/tests_main.c
- tests/libntp/refidsmear.c
- tests/libntp/timespecops.c


Changes:

=====================================
attic/sht.c
=====================================
--- a/attic/sht.c
+++ b/attic/sht.c
@@ -74,8 +74,6 @@ main (
 
 	progname = argv[0];
 
-	init_lib();
-
 	if (argc<=1) {
 	  usage:
 		printf ("usage: %s [uu:]{r[c][l]|w|snnn}\n",argv[0]);


=====================================
include/lib_strbuf.h
=====================================
--- a/include/lib_strbuf.h
+++ b/include/lib_strbuf.h
@@ -14,17 +14,6 @@
 #define	LIB_BUFLENGTH	128
 
 typedef char libbufstr[LIB_BUFLENGTH];
-extern libbufstr lib_stringbuf[LIB_NUMBUF];
-extern int lib_nextbuf;
-
-/*
- * Macro to get a pointer to the next buffer
- */
-#define	LIB_GETBUF(bufp)					\
-	do {							\
-		ZERO(lib_stringbuf[lib_nextbuf]);		\
-		(bufp) = &lib_stringbuf[lib_nextbuf++][0];	\
-		lib_nextbuf %= (int)COUNTOF(lib_stringbuf);		\
-	} while (false)
+extern char *lib_getbuf(void);
 
 #endif	/* GUARD_LIB_STRBUF_H */


=====================================
include/ntp_stdlib.h
=====================================
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -50,7 +50,6 @@ extern	bool	authusekey	(keyid_t, int, const uint8_t *);
 
 extern	int	clocktime	(int, int, int, int, int, uint32_t, uint32_t *, uint32_t *);
 extern	void	init_auth	(void);
-extern	void	init_lib	(void);
 extern	void	init_network	(void);
 extern	void	auth_prealloc_symkeys(int);
 extern	int	ymd2yd		(int, int, int);


=====================================
libntp/authreadkeys.c
=====================================
--- a/libntp/authreadkeys.c
+++ b/libntp/authreadkeys.c
@@ -143,7 +143,7 @@ msyslog(LOG_ERR, "authreadkeys: reading %s", file);
 		 */
 		char *upcased;
 		char *pch;
-		LIB_GETBUF(upcased);
+		upcased = lib_getbuf();
 		strlcpy(upcased, token, LIB_BUFLENGTH);
 		for (pch = upcased; '\0' != *pch; pch++)
 			*pch = (char)toupper((unsigned char)*pch);


=====================================
libntp/dolfptoa.c
=====================================
--- a/libntp/dolfptoa.c
+++ b/libntp/dolfptoa.c
@@ -32,7 +32,7 @@ dolfptoa(
 	/*
 	 * Get a string buffer before starting
 	 */
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 
 	/*
 	 * Zero the character buffer


=====================================
libntp/humandate.c
=====================================
--- a/libntp/humandate.c
+++ b/libntp/humandate.c
@@ -24,7 +24,7 @@ humanlogtime(void)
 	if (!tm)
 		return "-- --- --:--:--";
 
-	LIB_GETBUF(bp);
+	bp = lib_getbuf();
 
 #ifdef ENABLE_CLASSIC_MODE
 	const char * const months[12] = {
@@ -62,7 +62,7 @@ humantime(
 	if (!tm)
 		return "--:--:--";
 
-	LIB_GETBUF(bp);
+	bp  = lib_getbuf();
 	
 	snprintf(bp, LIB_BUFLENGTH, "%02d:%02d:%02d",
 		 tm->tm_hour, tm->tm_min, tm->tm_sec);


=====================================
libntp/lib_strbuf.c
=====================================
--- a/libntp/lib_strbuf.c
+++ b/libntp/lib_strbuf.c
@@ -9,24 +9,22 @@
 #include "ntp_stdlib.h"
 #include "lib_strbuf.h"
 
-
 /*
  * Storage declarations
  */
 int		debug;
-libbufstr	lib_stringbuf[LIB_NUMBUF];
-int		lib_nextbuf;
-
 
 /*
- * This stub is required to pacify the Mac OS X linker, which will
- * refuse to consider a module a candidate to be linked unless it
- * has an executable entry point called from somewhere else that
- * is linked.
- *
- * marking this __attribute__((const)) kills thelinker too.
+ * Macro to get a pointer to the next buffer
  */
-void
-init_lib(void)
+char *lib_getbuf(void)
 {
+    static libbufstr	lib_stringbuf[LIB_NUMBUF];
+    static int		lib_nextbuf;
+    char *bufp;
+
+    ZERO(lib_stringbuf[lib_nextbuf]);
+    (bufp) = &lib_stringbuf[lib_nextbuf++][0];
+    lib_nextbuf %= (int)COUNTOF(lib_stringbuf);
+    return bufp;
 }


=====================================
libntp/numtoa.c
=====================================
--- a/libntp/numtoa.c
+++ b/libntp/numtoa.c
@@ -21,7 +21,7 @@ numtoa(
 	register char *buf;
 
 	netnum = ntohl(num);
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 	snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
 		 ((unsigned long)netnum >> 24) & 0xff,
 		 ((unsigned long)netnum >> 16) & 0xff,
@@ -44,7 +44,7 @@ refid_str(
 	if (stratum > 1)
 		return numtoa(refid);
 
-	LIB_GETBUF(text);
+	text = lib_getbuf();
 	text[0] = '.';
 	memcpy(&text[1], &refid, sizeof(refid));
 	text[1 + sizeof(refid)] = '\0';


=====================================
libntp/prettydate.c
=====================================
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -129,7 +129,7 @@ common_prettydate(
 	uint32_t	     ntps;
 	time64_t	     sec;
 
-	LIB_GETBUF(bp);
+	bp = lib_getbuf();
 
 	/* get & fix milliseconds */
 	ntps = lfpuint(ts);
@@ -200,7 +200,7 @@ char * rfc3339time(
 	char *		buf;
 	struct tm tm, *tm2;
 
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 	tm2 = gmtime_r(&posix_stamp, &tm);
 	if (tm2 == NULL || tm.tm_year > 9999)
 		snprintf(buf, LIB_BUFLENGTH, "rfc3339time: %ld: range error",


=====================================
libntp/socktoa.c
=====================================
--- a/libntp/socktoa.c
+++ b/libntp/socktoa.c
@@ -31,7 +31,7 @@ socktoa(
 	unsigned long	scope;
 
 	saved_errno = errno;
-	LIB_GETBUF(res);
+	res = lib_getbuf();
 
 	if (NULL == sock) {
 		strlcpy(res, "(null)", LIB_BUFLENGTH);
@@ -50,7 +50,7 @@ socktoa(
 			scope = SCOPE_VAR(sock);
 			if (0 != scope && !strchr(res, '%')) {
 				addr = res;
-				LIB_GETBUF(res);
+				res = lib_getbuf();
 				snprintf(res, LIB_BUFLENGTH, "%s%%%lu",
 					 addr, scope);
 				res[LIB_BUFLENGTH - 1] = '\0';
@@ -80,7 +80,7 @@ sockporttoa(
 
 	saved_errno = errno;
 	atext = socktoa(sock);
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 	snprintf(buf, LIB_BUFLENGTH,
 		 (IS_IPV6(sock))
 		     ? "[%s]:%hu"


=====================================
libntp/ssl_init.c
=====================================
--- a/libntp/ssl_init.c
+++ b/libntp/ssl_init.c
@@ -23,8 +23,6 @@ ssl_init(void)
 	if (ssl_init_done)
 		return;
 
-	init_lib();
-
 #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
 	OpenSSL_add_all_digests();
 	atexit(&atexit_ssl_cleanup);


=====================================
libntp/statestr.c
=====================================
--- a/libntp/statestr.c
+++ b/libntp/statestr.c
@@ -267,7 +267,7 @@ getcode(
 		codetab++;
 	}
 
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 	snprintf(buf, LIB_BUFLENGTH, "%s_%d", codetab->string, code);
 
 	return buf;
@@ -286,7 +286,7 @@ getevents(
 	if (cnt == 0)
 		return "no events";
 
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 	snprintf(buf, LIB_BUFLENGTH, "%d event%s", cnt,
 		 (1 == cnt)
 		     ? ""
@@ -319,7 +319,7 @@ decode_bitflags(
 	int		saved_errno;	/* for use in DPRINT/TPRINT with %m */
 
 	saved_errno = errno;
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 	pch = buf;
 	lim = buf + LIB_BUFLENGTH;
 	sep = "";
@@ -412,7 +412,7 @@ statustoa(
 	char *	cc;
 	uint8_t	pst;
 
-	LIB_GETBUF(cb);
+	cb = lib_getbuf();
 
 	switch (type) {
 


=====================================
libntp/timetoa.c
=====================================
--- a/libntp/timetoa.c
+++ b/libntp/timetoa.c
@@ -64,7 +64,7 @@ format_time_fraction(
 
 	//REQUIRE(prec != 0);
 
-	LIB_GETBUF(cp);
+	cp = lib_getbuf();
 	secs_u = (u_time)secs;
 	
 	/* check if we need signed or unsigned mode */


=====================================
libparse/ieee754io.c
=====================================
--- a/libparse/ieee754io.c
+++ b/libparse/ieee754io.c
@@ -29,7 +29,7 @@ fmt_blong(
     int i = cnt;
 
     val <<= 32 - cnt;
-    LIB_GETBUF(buf);
+    buf = lib_getbuf();
     s = buf;
 
     while (i--) {
@@ -54,7 +54,7 @@ fmt_flt(
 {
         char *buf;
 
-        LIB_GETBUF(buf);
+        buf = lib_getbuf();
         if ( 8 == length ) {
             snprintf(buf, LIB_BUFLENGTH, "%c %s %s %s", sign ? '-' : '+',
                      fmt_blong(ch, 11),
@@ -79,7 +79,7 @@ fmt_hex(
         char    hex[4];
         int     i;
 
-        LIB_GETBUF(buf);
+        buf = lib_getbuf();
         buf[0] = '\0';
         for (i = 0; i < length; i++) {
                 snprintf(hex, sizeof(hex), "%02x", bufp[i]);


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -3884,7 +3884,7 @@ send_restrict_entry(
 			if ('\0' == match_str[0]) {
 				pch = access_str;
 			} else {
-				LIB_GETBUF(buf);
+				buf = lib_getbuf();
 				snprintf(buf, LIB_BUFLENGTH, "%s %s",
 					 match_str, access_str);
 				pch = buf;


=====================================
ntpd/ntp_refclock.c
=====================================
--- a/ntpd/ntp_refclock.c
+++ b/ntpd/ntp_refclock.c
@@ -130,7 +130,7 @@ refclock_name(
 {
 	char *buf;
 
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 
 	snprintf(buf, LIB_BUFLENGTH, "%s(%d)",
 			 peer->procptr->clockname, peer->refclkunit);


=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -353,7 +353,7 @@ timespec_to_MJDtime(const struct timespec *ts)
 	char *buf;
 	unsigned long	day, sec, msec;
 
-	LIB_GETBUF(buf);
+	buf = lib_getbuf();
 
 	day = (unsigned long)ts->tv_sec / SECSPERDAY + MJD_1970;
 	sec = (unsigned long)ts->tv_sec % SECSPERDAY;


=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -585,7 +585,6 @@ ntpdmain(
 	}
 # endif	/* HAVE_WORKING_FORK */
 
-	init_lib();
 	init_network();
 	/*
 	 * Detach us from the terminal.  May need an #ifndef GIZMO.


=====================================
tests/common/tests_main.c
=====================================
--- a/tests/common/tests_main.c
+++ b/tests/common/tests_main.c
@@ -78,7 +78,6 @@ static void RunAllTests(void)
 
 int main(int argc, const char * argv[]) {
 
-	init_lib();
 	init_auth();
 	init_network();
 


=====================================
tests/libntp/refidsmear.c
=====================================
--- a/tests/libntp/refidsmear.c
+++ b/tests/libntp/refidsmear.c
@@ -30,7 +30,7 @@ convertRefIDToLFP(uint32_t r)
 
 TEST_GROUP(refidsmear);
 
-TEST_SETUP(refidsmear) {init_lib();}
+TEST_SETUP(refidsmear) {}
 
 TEST_TEAR_DOWN(refidsmear) {}
 


=====================================
tests/libntp/timespecops.c
=====================================
--- a/tests/libntp/timespecops.c
+++ b/tests/libntp/timespecops.c
@@ -35,7 +35,7 @@ struct lfpfracdata {
 
 TEST_GROUP(timespecops);
 
-TEST_SETUP(timespecops) {init_lib();}
+TEST_SETUP(timespecops) {}
 
 TEST_TEAR_DOWN(timespecops) {}
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/63301f3f217b45dfadc2d5a116b782fad8ad6de3

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/63301f3f217b45dfadc2d5a116b782fad8ad6de3
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170816/1e28d7a8/attachment.html>


More information about the vc mailing list