mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
change libcalc dynamic library to link with libcustcalc
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 both "-dead_strip" and "-dead_strip_dylibs". The libcalc shared library is now linked with libcustcalc.
This commit is contained in:
11
CHANGES
11
CHANGES
@@ -1,3 +1,14 @@
|
|||||||
|
The following are the changes from calc version 2.14.3.4 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 macOS linker is used with both
|
||||||
|
"-dead_strip" and "-dead_strip_dylibs".
|
||||||
|
|
||||||
|
The libcalc shared library is now linked with libcustcalc.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The following are the changes from calc version 2.14.3.1 to 2.14.3.4:
|
The following are the changes from calc version 2.14.3.1 to 2.14.3.4:
|
||||||
|
|
||||||
Fix typo in the `make debug` Makefile rule.
|
Fix typo in the `make debug` Makefile rule.
|
||||||
|
4
Makefile
4
Makefile
@@ -475,8 +475,8 @@ calc${EXT}: .hsrc ${CALCOBJS} ${CALC_DYNAMIC_LIBS} ${MK_SET}
|
|||||||
${CC} ${CALCOBJS} ${LDFLAGS} ${LD_SHARE} ${CALC_DYNAMIC_LIBS} \
|
${CC} ${CALCOBJS} ${LDFLAGS} ${LD_SHARE} ${CALC_DYNAMIC_LIBS} \
|
||||||
${READLINE_LIB} ${READLINE_EXTRAS} -o $@
|
${READLINE_LIB} ${READLINE_EXTRAS} -o $@
|
||||||
|
|
||||||
libcalc${LIB_EXT_VERSION}: ${LIBOBJS} ver_calc${EXT} ${MK_SET}
|
libcalc${LIB_EXT_VERSION}: ${LIBOBJS} ver_calc${EXT} ${MK_SET} libcustcalc${LIB_EXT_VERSION}
|
||||||
${CC} ${LIBCALC_SHLIB} ${LIBOBJS} \
|
${CC} ${LIBCALC_SHLIB} ${LIBOBJS} libcustcalc${LIB_EXT_VERSION} \
|
||||||
${READLINE_LIB} ${READLINE_EXTRAS} -o libcalc${LIB_EXT_VERSION}
|
${READLINE_LIB} ${READLINE_EXTRAS} -o libcalc${LIB_EXT_VERSION}
|
||||||
|
|
||||||
libcalc${LIB_EXT}: libcalc${LIB_EXT_VERSION}
|
libcalc${LIB_EXT}: libcalc${LIB_EXT_VERSION}
|
||||||
|
@@ -177,22 +177,7 @@ 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
|
||||||
#
|
#
|
||||||
|
32
calc.c
32
calc.c
@@ -164,19 +164,13 @@ main(int argc, char **argv)
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case 'C':
|
case 'C':
|
||||||
#if defined(CUSTOM)
|
#if defined(CUSTOM)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* validate custtbl_allowed value
|
* error if libcustcalc was compiled with CUSTOM undefined
|
||||||
*
|
|
||||||
* 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 (custom_compiled() == 0) {
|
||||||
fprintf(stderr, "%s: calc was built with "
|
fprintf(stderr, "%s: calc was built with custom functions enabled, "
|
||||||
"custom functions enabled, "
|
"however custom_compiled() retuned 0", program);
|
||||||
"but custtbl_allowed: %d == 0\n",
|
|
||||||
program, custtbl_allowed);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,19 +180,13 @@ main(int argc, char **argv)
|
|||||||
allow_custom = TRUE;
|
allow_custom = TRUE;
|
||||||
break;
|
break;
|
||||||
#else /* CUSTOM */
|
#else /* CUSTOM */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* validate custtbl_allowed value
|
* error if libcustcalc was compiled with CUSTOM defined
|
||||||
*
|
|
||||||
* 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 (custom_compiled() == 1) {
|
||||||
fprintf(stderr, "%s: calc was built with "
|
fprintf(stderr, "%s: calc was built with custom functions disabled, "
|
||||||
"custom functions disabled, "
|
"however custom_compiled() retuned 1", program);
|
||||||
"but custtbl_allowed: %d != 0\n",
|
|
||||||
program, custtbl_allowed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
16
custom.c
16
custom.c
@@ -68,6 +68,14 @@ custom(char *name, int count, VALUE **vals)
|
|||||||
|
|
||||||
CONST struct custom *p; /* current function */
|
CONST struct custom *p; /* current function */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* error if libcustcalc was compiled with CUSTOM undefined
|
||||||
|
*/
|
||||||
|
if (custom_compiled() == 0) {
|
||||||
|
math_error("libcustcalc was compiled CUSTOM undefined");
|
||||||
|
not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* search the custom interface table for a function
|
* search the custom interface table for a function
|
||||||
*/
|
*/
|
||||||
@@ -100,6 +108,14 @@ custom(char *name, int count, VALUE **vals)
|
|||||||
|
|
||||||
#else /* CUSTOM */
|
#else /* CUSTOM */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* error if libcustcalc was compiled with CUSTOM defined
|
||||||
|
*/
|
||||||
|
if (custom_compiled() == 1) {
|
||||||
|
math_error("libcustcalc was compiled with CUSTOM defined");
|
||||||
|
not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%sCalc was built with custom functions disabled\n",
|
"%sCalc was built with custom functions disabled\n",
|
||||||
(conf->tab_ok ? "\t" : ""));
|
(conf->tab_ok ? "\t" : ""));
|
||||||
|
2
custom.h
2
custom.h
@@ -73,7 +73,7 @@ struct custom {
|
|||||||
*
|
*
|
||||||
* These are the required interfaces. The dummy.c stubs these interfaces too.
|
* These are the required interfaces. The dummy.c stubs these interfaces too.
|
||||||
*/
|
*/
|
||||||
EXTERN int custtbl_allowed; /* 1 ==> CUSTOM defined, 0 ==> CUSTOM undefined */
|
E_FUNC int custom_compiled(void); /* return 1 ==> libcustcalc compiled w/CUSTOM defined, else return 0 */
|
||||||
E_FUNC VALUE custom(char*, int, VALUE**); /* master custom interface */
|
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 */
|
||||||
|
@@ -25,17 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ISO C requires a translation unit to contain at least one declaration,
|
|
||||||
* so we declare a global variable whose value is based on if CUSTOM is defined.
|
|
||||||
*/
|
|
||||||
#if defined(CUSTOM)
|
|
||||||
int custtbl_allowed = 1; /* CUSTOM defined */
|
|
||||||
#else /* CUSTOM */
|
|
||||||
int custtbl_allowed = 0; /* CUSTOM undefined */
|
|
||||||
#endif /* CUSTOM */
|
|
||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "../have_const.h"
|
#include "../have_const.h"
|
||||||
@@ -46,6 +35,24 @@ int custtbl_allowed = 0; /* CUSTOM undefined */
|
|||||||
#include "../banned.h" /* include after system header <> includes */
|
#include "../banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* custom_compiled - determine if custom functions are compiled into libcustcalc
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
s* 1 ==> libcustcalc was compiled with CUSTOM defined
|
||||||
|
* 0 ==> libcustcalc was compiled with CUSTOM undefined
|
||||||
|
*/
|
||||||
|
E_FUNC int
|
||||||
|
custom_compiled(void)
|
||||||
|
{
|
||||||
|
#if defined(CUSTOM)
|
||||||
|
return 1;
|
||||||
|
#else /* CUSTOM */
|
||||||
|
return 0;
|
||||||
|
#endif /* CUSTOM */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: See the file HOW_TO_ADD for instructions on how to add custom functions.
|
* NOTE: See the file HOW_TO_ADD for instructions on how to add custom functions.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user