'make lean' target?

61 views
Skip to first unread message

Jeffrey Walton

unread,
Jan 4, 2016, 1:59:35 AM1/4/16
to Crypto++ Users
Hi Everyone,

I've noticed this comes up on occasion.... Many folks want a smaller library, but they don't quite know the steps they need to perform.

To help them along, I was thinking we could add a 'make lean' target to the makefile with the various options enabled for the platform. They will still need to link their final executable with either '-Wl,--gc-sections' (Unix and Linux compatibes) or '-Wl,-dead_strip' (OS X), but the target should help them along when using libcryptopp.a.

Any thoughts?

Jeff

Mobile Mouse

unread,
Jan 4, 2016, 6:48:12 AM1/4/16
to Jeffrey Walton, Crypto++ Users
Considering how the library is designed, I'm not sure how much work it would be. But it wood be great if we could offer that target. 

Sent from my iPad
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-user...@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Walton

unread,
Jan 4, 2016, 1:06:19 PM1/4/16
to Crypto++ Users, nolo...@gmail.com


On Monday, January 4, 2016 at 6:48:12 AM UTC-5, Mouse wrote:
Considering how the library is designed, I'm not sure how much work it would be. But it wood be great if we could offer that target.

I think this is an easy cut-in. Something like below, which looks for the 'lean' MAKECMDGOALS and adds the appropriate flags.

Below are the results I am seeing on OS X 10.9, but there's nothing surprising about the results. cryptest.exe does not really have an opportunity to discard anything because it tries to exercise everything :) And libcryptopp.{so|dylib} can't really discard much of anything because it may be needed.

However, when we compile and link a smaller program like:

  int main( int, char** ) {

    Integer j("100000000000000000000000000000000");
    j %= 1999;

    cout << "j: " << j << endl;

    return 0;
  }

Then we get a significant savings:

Lean:
  $ ls -l integer.exe
  -rwx------  1 jwalton  staff  162012 Jan  4 13:00 integer.exe

Normal:
  $ ls -l integer.exe
  -rwx------  1 jwalton  staff  2636952 Jan  4 13:02 integer.exe

*****

Lean:
  $ ls -l cryptest.exe libcryptopp.dylib
  -rwx------  1 jwalton  staff  9023592 Jan  4 12:51 cryptest.exe
  -rwx------  1 jwalton  staff  4828076 Jan  4 12:51 libcryptopp.dylib

Normal:
  $ ls -l cryptest.exe libcryptopp.dylib
  -rwx------  1 jwalton  staff  9580856 Jan  4 12:45 cryptest.exe
  -rwx------  1 jwalton  staff  4832404 Jan  4 12:46 libcryptopp.dylib

*****

$ cat git.diff
diff --git a/GNUmakefile b/GNUmakefile
index bf2fa54..af2b557 100755
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -155,6 +155,25 @@ endif

+# Remove dead code for lean target
+ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
+ ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
+  CXXFLAGS += -ffunction-sections
+ endif # CXXFLAGS
+ ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
+  CXXFLAGS += -fdata-sections
+ endif # CXXFLAGS
+ ifneq ($(IS_DARWIN),0)
+  ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
+   LDFLAGS += -Wl,-dead_strip
+  endif
+ else # BSD, Linux and Unix
+  ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
+   LDFLAGS += -Wl,--gc-sections
+  endif
+ endif
+endif #
+

@@ -336,6 +355,9 @@ deps GNUmakefile.deps:
 .PHONY: asan ubsan align aligned
 asan ubsan align aligned: libcryptopp.a cryptest.exe
 
+.PHONY: lean
+lean: libcryptopp.a cryptest.exe
+

jh...@emocha.com

unread,
Jan 4, 2016, 1:25:36 PM1/4/16
to Crypto++ Users
I think this would be an awesome help! Especially for those of us doing multi-platform development not privy to each platform's flags.

Jeffrey Walton

unread,
Jan 4, 2016, 2:22:34 PM1/4/16
to Crypto++ Users


On Monday, January 4, 2016 at 1:25:36 PM UTC-5, jh...@emocha.com wrote:
I think this would be an awesome help! Especially for those of us doing multi-platform development not privy to each platform's flags.

I actually had you in mind :) And others, too, since it comes up on occasion.

The changes are being tested now. I'll have the results in 3 or 4 hours.

Jeff

Jeffrey Walton

unread,
Jan 4, 2016, 6:30:52 PM1/4/16
to Crypto++ Users

This tested OK. It was committed at https://github.com/weidai11/cryptopp/commit/9696b9e5e79ff18a30956467497e757562e26310 .

To use it to build the library, just issue 'make lean'. It builds the static library, the shared library and cryptest.exe. The static library will be ready for dead code removal.

You will still need to link your application to the library, and use -Wl,--gc-sections (Linux and Unix) or -Wl,-dead_strip (OS X), to get the benefits.

Jeff

jh...@emocha.com

unread,
Jan 5, 2016, 12:43:52 PM1/5/16
to Crypto++ Users
I'll probably have some time allotted towards the end of this week, I'll give it a look-see. 
Reply all
Reply to author
Forward
0 new messages