Skip to content

Commit cf59ef1

Browse files
committed
feat: add support for .plt.sec sections
1 parent 2989c21 commit cf59ef1

5 files changed

Lines changed: 67 additions & 2 deletions

File tree

callgrind/fn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ fn_node* CLG_(get_fn_node)(BB* bb)
663663
pure[1] = fn;
664664
fn->pure_cxt = CLG_(get_cxt)(pure+1);
665665

666-
if (bb->sect_kind == Vg_SectPLT)
666+
if (bb->sect_kind == Vg_SectPLT || bb->sect_kind == Vg_SectPLTSEC)
667667
fn->skip = CLG_(clo).skip_plt;
668668

669669
if (VG_(strncmp)(fn->name, "_dl_runtime_resolve", 19)==0) {

coregrind/m_debuginfo/debuginfo.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4975,6 +4975,16 @@ SizeT VG_(DebugInfo_get_plt_size)(const DebugInfo* di)
49754975
return di->plt_present ? di->plt_size : 0;
49764976
}
49774977

4978+
Addr VG_(DebugInfo_get_pltsec_avma)(const DebugInfo* di)
4979+
{
4980+
return di->pltsec_present ? di->pltsec_avma : 0;
4981+
}
4982+
4983+
SizeT VG_(DebugInfo_get_pltsec_size)(const DebugInfo* di)
4984+
{
4985+
return di->pltsec_present ? di->pltsec_size : 0;
4986+
}
4987+
49784988
Addr VG_(DebugInfo_get_gotplt_avma)(const DebugInfo* di)
49794989
{
49804990
return di->gotplt_present ? di->gotplt_avma : 0;
@@ -5053,6 +5063,7 @@ const HChar* VG_(pp_SectKind)( VgSectKind kind )
50535063
case Vg_SectPLT: return "PLT";
50545064
case Vg_SectOPD: return "OPD";
50555065
case Vg_SectGOTPLT: return "GOTPLT";
5066+
case Vg_SectPLTSEC: return "PLTSEC";
50565067
default: vg_assert(0);
50575068
}
50585069
}
@@ -5115,6 +5126,12 @@ VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/const HChar** objname, Addr a)
51155126
res = Vg_SectPLT;
51165127
break;
51175128
}
5129+
if (di->pltsec_present
5130+
&& di->pltsec_size > 0
5131+
&& a >= di->pltsec_avma && a < di->pltsec_avma + di->pltsec_size) {
5132+
res = Vg_SectPLTSEC;
5133+
break;
5134+
}
51185135
if (di->got_present
51195136
&& di->got_size > 0
51205137
&& a >= di->got_avma && a < di->got_avma + di->got_size) {

coregrind/m_debuginfo/priv_storage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ struct _DebugInfo {
905905
Bool plt_present;
906906
Addr plt_avma;
907907
SizeT plt_size;
908+
/* .plt.sec */
909+
Bool pltsec_present;
910+
Addr pltsec_avma;
911+
SizeT pltsec_size;
908912
/* .got */
909913
Bool got_present;
910914
Addr got_avma;

coregrind/m_debuginfo/readelf.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,17 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
27342734
BAD(".plt");
27352735
}
27362736
}
2737+
/* Accept .plt.sec where mapped as rx (code) - hardened PLT section */
2738+
if (0 == VG_(strcmp)(name, ".plt.sec")) {
2739+
if (inrx && !di->pltsec_present) {
2740+
di->pltsec_present = True;
2741+
di->pltsec_avma = svma + inrx->bias;
2742+
di->pltsec_size = size;
2743+
TRACE_SYMTAB("acquiring .plt.sec avma = %#lx\n", di->pltsec_avma);
2744+
} else {
2745+
BAD(".plt.sec");
2746+
}
2747+
}
27372748
# elif defined(VGP_ppc32_linux)
27382749
/* Accept .plt where mapped as rw (data) */
27392750
if (0 == VG_(strcmp)(name, ".plt")) {
@@ -2746,6 +2757,17 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
27462757
BAD(".plt");
27472758
}
27482759
}
2760+
/* Accept .plt.sec where mapped as rw (data) - hardened PLT section */
2761+
if (0 == VG_(strcmp)(name, ".plt.sec")) {
2762+
if (inrw1 && !di->pltsec_present) {
2763+
di->pltsec_present = True;
2764+
di->pltsec_avma = svma + inrw1->bias;
2765+
di->pltsec_size = size;
2766+
TRACE_SYMTAB("acquiring .plt.sec avma = %#lx\n", di->pltsec_avma);
2767+
} else {
2768+
BAD(".plt.sec");
2769+
}
2770+
}
27492771
# elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
27502772
/* Accept .plt where mapped as rw (data), or unmapped */
27512773
if (0 == VG_(strcmp)(name, ".plt")) {
@@ -2766,6 +2788,25 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
27662788
BAD(".plt");
27672789
}
27682790
}
2791+
/* Accept .plt.sec where mapped as rw (data), or unmapped - hardened PLT section */
2792+
if (0 == VG_(strcmp)(name, ".plt.sec")) {
2793+
if (inrw1 && !di->pltsec_present) {
2794+
di->pltsec_present = True;
2795+
di->pltsec_avma = svma + inrw1->bias;
2796+
di->pltsec_size = size;
2797+
TRACE_SYMTAB("acquiring .plt.sec avma = %#lx\n", di->pltsec_avma);
2798+
} else
2799+
if ((!inrw1) && (!inrx) && size > 0 && !di->pltsec_present) {
2800+
/* File contains a .plt.sec, but it didn't get mapped.
2801+
Presumably it is not required on this platform. At
2802+
least don't reject the situation as invalid. */
2803+
di->pltsec_present = True;
2804+
di->pltsec_avma = 0;
2805+
di->pltsec_size = 0;
2806+
} else {
2807+
BAD(".plt.sec");
2808+
}
2809+
}
27692810
# else
27702811
# error "Unsupported platform"
27712812
# endif

include/pub_tool_debuginfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ Addr VG_(DebugInfo_get_bss_avma) ( const DebugInfo *di );
282282
SizeT VG_(DebugInfo_get_bss_size) ( const DebugInfo *di );
283283
Addr VG_(DebugInfo_get_plt_avma) ( const DebugInfo *di );
284284
SizeT VG_(DebugInfo_get_plt_size) ( const DebugInfo *di );
285+
Addr VG_(DebugInfo_get_pltsec_avma) ( const DebugInfo *di );
286+
SizeT VG_(DebugInfo_get_pltsec_size) ( const DebugInfo *di );
285287
Addr VG_(DebugInfo_get_gotplt_avma) ( const DebugInfo *di );
286288
SizeT VG_(DebugInfo_get_gotplt_size) ( const DebugInfo *di );
287289
Addr VG_(DebugInfo_get_got_avma) ( const DebugInfo *di );
@@ -310,7 +312,8 @@ typedef
310312
Vg_SectGOT,
311313
Vg_SectPLT,
312314
Vg_SectGOTPLT,
313-
Vg_SectOPD
315+
Vg_SectOPD,
316+
Vg_SectPLTSEC
314317
}
315318
VgSectKind;
316319

0 commit comments

Comments
 (0)