From: Crestez Dan Leonard <cdleonard@gmail.com>
To: systemtap@sourceware.org
Subject: [RFC 10/13] Create debug_frame_hdr in target byte order
Date: Thu, 31 Jul 2014 20:22:00 -0000 [thread overview]
Message-ID: <62279a838ba17e55133c435f18004ab0a4e6c6af.1406837921.git.cdleonard@gmail.com> (raw)
In-Reply-To: <cover.1406837921.git.cdleonard@gmail.com>
In-Reply-To: <cover.1406837921.git.cdleonard@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 44 bytes --]
This is a multi-part message in MIME format.
[-- Attachment #2: Type: text/plain, Size: 165 bytes --]
Signed-off-by: Crestez Dan Leonard <cdleonard@gmail.com>
---
translate.cxx | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0010-Create-debug_frame_hdr-in-target-byte-order.patch --]
[-- Type: text/x-patch; name="0010-Create-debug_frame_hdr-in-target-byte-order.patch", Size: 2479 bytes --]
diff --git a/translate.cxx b/translate.cxx
index ac6377b..158f76f 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -21,6 +21,7 @@
#include "runtime/k_syms.h"
#include "dwflpp.h"
#include "stapregex.h"
+#include <byteswap.h>
#include <cstdlib>
#include <iostream>
@@ -5537,6 +5538,17 @@ struct unwindsym_dump_context
set<string> undone_unwindsym_modules;
};
+static bool need_byte_swap_for_target (const unsigned char e_ident[])
+{
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ return (e_ident[EI_DATA] == ELFDATA2MSB);
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ return (e_ident[EI_DATA] == ELFDATA2LSB);
+#else
+ #error Bad host __BYTE_ORDER
+#endif
+}
+
static void create_debug_frame_hdr (const unsigned char e_ident[],
Elf_Data *debug_frame,
void **debug_frame_hdr,
@@ -5556,6 +5568,10 @@ static void create_debug_frame_hdr (const unsigned char e_ident[],
// So there is no need to read the CIEs. And the size is either 4
// or 8, depending on the elf class from e_ident.
int size = (e_ident[EI_CLASS] == ELFCLASS32) ? 4 : 8;
+ bool need_byte_swap = need_byte_swap_for_target (e_ident);
+#define host_to_target_64(x) (need_byte_swap ? bswap_64((x)) : (x))
+#define host_to_target_32(x) (need_byte_swap ? bswap_32((x)) : (x))
+
int res = 0;
Dwarf_Off off = 0;
Dwarf_CFI_Entry entry;
@@ -5620,23 +5636,23 @@ static void create_debug_frame_hdr (const unsigned char e_ident[],
if (size == 4)
{
uint32_t *table = (uint32_t *)(hdr + 4);
- *table++ = (uint32_t) 0; // eh_frame_ptr, unused
- *table++ = (uint32_t) fdes.size();
+ *table++ = host_to_target_32 ((uint32_t) 0); // eh_frame_ptr, unused
+ *table++ = host_to_target_32 ((uint32_t) fdes.size());
for (it = fdes.begin(); it != fdes.end(); it++)
{
- *table++ = (*it).first;
- *table++ = (*it).second;
+ *table++ = host_to_target_32 ((*it).first);
+ *table++ = host_to_target_32 ((*it).second);
}
}
else
{
uint64_t *table = (uint64_t *)(hdr + 4);
- *table++ = (uint64_t) 0; // eh_frame_ptr, unused
- *table++ = (uint64_t) fdes.size();
+ *table++ = host_to_target_64 ((uint64_t) 0); // eh_frame_ptr, unused
+ *table++ = host_to_target_64 ((uint64_t) fdes.size());
for (it = fdes.begin(); it != fdes.end(); it++)
{
- *table++ = (*it).first;
- *table++ = (*it).second;
+ *table++ = host_to_target_64 ((*it).first);
+ *table++ = host_to_target_64 ((*it).second);
}
}
}
next prev parent reply other threads:[~2014-07-31 20:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-31 20:21 [RFC 00/13] MIPS64 support Crestez Dan Leonard
2014-07-31 20:21 ` [RFC 02/13] mips: Define TIF_32BIT if missing Crestez Dan Leonard
2014-07-31 20:21 ` [RFC 03/13] mips: Read _stp_deref and _stp_store_deref support Crestez Dan Leonard
2014-07-31 20:21 ` [RFC 01/13] mips: Minimal build support Crestez Dan Leonard
2014-07-31 20:22 ` [RFC 07/13] loc2c: Add Dwarf pointer to location_context Crestez Dan Leonard
2014-07-31 20:22 ` [RFC 06/13] Force sign-extend statement addresses on mips64 -msym32 Crestez Dan Leonard
2014-07-31 20:22 ` [RFC 09/13] mips: dwflpp hack for struct fields being DW_OP_constu instead of DW_OP_plus_uconst Crestez Dan Leonard
2014-07-31 20:22 ` [RFC 04/13] mips: runtime and tapset code from cisco Crestez Dan Leonard
2014-07-31 20:22 ` Crestez Dan Leonard [this message]
2014-07-31 20:22 ` [RFC 08/13] mips: Fix fetching params of type long on mips kernel Crestez Dan Leonard
2014-07-31 20:22 ` [RFC 11/13] mips64: Initial unwind support Crestez Dan Leonard
2014-07-31 20:22 ` [RFC 05/13] mips: Special get_cycles for cavium octeon Crestez Dan Leonard
2014-07-31 20:23 ` [RFC 13/13] runtime: Hack to interpret mips64 FDEs as 32bit for unwind Crestez Dan Leonard
2014-07-31 20:23 ` [RFC 12/13] translator: " Crestez Dan Leonard
2014-08-01 11:16 ` [RFC 00/13] MIPS64 support Mark Wielaard
2014-08-01 12:02 ` Crestez Dan Leonard
2014-08-14 20:58 ` Josh Stone
2014-08-15 1:27 ` Victor Kamensky
2014-09-01 13:47 ` Crestez Dan Leonard
2014-09-02 18:05 ` Josh Stone
2014-09-02 19:10 ` Crestez Dan Leonard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=62279a838ba17e55133c435f18004ab0a4e6c6af.1406837921.git.cdleonard@gmail.com \
--to=cdleonard@gmail.com \
--cc=systemtap@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).