@@ -3711,9 +3711,22 @@ let writePdb (
37113711 // Used to capture the pdb file bytes in the case we're generating in-memory
37123712 let mutable pdbBytes = None
37133713
3714+ let signImage () =
3715+ // Sign the binary. No further changes to binary allowed past this point!
3716+ match signer with
3717+ | None -> ()
3718+ | Some s ->
3719+ use fs = reopenOutput()
3720+ try
3721+ s.SignStream fs
3722+ with exn ->
3723+ failwith ( $" Warning: A call to SignFile failed ({exn.Message})" )
3724+ reportTime showTimes " Signing Image"
3725+
37143726 // Now we've done the bulk of the binary, do the PDB file and fixup the binary.
37153727 match pdbfile with
3716- | None -> ()
3728+ | None -> signImage ()
3729+
37173730 | Some pdbfile ->
37183731 let idd =
37193732 match pdbInfoOpt with
@@ -3763,28 +3776,14 @@ let writePdb (
37633776 os2.BaseStream.Seek ( int64 ( textV2P i.iddChunk.addr), SeekOrigin.Begin) |> ignore
37643777 if i.iddChunk.size < i.iddData.Length then failwith " Debug data area is not big enough. Debug info may not be usable"
37653778 writeBytes os2 i.iddData
3779+ reportTime showTimes " Finalize PDB"
3780+ signImage ()
37663781 os2.Dispose()
37673782 with exn ->
37683783 failwith ( " Error while writing debug directory entry: " + exn.Message)
37693784 ( try os2.Dispose(); FileSystem.FileDeleteShim outfile with _ -> ())
37703785 reraise()
37713786
3772- reportTime showTimes " Finalize PDB"
3773-
3774- // Sign the binary. No further changes to binary allowed past this point!
3775- match signer with
3776- | None -> ()
3777- | Some s ->
3778- try
3779- s.SignFile outfile
3780- s.Close()
3781- with exn ->
3782- failwith ( " Warning: A call to SignFile failed (" + exn.Message+ " )" )
3783- ( try s.Close() with _ -> ())
3784- ( try FileSystem.FileDeleteShim outfile with _ -> ())
3785- ()
3786-
3787- reportTime showTimes " Signing Image"
37883787 pdbBytes
37893788
37903789type options =
@@ -4528,7 +4527,7 @@ let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
45284527 reraise()
45294528
45304529 let reopenOutput () =
4531- FileSystem.OpenFileForWriteShim( options.outfile, FileMode.Open, FileAccess.Write , FileShare.Read)
4530+ FileSystem.OpenFileForWriteShim( options.outfile, FileMode.Open, FileAccess.ReadWrite , FileShare.Read)
45324531
45334532 writePdb ( options.dumpDebugInfo,
45344533 options.showTimes,
@@ -4558,7 +4557,9 @@ let writeBinaryInMemory (options: options, modul, normalizeAssemblyRefs) =
45584557 let pdbData , pdbInfoOpt , debugDirectoryChunk , debugDataChunk , debugChecksumPdbChunk , debugEmbeddedPdbChunk , debugDeterministicPdbChunk , textV2P , _mappings =
45594558 writeBinaryAux( stream, options, modul, normalizeAssemblyRefs)
45604559
4561- let reopenOutput () = stream
4560+ let reopenOutput () =
4561+ stream.Seek( 0 , SeekOrigin.Begin) |> ignore
4562+ stream
45624563
45634564 let pdbBytes =
45644565 writePdb ( options.dumpDebugInfo,
0 commit comments