[PATCH 2/4] libctf, binutils: fix big-endian libctf archive opening

Nick Alcock nick.alcock@oracle.com
Wed Jul 22 09:39:24 GMT 2020


The recent commit "libctf, binutils: support CTF archives like objdump"
broke opening of CTF archives on big-endian platforms.

This didn't affect anyone much before now because the linker never
emitted CTF archives because it wasn't detecting ambiguous types
properly: now it does, and this bug becomes obvious.

Fix trivial.

libctf/
	* ctf-archive.c (ctf_arc_bufopen): Endian-swap the archive magic
	number if needed.
---
 libctf/ctf-archive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 3b4304f0894..4fbb246c67b 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -393,7 +393,7 @@ ctf_arc_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
   ctf_file_t *fp = NULL;
 
   if (ctfsect->cts_size > sizeof (uint64_t) &&
-      ((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC))
+      (le64toh ((*(uint64_t *) ctfsect->cts_data)) == CTFA_MAGIC))
     {
       /* The archive is mmappable, so this operation is trivial.
 
-- 
2.27.0.247.g3dff7de930



More information about the Binutils mailing list