1 diff -Nur a/bfd/libpei.h b/bfd/libpei.h 2 --- a/bfd/libpei.h 2015-10-21 11:59:30.181317175 -0700 3 +++ b/bfd/libpei.h 2015-10-22 11:42:59.840341121 -0700 4 @@ -238,6 +238,7 @@ 5 #define _bfd_XXi_swap_debugdir_in _bfd_pex64i_swap_debugdir_in 6 #define _bfd_XXi_swap_debugdir_out _bfd_pex64i_swap_debugdir_out 7 #define _bfd_XXi_write_codeview_record _bfd_pex64i_write_codeview_record 8 +#define _bfd_XXi_get_codeview_pdb_name _bfd_pex64i_get_codeview_pdb_name 9 10 #elif defined COFF_WITH_pep 11 12 @@ -272,6 +273,7 @@ 13 #define _bfd_XXi_swap_debugdir_in _bfd_pepi_swap_debugdir_in 14 #define _bfd_XXi_swap_debugdir_out _bfd_pepi_swap_debugdir_out 15 #define _bfd_XXi_write_codeview_record _bfd_pepi_write_codeview_record 16 +#define _bfd_XXi_get_codeview_pdb_name _bfd_pepi_get_codeview_pdb_name 17 18 #else /* !COFF_WITH_pep */ 19 20 @@ -306,6 +308,7 @@ 21 #define _bfd_XXi_swap_debugdir_in _bfd_pei_swap_debugdir_in 22 #define _bfd_XXi_swap_debugdir_out _bfd_pei_swap_debugdir_out 23 #define _bfd_XXi_write_codeview_record _bfd_pei_write_codeview_record 24 +#define _bfd_XXi_get_codeview_pdb_name _bfd_pei_get_codeview_pdb_name 25 26 #endif /* !COFF_WITH_pep */ 27 28 @@ -351,6 +354,7 @@ 29 void _bfd_XXi_swap_debugdir_in (bfd *, void *, void *); 30 unsigned _bfd_XXi_swap_debugdir_out (bfd *, void *, void *); 31 unsigned _bfd_XXi_write_codeview_record (bfd *, file_ptr, CODEVIEW_INFO *); 32 +const char* _bfd_XXi_get_codeview_pdb_name (bfd *); 33 34 /* The following are needed only for ONE of pe or pei, but don't 35 otherwise vary; peicode.h fixes up ifdefs but we provide the 36 diff -Nur a/bfd/peXXigen.c b/bfd/peXXigen.c 37 --- a/bfd/peXXigen.c 2015-10-21 20:04:27.793914713 -0700 38 +++ b/bfd/peXXigen.c 2015-10-22 12:20:31.644941168 -0700 39 @@ -1135,19 +1135,32 @@ 40 return sizeof (struct external_IMAGE_DEBUG_DIRECTORY); 41 } 42 43 + 44 +const char * 45 +_bfd_XXi_get_codeview_pdb_name (bfd * abfd) 46 +{ 47 + char * filename_ptr = bfd_get_filename(abfd); 48 + char * last_dir_separator = strrchr(filename_ptr, '/'); 49 + if (last_dir_separator != NULL) { 50 + filename_ptr = last_dir_separator+1; 51 + } 52 + return filename_ptr; 53 +} 54 + 55 static CODEVIEW_INFO * 56 -_bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length, CODEVIEW_INFO *cvinfo) 57 +_bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length, CODEVIEW_INFO * cvinfo) 58 { 59 - char buffer[256+1]; 60 61 - if (bfd_seek (abfd, where, SEEK_SET) != 0) 62 + char buffer [length]; 63 + 64 + if (!cvinfo) 65 return NULL; 66 67 - if (bfd_bread (buffer, 256, abfd) < 4) 68 + if (bfd_seek (abfd, where, SEEK_SET) != 0) 69 return NULL; 70 71 - /* Ensure null termination of filename. */ 72 - buffer[256] = '\0'; 73 + if (bfd_bread (buffer, length, abfd) < 4) 74 + return NULL; 75 76 cvinfo->CVSignature = H_GET_32(abfd, buffer); 77 cvinfo->Age = 0; 78 @@ -1168,7 +1181,7 @@ 79 memcpy (&(cvinfo->Signature[8]), &(cvinfo70->Signature[8]), 8); 80 81 cvinfo->SignatureLength = CV_INFO_SIGNATURE_LENGTH; 82 - // cvinfo->PdbFileName = cvinfo70->PdbFileName; 83 + strcpy(cvinfo->PdbFileName, cvinfo70->PdbFileName); 84 85 return cvinfo; 86 } 87 @@ -1190,7 +1203,9 @@ 88 unsigned int 89 _bfd_XXi_write_codeview_record (bfd * abfd, file_ptr where, CODEVIEW_INFO *cvinfo) 90 { 91 - unsigned int size = sizeof (CV_INFO_PDB70) + 1; 92 + const char * filename_ptr = _bfd_XXi_get_codeview_pdb_name(abfd); 93 + unsigned int filename_size = strlen(filename_ptr); 94 + unsigned int size = sizeof (CV_INFO_PDB70) + filename_size + 1; 95 CV_INFO_PDB70 *cvinfo70; 96 char buffer[size]; 97 98 @@ -1208,7 +1223,7 @@ 99 memcpy (&(cvinfo70->Signature[8]), &(cvinfo->Signature[8]), 8); 100 101 H_PUT_32 (abfd, cvinfo->Age, cvinfo70->Age); 102 - cvinfo70->PdbFileName[0] = '\0'; 103 + strcpy(cvinfo70->PdbFileName, filename_ptr); 104 105 if (bfd_bwrite (buffer, size, abfd) != size) 106 return 0; 107 @@ -2652,8 +2667,8 @@ 108 if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW) 109 { 110 char signature[CV_INFO_SIGNATURE_LENGTH * 2 + 1]; 111 - char buffer[256 + 1]; 112 - CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer; 113 + char buffer [idd.SizeOfData]; 114 + CODEVIEW_INFO * cvinfo = (CODEVIEW_INFO *) buffer; 115 116 /* The debug entry doesn't have to have to be in a section, 117 in which case AddressOfRawData is 0, so always use PointerToRawData. */ 118 @@ -2664,9 +2679,10 @@ 119 for (i = 0; i < cvinfo->SignatureLength; i++) 120 sprintf (&signature[i*2], "%02x", cvinfo->Signature[i] & 0xff); 121 122 - fprintf (file, "(format %c%c%c%c signature %s age %ld)\n", 123 - buffer[0], buffer[1], buffer[2], buffer[3], 124 - signature, cvinfo->Age); 125 + fprintf (file, "(format %c%c%c%c signature %s age %ld pdb %s)\n", 126 + buffer[0], buffer[1], buffer[2], buffer[3], 127 + signature, cvinfo->Age, cvinfo->PdbFileName); 128 + 129 } 130 } 131 132 diff -Nur a/include/coff/internal.h b/include/coff/internal.h 133 --- a/include/coff/internal.h 2015-10-21 11:59:30.213316958 -0700 134 +++ b/include/coff/internal.h 2015-10-22 11:42:59.844341094 -0700 135 @@ -167,7 +167,7 @@ 136 char Signature[CV_INFO_SIGNATURE_LENGTH]; 137 unsigned int SignatureLength; 138 unsigned long Age; 139 - // char PdbFileName[]; 140 + char PdbFileName[]; 141 } CODEVIEW_INFO; 142 143 /* Default image base for NT. */ 144 diff -Nur a/ld/emultempl/pe.em b/ld/emultempl/pe.em 145 --- a/ld/emultempl/pe.em 2015-10-21 11:59:29.957318693 -0700 146 +++ b/ld/emultempl/pe.em 2015-10-22 12:50:55.876527037 -0700 147 @@ -1324,6 +1324,9 @@ 148 return TRUE; 149 } 150 151 + const char * pdb_name = _bfd_XXi_get_codeview_pdb_name (abfd); 152 + unsigned int pdb_name_length = strlen(pdb_name); 153 + 154 if (t->build_id.sec->contents == NULL) 155 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size); 156 contents = t->build_id.sec->contents; 157 @@ -1342,7 +1348,7 @@ 158 idd.MajorVersion = 0; 159 idd.MinorVersion = 0; 160 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW; 161 - idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1; 162 + idd.SizeOfData = sizeof (CV_INFO_PDB70) + pdb_name_length + 1; 163 idd.AddressOfRawData = asec->vma - ib + link_order->offset 164 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY); 165 idd.PointerToRawData = asec->filepos + link_order->offset 166 @@ -1405,13 +1411,14 @@ 167 t->build_id.after_write_object_contents = &write_build_id; 168 t->build_id.style = emit_build_id; 169 t->build_id.sec = s; 170 - 171 - /* Section is a fixed size: 172 + 173 + /* Section is a variable size: 174 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW, 175 pointing at a CV_INFO_PDB70 record containing the build-id, with a 176 - null byte for PdbFileName. */ 177 + null terminated string for PdbFileName. */ 178 + 179 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY) 180 - + sizeof (CV_INFO_PDB70) + 1; 181 + + sizeof (CV_INFO_PDB70) + strlen(_bfd_XXi_get_codeview_pdb_name(link_info.output_bfd)) + 1; 182 183 return TRUE; 184 } 185 186