[Bug translator/32999] handle PIE executables with segments where file-offset is not vaddr

lijunlong at openresty dot com sourceware-bugzilla@sourceware.org
Wed May 28 07:36:34 GMT 2025


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

--- Comment #3 from lijunlong <lijunlong at openresty dot com> ---

readelf -s -W /usr/bin/cpp | grep FUNC | grep -v UND
   138: 0000000000442400   429 FUNC    GLOBAL DEFAULT    5 _obstack_newchunk


static struct stapiu_consumer stap_inode_uprobe_consumers[] = {
  { .finder={  .purpose="inode-uprobes", .callback=&stapiu_process_found,
.build_id_len=0, .procname="/usr/bin/cpp", }, .module_name="/usr/bin/cpp",
.offset=(loff_t)0x42400ULL, .probe=(&stap_probes[0]), },
};

readelf -l -W /usr/bin/cpp

Elf file type is EXEC (Executable file)
Entry point 0x447af0
There are 14 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
...
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x07adc1
0x07adc1 R E 0x1000
  LOAD           0x07b000 0x000000000047b000 0x000000000047b000 0x0be810
0x0be810 R   0x1000
  LOAD           0x139918 0x000000000053a918 0x000000000053a918 0x0025c0
0x006510 RW  0x1000

>From the above, we found the diff between VirtAddr and Offset is 0x400000.
The address of _obstack_newchunk is 0x442400.
Systemtap add uprobe on 0x42400 which has file offset rather than 0x442400.

The address is calcuated by the following function:
Dwarf_Addr
dwflpp::relocate_address(Dwarf_Addr dw_addr, interned_string& reloc_section)
{
  // PR10273
  // libdw address, so adjust for bias gotten from dwfl_module_getdwarf
  Dwarf_Addr reloc_addr = dw_addr + module_bias;
  if (!module)
    {
      assert(module_name == TOK_KERNEL);
      reloc_section = "";
    }
  else if (dwfl_module_relocations (module) > 0)
    {
      // This is a relocatable module; libdwfl already knows its
      // sections, so we can relativize addr.
      int idx = dwfl_module_relocate_address (module, &reloc_addr);
      const char* r_s = dwfl_module_relocation_info (module, idx, NULL);
      if (r_s)
        reloc_section = r_s;

      if (reloc_section == "" && dwfl_module_relocations (module) == 1)
          reloc_section = ".dynamic";
    }
  else
    reloc_section = ".absolute";
  return reloc_addr;
}

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Systemtap mailing list