0

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?

abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • To see where the difference is, you could try "objdump -x" on the two files, and compare the results. That should allow you to see which section is a different size, then you can use other objdump options to see what the difference is. Once you know that, you may be able to get the compiler/linker to do the same things in both cases. – sheltond Aug 01 '17 at 15:24

1 Answers1

0

Thanks to the hint, I ran this:

objdump -xD res1.so > res1.objdump
objdump -xD res2.so > res2.objdump
diffuse res1.objdump res2.objdump

Which lead me to using this for the strip command:

strip --remove-section=.note.gnu.build-id

Now the binaries are the same.

abo-abo
  • 20,038
  • 3
  • 50
  • 71