@@ -3714,9 +3714,22 @@ let writePdb (
37143714 // Used to capture the pdb file bytes in the case we're generating in-memory
37153715 let mutable pdbBytes = None
37163716
3717+ let signImage () =
3718+ // Sign the binary. No further changes to binary allowed past this point!
3719+ match signer with
3720+ | None -> ()
3721+ | Some s ->
3722+ use fs = reopenOutput()
3723+ try
3724+ s.SignStream fs
3725+ with exn ->
3726+ failwith ( $" Warning: A call to SignFile failed ({exn.Message})" )
3727+ reportTime showTimes " Signing Image"
3728+
37173729 // Now we've done the bulk of the binary, do the PDB file and fixup the binary.
37183730 match pdbfile with
3719- | None -> ()
3731+ | None -> signImage ()
3732+
37203733 | Some pdbfile ->
37213734 let idd =
37223735 match pdbInfoOpt with
@@ -3766,28 +3779,14 @@ let writePdb (
37663779 os2.BaseStream.Seek ( int64 ( textV2P i.iddChunk.addr), SeekOrigin.Begin) |> ignore
37673780 if i.iddChunk.size < i.iddData.Length then failwith " Debug data area is not big enough. Debug info may not be usable"
37683781 writeBytes os2 i.iddData
3782+ reportTime showTimes " Finalize PDB"
3783+ signImage ()
37693784 os2.Dispose()
37703785 with exn ->
37713786 failwith ( " Error while writing debug directory entry: " + exn.Message)
37723787 ( try os2.Dispose(); FileSystem.FileDeleteShim outfile with _ -> ())
37733788 reraise()
37743789
3775- reportTime showTimes " Finalize PDB"
3776-
3777- // Sign the binary. No further changes to binary allowed past this point!
3778- match signer with
3779- | None -> ()
3780- | Some s ->
3781- try
3782- s.SignFile outfile
3783- s.Close()
3784- with exn ->
3785- failwith ( " Warning: A call to SignFile failed (" + exn.Message+ " )" )
3786- ( try s.Close() with _ -> ())
3787- ( try FileSystem.FileDeleteShim outfile with _ -> ())
3788- ()
3789-
3790- reportTime showTimes " Signing Image"
37913790 pdbBytes
37923791
37933792type options =
@@ -4531,7 +4530,7 @@ let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
45314530 reraise()
45324531
45334532 let reopenOutput () =
4534- FileSystem.OpenFileForWriteShim( options.outfile, FileMode.Open, FileAccess.Write , FileShare.Read)
4533+ FileSystem.OpenFileForWriteShim( options.outfile, FileMode.Open, FileAccess.ReadWrite , FileShare.Read)
45354534
45364535 writePdb ( options.dumpDebugInfo,
45374536 options.showTimes,
@@ -4561,7 +4560,9 @@ let writeBinaryInMemory (options: options, modul, normalizeAssemblyRefs) =
45614560 let pdbData , pdbInfoOpt , debugDirectoryChunk , debugDataChunk , debugChecksumPdbChunk , debugEmbeddedPdbChunk , debugDeterministicPdbChunk , textV2P , _mappings =
45624561 writeBinaryAux( stream, options, modul, normalizeAssemblyRefs)
45634562
4564- let reopenOutput () = stream
4563+ let reopenOutput () =
4564+ stream.Seek( 0 , SeekOrigin.Begin) |> ignore
4565+ stream
45654566
45664567 let pdbBytes =
45674568 writePdb ( options.dumpDebugInfo,
0 commit comments