[PATCH] Fix writing object contents above 4GB in tekhex format

Dani Szebenyi szedani@linux.ibm.com
Wed Oct 23 15:10:50 GMT 2024


Writing tekhex object with addresses above 4GB resulted in a corrupted object
contents, because the upper 32-bit of the address were silently ignored
in `writevalue`.
While reading a 64-bit address section did work in tekhex format, with the
address length encoded as 0.

This code adds the neccesary support for writing the upper bits of the
address, while not changing the existing behavior for addresses below
4GB.

Signed-off-by: Dani Szebenyi <szedani@linux.ibm.com>
---
 bfd/tekhex.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bfd/tekhex.c b/bfd/tekhex.c
index 96022c585ab..46f40b19817 100644
--- a/bfd/tekhex.c
+++ b/bfd/tekhex.c
@@ -719,11 +719,11 @@ writevalue (char **dst, bfd_vma value)
   int len;
   int shift;
 
-  for (len = 8, shift = 28; shift; shift -= 4, len--)
+  for (len = 16, shift = 60; shift; shift -= 4, len--)
     {
       if ((value >> shift) & 0xf)
 	{
-	  *p++ = len + '0';
+	  *p++ = digs[len & 0xf];
 	  while (len)
 	    {
 	      *p++ = digs[(value >> shift) & 0xf];
-- 
2.47.0



More information about the Binutils mailing list