public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug libdw/31447] New: Provide a public debug section relocation function
@ 2024-03-03 12:19 mark at klomp dot org
  2024-03-03 12:35 ` [Bug libdw/31447] " mark at klomp dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mark at klomp dot org @ 2024-03-03 12:19 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=31447

            Bug ID: 31447
           Summary: Provide a public debug section relocation function
           Product: elfutils
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libdw
          Assignee: unassigned at sourceware dot org
          Reporter: mark at klomp dot org
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

When opening an ET_REL file with dwarf_begin no relocations are resolved and no
error checking is done if that is necessary. Causing some functions to produce
errors or wrong results (because an index is wrongly assumed to be zero).

When opening such a file through libdwfl we do resolve all cross-debug-section
relocations using __libdwfl_relocate.

It would be good to make this a public function. Maybe through libdwelf
dwelf_relocation_debug_sections (Elf *elf). So users can make sure ET_REL files
can be handled by libdw.

And maybe add a check/flag in dwarf_begin so an error can be produced if a
relocation value is needed for a correct result.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libdw/31447] Provide a public debug section relocation function
  2024-03-03 12:19 [Bug libdw/31447] New: Provide a public debug section relocation function mark at klomp dot org
@ 2024-03-03 12:35 ` mark at klomp dot org
  2024-03-21 14:19 ` dichen at redhat dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mark at klomp dot org @ 2024-03-03 12:35 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=31447

--- Comment #1 from Mark Wielaard <mark at klomp dot org> ---
This is the current "workaround" I use when working with individual ET_REL
DWARF files (also works for any other ELF type):

 static char *debuginfo_path = NULL;
 static const Dwfl_Callbacks dwfl_callbacks =
    {
      .find_elf = dwfl_build_id_find_elf,
      .find_debuginfo = dwfl_standard_find_debuginfo,
      .section_address = dwfl_offline_section_address,
      .debuginfo_path = &debuginfo_path,
    };

 int main (int argc, char **argv)
 {
    Dwfl *dwfl = dwfl_begin (&dwfl_callbacks);
    Dwfl_Module *module = dwfl_report_elf (dwfl, argv[1], argv[1], -1, 0,
false);
    if (module == NULL)
      printf ("%s\n", dwfl_errmsg (-1));
    dwfl_report_end (dwfl, NULL, NULL);

    Dwarf_Addr bias;
    Dwarf *dwarf = dwfl_module_getdwarf (module, &bias);
    if (dwarf == NULL)
      printf ("%s\n", dwfl_errmsg (-1));

    /* ... do something with dwarf ... */

    dwfl_end (dwfl); // Also cleans up dwarf.
 }

But this is obviously a little cumbersome if not really using any other libdwfl
features.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libdw/31447] Provide a public debug section relocation function
  2024-03-03 12:19 [Bug libdw/31447] New: Provide a public debug section relocation function mark at klomp dot org
  2024-03-03 12:35 ` [Bug libdw/31447] " mark at klomp dot org
@ 2024-03-21 14:19 ` dichen at redhat dot com
  2024-05-12  7:29 ` dichen at redhat dot com
  2024-05-12  9:06 ` mark at klomp dot org
  3 siblings, 0 replies; 5+ messages in thread
From: dichen at redhat dot com @ 2024-03-21 14:19 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=31447

Di Chen <dichen at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |dichen at redhat dot com
                 CC|                            |dichen at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libdw/31447] Provide a public debug section relocation function
  2024-03-03 12:19 [Bug libdw/31447] New: Provide a public debug section relocation function mark at klomp dot org
  2024-03-03 12:35 ` [Bug libdw/31447] " mark at klomp dot org
  2024-03-21 14:19 ` dichen at redhat dot com
@ 2024-05-12  7:29 ` dichen at redhat dot com
  2024-05-12  9:06 ` mark at klomp dot org
  3 siblings, 0 replies; 5+ messages in thread
From: dichen at redhat dot com @ 2024-05-12  7:29 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=31447

--- Comment #2 from Di Chen <dichen at redhat dot com> ---
Hey @mjw

```
$ eu-readelf -a qq.o | grep Type
  Type: REL (Relocatable file)

$ eu-readelf -S qq.o | grep REL
[ 2] .rela.text           RELA         0000000000000000 000004b8 00000048 24 I 
   19   1  8
[ 6] .rela.debug_info     RELA         0000000000000000 00000500 000000f0 24 I 
   19   5  8
[ 9] .rela.debug_aranges  RELA         0000000000000000 000005f0 00000030 24 I 
   19   8  8
[11] .rela.debug_line     RELA         0000000000000000 00000620 00000060 24 I 
   19  10  8
[18] .rela.eh_frame       RELA         0000000000000000 00000680 00000030 24 I 
   19  17  8

```


When applying relocation on a relocatable file (the above qq.o) with the new
function
dwelf_relocation_debug_sections (Elf *elf), it only needs to apply relocation
on debug sections (which are 
[ 6] .rela.debug_info, 
[ 9] .rela.debug_aranges,
[11] .rela.debug_line
), am I right?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libdw/31447] Provide a public debug section relocation function
  2024-03-03 12:19 [Bug libdw/31447] New: Provide a public debug section relocation function mark at klomp dot org
                   ` (2 preceding siblings ...)
  2024-05-12  7:29 ` dichen at redhat dot com
@ 2024-05-12  9:06 ` mark at klomp dot org
  3 siblings, 0 replies; 5+ messages in thread
From: mark at klomp dot org @ 2024-05-12  9:06 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=31447

--- Comment #3 from Mark Wielaard <mark at klomp dot org> ---
Yes, just process the .rela.debug_* sections.
Note that you don't need to depend on the exact name.
You can follow the section header sh_info field, which points to the section
(number) to which the relocations apply.
If that section starts with .debug you can apply the relocations.
Or better use ebl_debugscn_p, which checks against the list in
libebl/eblopenbackend.c (default_debugscn_p).

See also in strip.c, where it says:

          /* Make sure that this relocation section points to a
             section to relocate with contents, that isn't
             allocated and that is a debug section.  */

Or libdwfl/relocate.c (relocate_section). Which contains similar logic.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-12  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-03 12:19 [Bug libdw/31447] New: Provide a public debug section relocation function mark at klomp dot org
2024-03-03 12:35 ` [Bug libdw/31447] " mark at klomp dot org
2024-03-21 14:19 ` dichen at redhat dot com
2024-05-12  7:29 ` dichen at redhat dot com
2024-05-12  9:06 ` mark at klomp dot org

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).