Skip to content

Commit

Permalink
bintools-wrapper: drop postLinkSignHook
Browse files Browse the repository at this point in the history
When the linker signs a Mach-O binary, it sets a flag in the signature’s code directory indicating that the signature was generated by a linker. Tools such as `strip` and `install_name_tool` read this flag and will
update ad hoc signatures after they perform their modifications.

The updated l64 supports signing binaries automatically. Both the updated cctools and LLVM will check for the linker-signed flag and resign binaries they modify automatically when it’s present. Given that, use of postLinkSignHook is unnecessary and potentially harmful.

In particular, if the hook is used and an unwrapped `strip` or `install_name_tool` is on the user’s path, they will not automatically update an ad hoc signature. Instead, they will issue a warning and create a binary with a broken signature.

It is more robust to let the tools handled this since the only time a signature would not be linker-signed is when the user is manually invoking `codesign` (or another tool such as `sigtool` or `rcodesign`), which by nature of the invocation updates the signature to a valid  one.

Since `strip` no longer needs to be wrapped for code-signing, binutils-wrapper now uses the GNU strip wrapper on Darwin.

Fixes #208951.
  • Loading branch information
reckenrode committed Jul 13, 2024
1 parent 10c87ee commit c922cb2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
23 changes: 1 addition & 22 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
(!(targetPlatform.isAarch && targetPlatform.isStatic))
])
]) "pie"

# Darwin code signing support utilities
, postLinkSignHook ? null, signingUtils ? null
}:

assert propagateDoc -> bintools ? man;
Expand Down Expand Up @@ -357,7 +354,7 @@ stdenvNoCC.mkDerivation {
##

# TODO(@sternenseemann): make a generic strip wrapper?
+ optionalString (bintools.isGNU or false) ''
+ optionalString (bintools.isGNU or false || bintools.isCCTools or false) ''
wrap ${targetPrefix}strip ${./gnu-binutils-strip-wrapper.sh} \
"${bintools_bin}/bin/${targetPrefix}strip"
''
Expand Down Expand Up @@ -396,24 +393,6 @@ stdenvNoCC.mkDerivation {
''
)

##
## Code signing on Apple Silicon
##
+ optionalString (targetPlatform.isDarwin && targetPlatform.isAarch64) ''
echo 'source ${postLinkSignHook}' >> $out/nix-support/post-link-hook
export signingUtils=${signingUtils}
wrap \
${targetPrefix}install_name_tool \
${./darwin-install_name_tool-wrapper.sh} \
"${bintools_bin}/bin/${targetPrefix}install_name_tool"
wrap \
${targetPrefix}strip ${./darwin-strip-wrapper.sh} \
"${bintools_bin}/bin/${targetPrefix}strip"
''

##
## Extra custom steps
##
Expand Down
1 change: 0 additions & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16774,7 +16774,6 @@ with pkgs;
noLibc = (self.libc == null);

inherit bintools libc;
inherit (darwin) postLinkSignHook signingUtils;
} // extraArgs; in self);

yaml-language-server = callPackage ../development/tools/language-servers/yaml-language-server { };
Expand Down

0 comments on commit c922cb2

Please sign in to comment.