public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Torsten Polle <Torsten.Polle@gmx.de>
To: Mark Wielaard <mjw@redhat.com>
Cc: systemtap@sourceware.org
Subject: Re: Prelinking on ARM with Debug Link
Date: Mon, 22 Feb 2016 21:45:00 -0000	[thread overview]
Message-ID: <23DAF1AA-DD74-4B03-8290-A4CB49F10D14@gmx.de> (raw)
In-Reply-To: <1455812509.7770.4.camel@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1204 bytes --]

Am 18.02.2016 um 17:21 schrieb Mark Wielaard <mjw@redhat.com>:
> 
> On Tue, 2016-02-16 at 21:46 +0100, Torsten Polle wrote:
>> The target architecture is 32bit ARM. The host architecture is 64bit
>> X86. That’s the reason why field .sec_load_offset is initialised with
>> a 64bit wide hexadecimal number. But as the field .sec_load_offset is
>> defined only as „unsigned long“, the compiler complains. As a work
>> around I tried to output decimal number instead for the initialisation
>> of .sec_load_offset. I can compile alright. But the resulting
>> backtrace calculations shown in my previous example produce strange
>> results.
> 
> OK, I don't have such a setup, but maybe all that is needed, if we
> assume negative values are ok, is to not write sec_load_offset out in
> hex, but simply in dec. Could you try the attached patch?
> 
> Thanks,
> 
> Mark

Hi Mark,

the principle idea of your patch works. But I had to rewrite it to really work in my environment. Could you please have a look at my proposal? Would something like that be acceptable?

I would like to double check in my environment if we could fall back to the hex notation again.

Thanks,
Torsten

[-- Attachment #2: 0001-Fix-Compilation-fails-for-prelinked-libraries.patch --]
[-- Type: application/octet-stream, Size: 3013 bytes --]

From c2854c6c8400ae3658e6037d2a0bc656ee550a33 Mon Sep 17 00:00:00 2001
Message-Id: <c2854c6c8400ae3658e6037d2a0bc656ee550a33.1456177234.git.Torsten.Polle@gmx.de>
From: Torsten Polle <Torsten.Polle@gmx.de>
Date: Mon, 22 Feb 2016 22:39:59 +0100
Subject: [PATCH] Fix: Compilation fails for prelinked libraries.

The offset to the section ".text" in a prelinked library might increase due to
changed relocations that need more space. If the prelinked library contains a
debug link and the linked file is not prelinked, the offset to the ".text"
section is different. If the difference between the offset of the ".text"
section in the prelinked library and non-prelinked library (with e.g. debug
information) becomes negative, the representation of this negative number has
to fit into an "unsigned int". If the width of the host is larger than the
width of the target, the compilation for the target fails.

Signed-off-by: Torsten Polle <Torsten.Polle@gmx.de>
---
 translate.cxx |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/translate.cxx b/translate.cxx
index f792343..f0364e9 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -6844,9 +6844,22 @@ dump_unwindsym_cxt (Dwfl_Module *m,
           c->output << ".debug_hdr_len = " << debug_frame_hdr_len << ", \n";
 
 	  Dwarf_Addr dwbias = 0;
+	  Dwarf_Addr elf_bias;
+	  GElf_Ehdr *ehdr, ehdr_mem;
+	  Elf *elf;
+	  elf = dwfl_module_getelf(m, &elf_bias);
+	  ehdr = gelf_getehdr(elf, &ehdr_mem);
 	  dwfl_module_getdwarf (m, &dwbias);
-	  c->output << ".sec_load_offset = 0x"
-		    << hex << debug_frame_off - dwbias << dec << "\n";
+	  if (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
+	    {
+	      c->output << ".sec_load_offset = "
+			<< (uint32_t)debug_frame_off - (uint32_t)dwbias << "u\n";
+	    }
+	  else
+	    {
+	      c->output << ".sec_load_offset = 0x"
+			<< hex << debug_frame_off - dwbias << dec << "\n";
+	    }
 
 	  c->output << "#else\n";
 	  c->output << ".debug_hdr = NULL,\n";
@@ -6864,9 +6877,22 @@ dump_unwindsym_cxt (Dwfl_Module *m,
             {
               c->output << "#if defined(STP_NEED_LINE_DATA)\n";
               Dwarf_Addr dwbias = 0;
+	      Dwarf_Addr elf_bias;
+	      GElf_Ehdr *ehdr, ehdr_mem;
+	      Elf *elf;
+	      elf = dwfl_module_getelf(m, &elf_bias);
+	      ehdr = gelf_getehdr(elf, &ehdr_mem);
               dwfl_module_getdwarf (m, &dwbias);
-              c->output << ".sec_load_offset = 0x"
-                        << hex << debug_frame_off - dwbias << dec << "\n";
+	      if (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
+		{
+		  c->output << ".sec_load_offset = "
+			    << (uint32_t)debug_frame_off - (uint32_t)dwbias << "u\n";
+		}
+	      else
+		{
+		  c->output << ".sec_load_offset = 0x"
+			    << hex << debug_frame_off - dwbias << dec << "\n";
+		}
               c->output << "#else\n";
             }
 	  c->output << ".sec_load_offset = 0\n";
-- 
1.7.4.1


  reply	other threads:[~2016-02-22 21:45 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01 19:29 Torsten Polle
2016-02-09 20:55 ` Torsten Polle
2016-02-10 16:17   ` Mark Wielaard
2016-02-10 20:12     ` Torsten Polle
2016-02-10 20:35       ` Mark Wielaard
2016-02-11 10:49         ` Aw: " Torsten Polle
2016-02-16 10:08           ` Mark Wielaard
2016-02-16 20:46             ` Torsten Polle
2016-02-18 16:21               ` Mark Wielaard
2016-02-22 21:45                 ` Torsten Polle [this message]
2016-02-23 16:46                   ` Mark Wielaard
2016-02-23 22:16                     ` Torsten Polle
2016-02-28 20:51                       ` Torsten Polle
2016-03-30 20:05                         ` Torsten Polle
2016-04-01 13:07                           ` Mark Wielaard
2016-04-01 21:19                             ` Torsten Polle
2016-04-05 13:44                               ` Mark Wielaard
2016-04-06 20:45                                 ` Torsten Polle
2016-04-06 21:56                                   ` Mark Wielaard
2016-04-11 18:47                                     ` Torsten Polle
2016-04-11 21:02                                       ` Mark Wielaard
2016-04-12 20:26                                         ` Torsten Polle
2016-04-13  9:25                                           ` Mark Wielaard
2016-04-13 14:36                                             ` Aw: " Torsten Polle
  -- strict thread matches above, loose matches on Subject: below --
2015-12-01  7:26 Torsten Polle
2015-11-25 20:52 Torsten Polle
2015-11-26 10:33 ` Mark Wielaard
2015-11-26 22:05   ` Torsten Polle
2015-11-27  8:05     ` Mark Wielaard
2015-11-27 12:57       ` Torsten Polle
2015-11-27 15:06         ` Mark Wielaard
2015-11-27 16:34           ` Mark Wielaard
2015-11-27 20:08             ` Torsten Polle
2015-11-27 20:01           ` Torsten Polle
2015-11-30 19:26             ` David Smith
2015-12-01 20:10               ` Torsten Polle
2015-12-10 19:00                 ` David Smith
2015-12-10 19:45                   ` Torsten Polle

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=23DAF1AA-DD74-4B03-8290-A4CB49F10D14@gmx.de \
    --to=torsten.polle@gmx.de \
    --cc=mjw@redhat.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).