Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use -oso_prefix to relativize object file paths in debug info with ld64 on macOS #299904

Open
lf- opened this issue Mar 29, 2024 · 2 comments
Open
Labels
6.topic: darwin Running or building packages on Darwin 6.topic: reproducible builds 6.topic: stdenv Standard environment significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.

Comments

@lf-
Copy link
Member

lf- commented Mar 29, 2024

Issue description

Currently absolute paths leak into linked binaries on macOS inside the OSO debug info section, making a lot of binaries nonreproducible since /private/tmp/nix-build-dskfdsjlksdfl/ absolutely can arbitrarily vary between runs. This can be fixed with a ld64 feature called -oso_prefix, about which you can learn more here: https://milen.me/writings/apple-linker-ld64-deterministic-builds-oso-prefix/

@lf- lf- added 6.topic: darwin Running or building packages on Darwin 6.topic: reproducible builds 6.topic: stdenv Standard environment labels Mar 29, 2024
@lf- lf- added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Apr 6, 2024
@RaitoBezarius
Copy link
Member

cc @reckenrode I suppose

@reckenrode
Copy link
Contributor

I tried building hello manually (see below), and it seems to work. It probably should be added an extra input to the stdenv, which would allow it to be dropped when cross-compiling.

$ export NIX_LDFLAGS+=" -oso_prefix $(realpath "$NIX_BUILD_TOP")/"
$ genericBuild
$ nm -a $out/bin/hello | rg OSO
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(c-strcasecmp.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(close-stream.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(closeout.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(error.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(exitfail.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(fpending.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(getopt.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(getopt1.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(localcharset.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(progname.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(propername.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(quotearg.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(version-etc-fsf.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(version-etc.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(xalloc-die.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/./lib/libhello.a(xmalloc.o)
0000000000000000 - 00 0001   OSO hello-2.12.1/src/hello.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 6.topic: reproducible builds 6.topic: stdenv Standard environment significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.
Projects
None yet
Development

No branches or pull requests

3 participants