Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CODSPEED-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ This file documents changes made to Valgrind for CodSpeed integration, beyond th

## Features

### Skip `.plt.sec` in `--skip-plt`

**Feature**: Added support for skipping `.plt.sec` sections when using the `--skip-plt` option.

**Motivation**: The `.plt.sec` section is a specialized variant of the Procedure Linkage Table (PLT) used in systems with Intel Control-flow Enforcement Technology (CET). When profiling applications using libraries compiled with it (e.g. libpython), symbols in `.plt.sec` were not skipped by the `--skip-plt` option, causing unresolved addresses to appear in profiling data (e.g., `_PySequence_Tuple` at 0x48ce4a0). Both `.plt` and `.plt.sec` sections contain only jumps to the actual function implementations, and do not have any symbols associated with those wrapper functions.

**How it works**:
- Extends the existing PLT-skipping logic to also recognize and skip `.plt.sec` sections
- Whenever we see a function inside the `.plt.sec` section, skip it

**Usage**: Enable `--skip-plt=yes` and both `.plt` and `.plt.sec` will be skipped.

### Callgrind: Inline Function Tracking

Expand Down
2 changes: 1 addition & 1 deletion callgrind/fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ fn_node* CLG_(get_fn_node)(BB* bb)
pure[1] = fn;
fn->pure_cxt = CLG_(get_cxt)(pure+1);

if (bb->sect_kind == Vg_SectPLT)
if (bb->sect_kind == Vg_SectPLT || bb->sect_kind == Vg_SectPLTSEC)
Comment thread
not-matthias marked this conversation as resolved.
fn->skip = CLG_(clo).skip_plt;

if (VG_(strncmp)(fn->name, "_dl_runtime_resolve", 19)==0) {
Expand Down
17 changes: 17 additions & 0 deletions coregrind/m_debuginfo/debuginfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4975,6 +4975,16 @@ SizeT VG_(DebugInfo_get_plt_size)(const DebugInfo* di)
return di->plt_present ? di->plt_size : 0;
}

Addr VG_(DebugInfo_get_pltsec_avma)(const DebugInfo* di)
{
return di->pltsec_present ? di->pltsec_avma : 0;
}

SizeT VG_(DebugInfo_get_pltsec_size)(const DebugInfo* di)
{
return di->pltsec_present ? di->pltsec_size : 0;
}

Addr VG_(DebugInfo_get_gotplt_avma)(const DebugInfo* di)
{
return di->gotplt_present ? di->gotplt_avma : 0;
Expand Down Expand Up @@ -5053,6 +5063,7 @@ const HChar* VG_(pp_SectKind)( VgSectKind kind )
case Vg_SectPLT: return "PLT";
case Vg_SectOPD: return "OPD";
case Vg_SectGOTPLT: return "GOTPLT";
case Vg_SectPLTSEC: return "PLTSEC";
default: vg_assert(0);
}
}
Expand Down Expand Up @@ -5115,6 +5126,12 @@ VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/const HChar** objname, Addr a)
res = Vg_SectPLT;
break;
}
if (di->pltsec_present
&& di->pltsec_size > 0
&& a >= di->pltsec_avma && a < di->pltsec_avma + di->pltsec_size) {
res = Vg_SectPLTSEC;
break;
}
if (di->got_present
&& di->got_size > 0
&& a >= di->got_avma && a < di->got_avma + di->got_size) {
Expand Down
4 changes: 4 additions & 0 deletions coregrind/m_debuginfo/priv_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ struct _DebugInfo {
Bool plt_present;
Addr plt_avma;
SizeT plt_size;
/* .plt.sec */
Bool pltsec_present;
Addr pltsec_avma;
SizeT pltsec_size;
/* .got */
Bool got_present;
Addr got_avma;
Expand Down
41 changes: 41 additions & 0 deletions coregrind/m_debuginfo/readelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,17 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
BAD(".plt");
}
}
/* Accept .plt.sec where mapped as rx (code) - hardened PLT section */
if (0 == VG_(strcmp)(name, ".plt.sec")) {
if (inrx && !di->pltsec_present) {
di->pltsec_present = True;
di->pltsec_avma = svma + inrx->bias;
di->pltsec_size = size;
TRACE_SYMTAB("acquiring .plt.sec avma = %#lx\n", di->pltsec_avma);
} else {
BAD(".plt.sec");
}
}
# elif defined(VGP_ppc32_linux)
/* Accept .plt where mapped as rw (data) */
if (0 == VG_(strcmp)(name, ".plt")) {
Expand All @@ -2746,6 +2757,17 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
BAD(".plt");
}
}
/* Accept .plt.sec where mapped as rw (data) - hardened PLT section */
if (0 == VG_(strcmp)(name, ".plt.sec")) {
if (inrw1 && !di->pltsec_present) {
di->pltsec_present = True;
di->pltsec_avma = svma + inrw1->bias;
di->pltsec_size = size;
TRACE_SYMTAB("acquiring .plt.sec avma = %#lx\n", di->pltsec_avma);
} else {
BAD(".plt.sec");
}
}
# elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
/* Accept .plt where mapped as rw (data), or unmapped */
if (0 == VG_(strcmp)(name, ".plt")) {
Expand All @@ -2766,6 +2788,25 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
BAD(".plt");
}
}
/* Accept .plt.sec where mapped as rw (data), or unmapped - hardened PLT section */
if (0 == VG_(strcmp)(name, ".plt.sec")) {
if (inrw1 && !di->pltsec_present) {
di->pltsec_present = True;
di->pltsec_avma = svma + inrw1->bias;
di->pltsec_size = size;
TRACE_SYMTAB("acquiring .plt.sec avma = %#lx\n", di->pltsec_avma);
} else
if ((!inrw1) && (!inrx) && size > 0 && !di->pltsec_present) {
/* File contains a .plt.sec, but it didn't get mapped.
Presumably it is not required on this platform. At
least don't reject the situation as invalid. */
di->pltsec_present = True;
di->pltsec_avma = 0;
di->pltsec_size = 0;
} else {
BAD(".plt.sec");
}
}
# else
# error "Unsupported platform"
# endif
Expand Down
5 changes: 4 additions & 1 deletion include/pub_tool_debuginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ Addr VG_(DebugInfo_get_bss_avma) ( const DebugInfo *di );
SizeT VG_(DebugInfo_get_bss_size) ( const DebugInfo *di );
Addr VG_(DebugInfo_get_plt_avma) ( const DebugInfo *di );
SizeT VG_(DebugInfo_get_plt_size) ( const DebugInfo *di );
Addr VG_(DebugInfo_get_pltsec_avma) ( const DebugInfo *di );
SizeT VG_(DebugInfo_get_pltsec_size) ( const DebugInfo *di );
Addr VG_(DebugInfo_get_gotplt_avma) ( const DebugInfo *di );
SizeT VG_(DebugInfo_get_gotplt_size) ( const DebugInfo *di );
Addr VG_(DebugInfo_get_got_avma) ( const DebugInfo *di );
Expand Down Expand Up @@ -310,7 +312,8 @@ typedef
Vg_SectGOT,
Vg_SectPLT,
Vg_SectGOTPLT,
Vg_SectOPD
Vg_SectOPD,
Vg_SectPLTSEC
}
VgSectKind;

Expand Down