From e0df1646fc1aa7e30586b144db63472ef213143f Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Mon, 14 Aug 2023 04:11:33 -0700 Subject: [PATCH] add -dead_strip_dylibs by default to the macOS linker 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". --- CHANGES | 3 ++- Makefile.target | 9 +-------- custom.c | 19 +++++++++++++++++++ custom.h | 1 + custom/c_argv.c | 4 ++-- custom/c_devnull.c | 4 ++-- custom/c_help.c | 4 ++-- custom/c_pmodm127.c | 4 ++-- custom/c_pzasusb8.c | 4 ++-- custom/c_register.c | 4 ++-- custom/c_sysinfo.c | 4 ++-- custom/custtbl.c | 17 ++++++++++++++--- 12 files changed, 51 insertions(+), 26 deletions(-) diff --git a/CHANGES b/CHANGES index 0d5f243..ec3db01 100644 --- a/CHANGES +++ b/CHANGES @@ -89,7 +89,8 @@ 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". + In particular, the linker is run with "-dead_strip" and with + "-dead_strip_dylibs". 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 c64be88..09dbe39 100644 --- a/Makefile.target +++ b/Makefile.target @@ -165,14 +165,7 @@ LIBCUSTCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \ # To reduce dependency chains under macOS, we remove functions and # data that are unreachable by the entry point or exported symbols. # -LDFLAGS+= -Wl,-dead_strip - -# NOTE: Do not use: LDFLAGS+= -Wl,-dead_strip_dylibs -# -# This option should not be used when linking against a dylib which is -# required at runtime for some indirect reason such as the dylib has an -# important initializer. The libcalc and libcustcalc have -# important initializers, and so this option should not be used. +LDFLAGS+= -Wl,-dead_strip -Wl,-dead_strip_dylibs # static library option # diff --git a/custom.c b/custom.c index 58f0d15..6e0e9db 100644 --- a/custom.c +++ b/custom.c @@ -91,6 +91,16 @@ 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 is 0\n", + (conf->tab_ok ? "\t" : "")); + return error_value(E_NO_CUSTOM); + } + /* * no such custom function */ @@ -107,6 +117,15 @@ 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 is != 0\n", + (conf->tab_ok ? "\t" : "")); + } return error_value(E_NO_CUSTOM); #endif /* CUSTOM */ diff --git a/custom.h b/custom.h index a694c3b..42d246f 100644 --- a/custom.h +++ b/custom.h @@ -73,6 +73,7 @@ struct custom { * * These are the required interfaces. The dummy.c stubs these interfaces too. */ +EXTERN int custtbl_allowed; /* 1 ==> CUSTOM defined, 0 ==> CUSTOM undefined */ 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 */ diff --git a/custom/c_argv.c b/custom/c_argv.c index c9bb6e2..8497eaa 100644 --- a/custom/c_argv.c +++ b/custom/c_argv.c @@ -1,7 +1,7 @@ /* * c_argv - a custom function display info about its args * - * Copyright (C) 1999-2006,2021 Landon Curt Noll + * Copyright (C) 1999-2006,2021,2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -32,7 +32,7 @@ #if defined(CUSTOM) int c_argv_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_argv_allowed = 0; /* CUSTOM defined */ +int c_argv_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/c_devnull.c b/custom/c_devnull.c index 89d2e40..dbb11b5 100644 --- a/custom/c_devnull.c +++ b/custom/c_devnull.c @@ -1,7 +1,7 @@ /* * c_devnull - a custom function that does nothing * - * Copyright (C) 1999-2004,2021 Landon Curt Noll + * Copyright (C) 1999-2004,2021,2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -32,7 +32,7 @@ #if defined(CUSTOM) int c_devnull_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_devnull_allowed = 0; /* CUSTOM defined */ +int c_devnull_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/c_help.c b/custom/c_help.c index 52eb1d0..538a707 100644 --- a/custom/c_help.c +++ b/custom/c_help.c @@ -1,7 +1,7 @@ /* * c_help - custom help function * - * Copyright (C) 1999-2004,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2004,2021-2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -32,7 +32,7 @@ #if defined(CUSTOM) int c_help_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_help_allowed = 0; /* CUSTOM defined */ +int c_help_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/c_pmodm127.c b/custom/c_pmodm127.c index 6ea19f1..5201f95 100644 --- a/custom/c_pmodm127.c +++ b/custom/c_pmodm127.c @@ -1,7 +1,7 @@ /* * c_pmodm127 - calculate q mod 2^(2^127-1) * - * Copyright (C) 2004-2007,2021,2022 Landon Curt Noll + * Copyright (C) 2004-2007,2021-2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -31,7 +31,7 @@ #if defined(CUSTOM) int c_pmodm127_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_pmodm127_allowed = 0; /* CUSTOM defined */ +int c_pmodm127_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/c_pzasusb8.c b/custom/c_pzasusb8.c index 4b50503..7db143e 100644 --- a/custom/c_pzasusb8.c +++ b/custom/c_pzasusb8.c @@ -1,7 +1,7 @@ /* * c_pzasusb8 - print numerator as a string of USB8s * - * Copyright (C) 1999-2004,2021,2022 Ernest Bowen + * Copyright (C) 1999-2004,2021-2023 Ernest Bowen * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -31,7 +31,7 @@ #if defined(CUSTOM) int c_pzasusb8_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_pzasusb8_allowed = 0; /* CUSTOM defined */ +int c_pzasusb8_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/c_register.c b/custom/c_register.c index f841fa4..72553c3 100644 --- a/custom/c_register.c +++ b/custom/c_register.c @@ -1,7 +1,7 @@ /* * c_register - set or print a custom register value * - * Copyright (C) 2007,2021,2022 Landon Curt Noll + * Copyright (C) 2007,2021-2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -32,7 +32,7 @@ #if defined(CUSTOM) int c_register_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_register_allowed = 0; /* CUSTOM defined */ +int c_register_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/c_sysinfo.c b/custom/c_sysinfo.c index 2cbf4e6..cefbeb3 100644 --- a/custom/c_sysinfo.c +++ b/custom/c_sysinfo.c @@ -1,7 +1,7 @@ /* * c_sysinfo - names and values of selected #defines * - * Copyright (C) 1999-2007,2021,2022 Landon Curt Noll + * Copyright (C) 1999-2007,2021-2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -32,7 +32,7 @@ #if defined(CUSTOM) int c_sysinfo_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_sysinfo_allowed = 0; /* CUSTOM defined */ +int c_sysinfo_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ diff --git a/custom/custtbl.c b/custom/custtbl.c index f312a22..71c6b25 100644 --- a/custom/custtbl.c +++ b/custom/custtbl.c @@ -1,7 +1,7 @@ /* * custtbl - custom interface table * - * Copyright (C) 1999-2007,2021 Landon Curt Noll + * Copyright (C) 1999-2007,2021,2023 Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License @@ -24,6 +24,18 @@ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ + +/* + * 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 #include "../have_const.h" @@ -35,8 +47,7 @@ /* - * NOTE: See the file CUSTOM for instructions on how to add - * custom functions. + * NOTE: See the file HOW_TO_ADD for instructions on how to add custom functions. */