Skip to content

Commit 74a1e31

Browse files
committed
builder: stabilize macOS debug compiler signatures
1 parent 2122b87 commit 74a1e31

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

vlib/v/builder/cc.v

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,10 +1143,13 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
11431143
ccoptions.linker_flags << '-Wl,-export_dynamic' // clang for mac needs export_dynamic instead of -rdynamic
11441144
if v.pref.building_v && ccoptions.cc == .clang {
11451145
// ld64 otherwise lets temporary object and output paths perturb the
1146-
// content-derived UUID and the ad-hoc code signature.
1146+
// content-derived UUID and its provisional ad-hoc code signature.
1147+
// Suppress that signature so every linker version leaves the same
1148+
// unsigned layout for the normalized post-link signature below.
11471149
ccoptions.args << os.quoted_path('-ffile-prefix-map=${v.out_name_c}=<generated-c>')
11481150
ccoptions.linker_flags << '-Wl,-reproducible'
11491151
ccoptions.linker_flags << '-Wl,-final_output,v-compiler'
1152+
ccoptions.linker_flags << '-Wl,-no_adhoc_codesign'
11501153
}
11511154
} else {
11521155
if v.pref.ccompiler != 'x86_64-w64-mingw32-gcc' {
@@ -2374,9 +2377,8 @@ fn (v &Builder) finalize_reproducible_macos_debug_compiler() {
23742377
verror('could not find `codesign` to finalize the reproducible macOS compiler binary')
23752378
return
23762379
}
2377-
// Removing the linker's signature first also removes its output-name-dependent
2378-
// allocation, so the replacement has the same layout for every output path.
2379-
os.execute('${os.quoted_path(codesign_path)} --remove-signature ${os.quoted_path(v.pref.out_name)}')
2380+
// The linker leaves this compiler unsigned; add one normalized signature with
2381+
// a stable identifier so its layout and contents do not depend on the output path.
23802382
codesign_result :=
23812383
os.execute('${os.quoted_path(codesign_path)} --force --sign - --identifier org.vlang.v ${os.quoted_path(v.pref.out_name)}')
23822384
if codesign_result.exit_code != 0 {

vlib/v/builder/macos_reproducible_compiler_test.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ fn test_macos_debug_compiler_build_is_reproducible() {
172172
assert cdebug_hashes[0] == cdebug_hashes[1], cdebug_hashes.str()
173173

174174
first_output := os.join_path(test_dir, 'first')
175+
first_codesign_result :=
176+
os.execute('codesign --verify --strict ${os.quoted_path(first_output)}')
177+
assert first_codesign_result.exit_code == 0, first_codesign_result.output
175178
nm_result := os.execute('nm -ap ${os.quoted_path(first_output)}')
176179
assert nm_result.exit_code == 0, nm_result.output
177180
oso_lines := nm_result.output.split_into_lines().filter(it.contains(' OSO '))

0 commit comments

Comments
 (0)