change macOS to not use "-dead_strip_dylibs" when CUSTOM is defined

Under macOS, to reduce dependency chains, we remove functions and
data that are unreachable by the entry point or exported symbols.
In particular, the macOS linker is used with "-dead_strip".

While calc on macOS will execute if linker used with "-dead_strip_dylibs"
and CUSTOM is defined, other applications that use libcalc but not
libcustcalc (such as sample_many and sample_rand) will fail to execute
due to missile symbols.  Therefore "-dead_strip_dylibs" is not used
by default when ALLOW_CUSTOM is "-DCUSTOM" under macOS.
This commit is contained in:
Landon Curt Noll
2023-08-14 17:08:28 -07:00
parent af9b052fe9
commit 7d8d4cb5ea
5 changed files with 34 additions and 24 deletions

View File

@@ -92,8 +92,13 @@ The following are the changes from calc version 2.14.3.1 to date:
Under macOS, to reduce dependency chains, we remove functions and Under macOS, to reduce dependency chains, we remove functions and
data that are unreachable by the entry point or exported symbols. data that are unreachable by the entry point or exported symbols.
In particular, the linker is run with "-dead_strip" and with In particular, the macOS linker is used with "-dead_strip".
"-dead_strip_dylibs".
While calc on macOS will execute if linker used with "-dead_strip_dylibs"
and CUSTOM is defined, other applications that use libcalc but not
libcustcalc (such as sample_many and sample_rand) will fail to execute
due to missile symbols. Therefore "-dead_strip_dylibs" is not used
by default when ALLOW_CUSTOM is "-DCUSTOM" under macOS.
The following are the changes from calc version 2.14.2.1 to 2.14.3.0: The following are the changes from calc version 2.14.2.1 to 2.14.3.0:

View File

@@ -177,7 +177,22 @@ LIBCUSTCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \
# data that are unreachable by the entry point or exported symbols. # data that are unreachable by the entry point or exported symbols.
# #
COMMON_LDFLAGS+= -Wl,-dead_strip COMMON_LDFLAGS+= -Wl,-dead_strip
# Do not link with "-dead_strip_dylibs" if CUSTOM is defined
# (i.e., ${ALLOW_CUSTOM} is "-DCUSTOM). This is because unless
# the application makes an explicit symbol reference to some symbol
# in libcustcalc, the application will fail to execute due to
# a missing symbol.
#
# The calc application will run with CUSTOM defined under
# "-dead_strip_dylibs" because calc.o (in main()) makes an explicit
# reference to custtbl_allowed (see custom/custtbl.c) in libcustcalc.
# However applications such as sample_many and sample_rand will
# fail to load when CUSTOM is defined and "-dead_strip_dylibs" is used..
#
ifneq ($(ALLOW_CUSTOM),-DCUSTOM)
COMMON_LDFLAGS+= -Wl,-dead_strip_dylibs COMMON_LDFLAGS+= -Wl,-dead_strip_dylibs
endif # ($(ALLOW_CUSTOM),-DCUSTOM)
# static library option # static library option
# #

10
calc.c
View File

@@ -166,6 +166,11 @@ main(int argc, char **argv)
#if defined(CUSTOM) #if defined(CUSTOM)
/* /*
* validate custtbl_allowed value * validate custtbl_allowed value
*
* We make an explicit reference to the custtbl_allowed symbol
* in libcustcalc (see custom/custtbl.c) so that the use
* of "-dead_strip_dylibs" with the macOS linker won't cause
* the calc to fail to load due to a missing symbol.
*/ */
if (custtbl_allowed == 0) { if (custtbl_allowed == 0) {
fprintf(stderr, "%s: calc was built with " fprintf(stderr, "%s: calc was built with "
@@ -183,6 +188,11 @@ main(int argc, char **argv)
#else /* CUSTOM */ #else /* CUSTOM */
/* /*
* validate custtbl_allowed value * validate custtbl_allowed value
*
* We make an explicit reference to the custtbl_allowed symbol
* in libcustcalc (see custom/custtbl.c) so that the use
* of "-dead_strip_dylibs" with the macOS linker won't cause
* the calc to fail to load due to a missing symbol.
*/ */
if (custtbl_allowed != 0) { if (custtbl_allowed != 0) {
fprintf(stderr, "%s: calc was built with " fprintf(stderr, "%s: calc was built with "

View File

@@ -41,6 +41,8 @@
# include <string.h> # include <string.h>
#endif #endif
EXTERN CONST struct custom cust[]; /* custom interface table */
#else /* CUSTOM */ #else /* CUSTOM */
#include "config.h" #include "config.h"
@@ -91,16 +93,6 @@ custom(char *name, int count, VALUE **vals)
} }
} }
/*
* validate custtbl_allowed value
*/
if (custtbl_allowed == 0) {
fprintf(stderr,
"%sCalc was built with custom functions enabled but custtbl_allowed: %d == 0\n",
(conf->tab_ok ? "\t" : ""), custtbl_allowed);
return error_value(E_NO_CUSTOM);
}
/* /*
* no such custom function * no such custom function
*/ */
@@ -117,15 +109,6 @@ custom(char *name, int count, VALUE **vals)
(conf->tab_ok ? "\t" : ""), name, count, (conf->tab_ok ? "\t" : ""), name, count,
(vals == NULL) ? "NULL" : "non-NULL"); (vals == NULL) ? "NULL" : "non-NULL");
} }
/*
* validate custtbl_allowed value
*/
if (custtbl_allowed != 0) {
fprintf(stderr,
"%sCalc was built with custom functions disabled but custtbl_allowed: %d != 0\n",
(conf->tab_ok ? "\t" : ""), custtbl_allowed);
}
return error_value(E_NO_CUSTOM); return error_value(E_NO_CUSTOM);
#endif /* CUSTOM */ #endif /* CUSTOM */

View File

@@ -78,9 +78,6 @@ E_FUNC VALUE custom(char*, int, VALUE**); /* master custom interface */
EXTERN BOOL allow_custom; /* TRUE => custom builtins allowed */ EXTERN BOOL allow_custom; /* TRUE => custom builtins allowed */
E_FUNC void showcustom(void); /* print custom functions */ E_FUNC void showcustom(void); /* print custom functions */
E_FUNC void customhelp(char *); /* direct custom help */ E_FUNC void customhelp(char *); /* direct custom help */
#if defined(CUSTOM)
EXTERN CONST struct custom cust[]; /* custom interface table */
#endif /* CUSTOM */
E_FUNC void init_custreg(void); /* initialize custom registers */ E_FUNC void init_custreg(void); /* initialize custom registers */
#endif /* !CUSTOM_H */ #endif /* !CUSTOM_H */