Skip to content

Commit

Permalink
add -dead_strip_dylibs by default to the macOS linker
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
lcn2 committed Aug 14, 2023
1 parent ee900ec commit e0df164
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 1 addition & 8 deletions Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
19 changes: 19 additions & 0 deletions custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions custom/c_argv.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions custom/c_devnull.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions custom/c_help.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions custom/c_pmodm127.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions custom/c_pzasusb8.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions custom/c_register.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions custom/c_sysinfo.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */


Expand Down
17 changes: 14 additions & 3 deletions custom/custtbl.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <unistd.h>

#include "../have_const.h"
Expand All @@ -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.
*/


Expand Down

0 comments on commit e0df164

Please sign in to comment.