I'm trying to improve the build time on a 1GB shared library that's built from ~400 dependencies and then stripped to 100MB.
The dependencies are not stripped, so I'm thinking it might build faster if I pre-strip the dependencies before (or simply build them without -g
from the start).
Testing this library is a big effort, but I can avoid testing if the new build process produces exactly the same binary.
I've made a small test for this, with just one C++ file, lib.cc
:
int lib1_f1(int x) {
return x + x;
}
int lib1_f2(int x) {
return x*x;
}
And here's a Makefile:
diff: res1.so res2.so
./hexdump-diffuse $^
res1.so: lib.cc.o.1
g++ -fPIC -shared -o $@ $^
strip $@
res2.so: lib.cc.o.2
g++ -fPIC -shared -o $@ $^
strip $@
# with -g
%.cc.o.1: %.cc
g++ -g -O2 -std=c++11 -c $^ -o $@
# without -g
%.cc.o.2: %.cc
g++ -O2 -std=c++11 -c $^ -o $@
install-tools:
sudo apt-get install diffuse bsdmainutils
.PHONY: install-tools diff
Here's a script I use for comparing binaries:
#!/bin/bash
hexdump -v -C $1 > /tmp/mydiff.1
hexdump -v -C $2 > /tmp/mydiff.2
diffuse /tmp/mydiff.1 /tmp/mydiff.2
The difference between the binaries I'm getting is around 10 bytes. Is there any way to avoid this difference, and have both methods produce identical binaries?
Thanks to the hint, I ran this:
Which lead me to using this for the strip command:
Now the binaries are the same.