On 11/27/21 23:27, Tom Kacvinsky wrote:
>
>
> On Sat, Nov 27, 2021 at 5:05 PM Jacob Kroon via Gcc-help
> <gcc-help@xxxxxxxxxxx <mailto:gcc-help@xxxxxxxxxxx>> wrote:
>
> Hi,
>
> As part of an effort to make binaries reproducible regardless of their
> build path, I need to enforce the same size of the RUNPATH entry in the
> dynamic section during linking, even though I don't fill it completely.
> Is it possible to give some flag to gnu ld that allows me to set it to a
> specific size ? Or is there a way to patch the elf file after linking,
> so that the entry has a specified size ?
>
>
> This tool doesn't quite do what you'd like (set a fixed size for the
> RUNPATH entry in the dynamic table), but I have found it quite
> useful:
>
> https://github.com/NixOS/patchelf <https://github.com/NixOS/patchelf>
>
Thanks for the tip, but I can't get patchelf to produce identical
binaries, unless the rpath is already padded up to a common size in both
of the binaries.
I've attached a small Makefile I use to test with.
Jacob
workdir := $(shell mktemp -d)
all : compare
compare : $(workdir)/test-a $(workdir)/test-b
diffoscope $(workdir)/test-a $(workdir)/test-b
rpath-a = "/foobar "
rpath-b = "/a/much/longer/foobar"
$(workdir)/test-% : $(workdir)/%/test.c
gcc -O2 $< -o $@ -Wl,--build-id=none -Wl,--rpath=$(rpath-$*)
#chrpath -r "replacement" $@
patchelf --set-rpath "my-new-rpath" $@
define sourcecode
#include <stdio.h>
int main() {
printf("HelloWorld");
return 0;
}
endef
define newline
endef
$(workdir)/%/test.c :
mkdir -p $(dir $@)
echo -e '$(subst $(newline),\n,$(sourcecode))' > $@