[PATCH 1/4] pe/coff: Display GUID build-id in the conventional way

Jon TURNEY jon.turney@dronecode.org.uk
Mon Apr 21 20:17:00 GMT 2014


On 21/04/2014 18:25, Pierre Muller wrote:
>   I was also wondering if this would not require some
> byte swapping to write the 32 and 16 bit integers correctly on
> a big endian machine.

Yes, I don't think I've got this right.

I think you are quite correct that with this patch I also need to do some
swapping on write to make a GUID set with --buildid=0xhexdigits be reported in
a consistent way.

I think I've been confused by the fact that these components of the GUID are
said to be in native byte-order, but that really means little-endian since (I
think) these files could only sensibly exist for a little-endian target.

Replacement patch attached.
-------------- next part --------------
>From 8b14872e2954c6dc3a43ce5eec0fc72753176cdf Mon Sep 17 00:00:00 2001
From: Jon TURNEY <jon.turney@dronecode.org.uk>
Date: Mon, 21 Apr 2014 21:11:06 +0100
Subject: [PATCH] pe/coff: Swap GUID build-id on read and write

Byte-swap GUID build-id on read and write so it is consistently displayed in the
conventional way.

bfd/ChangeLog:

2014-04-21  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* peXXigen.c (_bfd_XXi_slurp_codeview_record)
	(_bfd_XXi_write_codeview_record): Byte-swap GUID from
	little-endian to big-endian order for consistent and conventional
	display.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 bfd/peXXigen.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index ea7846f..2de64a2 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -1088,7 +1088,15 @@ _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length
       CV_INFO_PDB70 *cvinfo70 = (CV_INFO_PDB70 *)(buffer);
 
       cvinfo->Age = H_GET_32(abfd, cvinfo70->Age);
-      memcpy (cvinfo->Signature, cvinfo70->Signature, CV_INFO_SIGNATURE_LENGTH);
+
+      /* A GUID consists of 4,2,2 byte values in little-endian order, followed
+         by 8 single bytes. Byte swap then so we can conveniently treat the GUID
+         as 16 bytes in big-endian order. */
+      bfd_putb32 (bfd_getl32 (cvinfo70->Signature), cvinfo->Signature);
+      bfd_putb16 (bfd_getl16 (&(cvinfo70->Signature[4])), &(cvinfo->Signature[4]));
+      bfd_putb16 (bfd_getl16 (&(cvinfo70->Signature[6])), &(cvinfo->Signature[6]));
+      memcpy (&(cvinfo->Signature[8]), &(cvinfo70->Signature[8]), 8);
+
       cvinfo->SignatureLength = CV_INFO_SIGNATURE_LENGTH;
       // cvinfo->PdbFileName = cvinfo70->PdbFileName;
 
@@ -1121,7 +1129,14 @@ _bfd_XXi_write_codeview_record (bfd * abfd, file_ptr where, CODEVIEW_INFO *cvinf
 
   cvinfo70 = (CV_INFO_PDB70 *) buffer;
   H_PUT_32 (abfd, CVINFO_PDB70_CVSIGNATURE, cvinfo70->CvSignature);
-  memcpy (&(cvinfo70->Signature), cvinfo->Signature, CV_INFO_SIGNATURE_LENGTH);
+
+  /* Byte swap the GUID from 16 bytes in big-endian order to 4,2,2 byte values
+     in little-endian order, followed by 8 single bytes. */
+  bfd_putl32 (bfd_getb32 (cvinfo->Signature), cvinfo70->Signature);
+  bfd_putl16 (bfd_getb16 (&(cvinfo->Signature[4])), &(cvinfo70->Signature[4]));
+  bfd_putl16 (bfd_getb16 (&(cvinfo->Signature[6])), &(cvinfo70->Signature[6]));
+  memcpy (&(cvinfo70->Signature[8]), &(cvinfo->Signature[8]), 8);
+
   H_PUT_32 (abfd, cvinfo->Age, cvinfo70->Age);
   cvinfo70->PdbFileName[0] = '\0';
 
-- 
1.8.5.5



More information about the Binutils mailing list