diff --git a/CHANGES b/CHANGES index 8da3746..0ceaf4a 100644 --- a/CHANGES +++ b/CHANGES @@ -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 data that are unreachable by the entry point or exported symbols. - In particular, the linker is run with "-dead_strip" and with - "-dead_strip_dylibs". + 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. The following are the changes from calc version 2.14.2.1 to 2.14.3.0: diff --git a/Makefile.target b/Makefile.target index 341df10..9990556 100644 --- a/Makefile.target +++ b/Makefile.target @@ -177,7 +177,22 @@ LIBCUSTCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \ # data that are unreachable by the entry point or exported symbols. # 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 +endif # ($(ALLOW_CUSTOM),-DCUSTOM) # static library option # diff --git a/calc.c b/calc.c index a483dd6..dd371cc 100644 --- a/calc.c +++ b/calc.c @@ -166,6 +166,11 @@ main(int argc, char **argv) #if defined(CUSTOM) /* * 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) { fprintf(stderr, "%s: calc was built with " @@ -183,6 +188,11 @@ main(int argc, char **argv) #else /* CUSTOM */ /* * 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) { fprintf(stderr, "%s: calc was built with " diff --git a/custom.c b/custom.c index a0e895b..1638db2 100644 --- a/custom.c +++ b/custom.c @@ -41,6 +41,8 @@ # include #endif +EXTERN CONST struct custom cust[]; /* custom interface table */ + #else /* CUSTOM */ #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 */ @@ -117,15 +109,6 @@ custom(char *name, int count, VALUE **vals) (conf->tab_ok ? "\t" : ""), name, count, (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); #endif /* CUSTOM */ diff --git a/custom.h b/custom.h index 42d246f..94f1707 100644 --- a/custom.h +++ b/custom.h @@ -78,9 +78,6 @@ E_FUNC VALUE custom(char*, int, VALUE**); /* master custom interface */ EXTERN BOOL allow_custom; /* TRUE => custom builtins allowed */ E_FUNC void showcustom(void); /* print custom functions */ 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 */ #endif /* !CUSTOM_H */