static bool
write_build_id (bfd *abfd)
{
- struct pe_tdata *t = pe_data (abfd);
+ struct pe_tdata *td = pe_data (abfd);
asection *asec;
struct bfd_link_order *link_order = NULL;
unsigned char *contents;
{
if (l->type == bfd_indirect_link_order)
{
- if (l->u.indirect.section == t->build_id.sec)
+ if (l->u.indirect.section == td->build_id.sec)
{
link_order = l;
break;
return true;
}
- if (t->build_id.sec->contents == NULL)
- t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
- contents = t->build_id.sec->contents;
+ if (td->build_id.sec->contents == NULL)
+ td->build_id.sec->contents = xmalloc (td->build_id.sec->size);
+ contents = td->build_id.sec->contents;
- build_id_size = compute_build_id_size (t->build_id.style);
+ build_id_size = compute_build_id_size (td->build_id.style);
build_id = xmalloc (build_id_size);
- generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
+ generate_build_id (abfd, td->build_id.style, pecoff_checksum_contents,
+ build_id, build_id_size);
- bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
+ bfd_vma ib = td->pe_opthdr.ImageBase;
#ifdef PDB_H
if (pdb_name)
cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
cvinfo.Age = 1;
- /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
+ /* Zero pad or truncate the generated build_id to fit in the
+ CodeView record. */
memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
- memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
- ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
+ memcpy (&(cvinfo.Signature), build_id,
+ (build_id_size > CV_INFO_SIGNATURE_LENGTH
+ ? CV_INFO_SIGNATURE_LENGTH : build_id_size));
free (build_id);
return 0;
/* Record the location of the debug directory in the data directory. */
- pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
- = asec->vma - ib + link_order->offset;
- pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
+ td->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
+ = asec->vma - ib + link_order->offset;
+ td->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
= sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
return true;
s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
if (s != NULL)
{
- struct pe_tdata *t = pe_data (link_info.output_bfd);
- t->build_id.after_write_object_contents = &write_build_id;
- t->build_id.style = emit_build_id;
- t->build_id.sec = s;
+ struct pe_tdata *td = pe_data (link_info.output_bfd);
+ td->build_id.after_write_object_contents = &write_build_id;
+ td->build_id.style = emit_build_id;
+ td->build_id.sec = s;
/* Section is a fixed size:
One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
pointing at a CV_INFO_PDB70 record containing the build-id, followed by
PdbFileName if relevant. */
- s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
- + sizeof (CV_INFO_PDB70) + 1;
+ s->size = (sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
+ + sizeof (CV_INFO_PDB70) + 1);
#ifdef PDB_H
if (pdb_name)
static bool
write_build_id (bfd *abfd)
{
- struct pe_tdata *t = pe_data (abfd);
+ struct pe_tdata *td = pe_data (abfd);
asection *asec;
struct bfd_link_order *link_order = NULL;
unsigned char *contents;
{
if (l->type == bfd_indirect_link_order)
{
- if (l->u.indirect.section == t->build_id.sec)
+ if (l->u.indirect.section == td->build_id.sec)
{
link_order = l;
break;
return true;
}
- if (t->build_id.sec->contents == NULL)
- t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
- contents = t->build_id.sec->contents;
+ if (td->build_id.sec->contents == NULL)
+ td->build_id.sec->contents = xmalloc (td->build_id.sec->size);
+ contents = td->build_id.sec->contents;
- build_id_size = compute_build_id_size (t->build_id.style);
+ build_id_size = compute_build_id_size (td->build_id.style);
build_id = xmalloc (build_id_size);
- generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
+ generate_build_id (abfd, td->build_id.style, pecoff_checksum_contents,
+ build_id, build_id_size);
- bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
+ bfd_vma ib = td->pe_opthdr.ImageBase;
#ifdef PDB_H
if (pdb_name)
struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
_bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
- /* Write the debug directory enttry */
+ /* Write the debug directory entry. */
if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
return 0;
cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
cvinfo.Age = 1;
- /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
+ /* Zero pad or truncate the generated build_id to fit in the
+ CodeView record. */
memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
- memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
- ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
+ memcpy (&(cvinfo.Signature), build_id,
+ (build_id_size > CV_INFO_SIGNATURE_LENGTH
+ ? CV_INFO_SIGNATURE_LENGTH : build_id_size));
free (build_id);
return 0;
/* Record the location of the debug directory in the data directory. */
- pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
- = asec->vma - ib + link_order->offset;
- pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
+ td->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
+ = asec->vma - ib + link_order->offset;
+ td->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
= sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
return true;
s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
if (s != NULL)
{
- struct pe_tdata *t = pe_data (link_info.output_bfd);
- t->build_id.after_write_object_contents = &write_build_id;
- t->build_id.style = emit_build_id;
- t->build_id.sec = s;
+ struct pe_tdata *td = pe_data (link_info.output_bfd);
+ td->build_id.after_write_object_contents = &write_build_id;
+ td->build_id.style = emit_build_id;
+ td->build_id.sec = s;
/* Section is a fixed size:
One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
static void
ld_cleanup (void)
{
- bfd_cache_close_all ();
+ bfd *ibfd, *inext;
+ if (link_info.output_bfd)
+ bfd_close_all_done (link_info.output_bfd);
+ for (ibfd = link_info.input_bfds; ibfd; ibfd = inext)
+ {
+ inext = ibfd->link.next;
+ bfd_close_all_done (ibfd);
+ }
#if BFD_SUPPORTS_PLUGINS
plugin_call_cleanup ();
#endif
}
else
{
- if (!bfd_close (link_info.output_bfd))
+ bfd *obfd = link_info.output_bfd;
+ link_info.output_bfd = NULL;
+ if (!bfd_close (obfd))
einfo (_("%F%P: %s: final close failed: %E\n"), output_filename);
/* If the --force-exe-suffix is enabled, and we're making an
fflush (stderr);
}
- /* Prevent ld_cleanup from doing anything, after a successful link. */
+ /* Prevent ld_cleanup from deleting the output file. */
output_filename = NULL;
xexit (0);