|
Mark Wielaard |
91f534 |
commit 3bce9544deab0261c7c55ccdc46ce1f36e468040
|
|
Mark Wielaard |
91f534 |
Author: Mark Wielaard <mark@klomp.org>
|
|
Mark Wielaard |
91f534 |
Date: Thu Jul 12 13:56:00 2018 +0200
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
Accept read-only PT_LOAD segments and .rodata.
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
The new binutils ld -z separate-code option creates multiple read-only
|
|
Mark Wielaard |
91f534 |
PT_LOAD segments and might place .rodata in a non-executable segment.
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
Allow and keep track of separate read-only segments and allow a readonly
|
|
Mark Wielaard |
91f534 |
page with .rodata section.
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
Based on patches from Tom Hughes <tom@compton.nu> and
|
|
Mark Wielaard |
91f534 |
H.J. Lu <hjl.tools@gmail.com>.
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
https://bugs.kde.org/show_bug.cgi?id=395682
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
index 13991b6..c36d498 100644
|
|
Mark Wielaard |
91f534 |
--- a/coregrind/m_debuginfo/debuginfo.c
|
|
Mark Wielaard |
91f534 |
+++ b/coregrind/m_debuginfo/debuginfo.c
|
|
Mark Wielaard |
91f534 |
@@ -1126,9 +1126,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
|
|
Mark Wielaard |
91f534 |
# error "Unknown platform"
|
|
Mark Wielaard |
91f534 |
# endif
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
-# if defined(VGP_x86_darwin) && DARWIN_VERS >= DARWIN_10_7
|
|
Mark Wielaard |
91f534 |
is_ro_map = seg->hasR && !seg->hasW && !seg->hasX;
|
|
Mark Wielaard |
91f534 |
-# endif
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
# if defined(VGO_solaris)
|
|
Mark Wielaard |
91f534 |
is_rx_map = seg->hasR && seg->hasX && !seg->hasW;
|
|
Mark Wielaard |
91f534 |
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
|
|
Mark Wielaard |
91f534 |
index 62192f0..95b97d6 100644
|
|
Mark Wielaard |
91f534 |
--- a/coregrind/m_debuginfo/readelf.c
|
|
Mark Wielaard |
91f534 |
+++ b/coregrind/m_debuginfo/readelf.c
|
|
Mark Wielaard |
91f534 |
@@ -1881,7 +1881,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
|
|
Mark Wielaard |
91f534 |
Bool loaded = False;
|
|
Mark Wielaard |
91f534 |
for (j = 0; j < VG_(sizeXA)(di->fsm.maps); j++) {
|
|
Mark Wielaard |
91f534 |
const DebugInfoMapping* map = VG_(indexXA)(di->fsm.maps, j);
|
|
Mark Wielaard |
91f534 |
- if ( (map->rx || map->rw)
|
|
Mark Wielaard |
91f534 |
+ if ( (map->rx || map->rw || map->ro)
|
|
Mark Wielaard |
91f534 |
&& map->size > 0 /* stay sane */
|
|
Mark Wielaard |
91f534 |
&& a_phdr.p_offset >= map->foff
|
|
Mark Wielaard |
91f534 |
&& a_phdr.p_offset < map->foff + map->size
|
|
Mark Wielaard |
91f534 |
@@ -1912,6 +1912,16 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
|
|
Mark Wielaard |
91f534 |
i, (UWord)item.bias);
|
|
Mark Wielaard |
91f534 |
loaded = True;
|
|
Mark Wielaard |
91f534 |
}
|
|
Mark Wielaard |
91f534 |
+ if (map->ro
|
|
Mark Wielaard |
91f534 |
+ && (a_phdr.p_flags & (PF_R | PF_W | PF_X))
|
|
Mark Wielaard |
91f534 |
+ == PF_R) {
|
|
Mark Wielaard |
91f534 |
+ item.exec = False;
|
|
Mark Wielaard |
91f534 |
+ VG_(addToXA)(svma_ranges, &item);
|
|
Mark Wielaard |
91f534 |
+ TRACE_SYMTAB(
|
|
Mark Wielaard |
91f534 |
+ "PT_LOAD[%ld]: acquired as ro, bias 0x%lx\n",
|
|
Mark Wielaard |
91f534 |
+ i, (UWord)item.bias);
|
|
Mark Wielaard |
91f534 |
+ loaded = True;
|
|
Mark Wielaard |
91f534 |
+ }
|
|
Mark Wielaard |
91f534 |
}
|
|
Mark Wielaard |
91f534 |
}
|
|
Mark Wielaard |
91f534 |
if (!loaded) {
|
|
Mark Wielaard |
91f534 |
@@ -2179,17 +2189,25 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
|
|
Mark Wielaard |
91f534 |
}
|
|
Mark Wielaard |
91f534 |
}
|
|
Mark Wielaard |
91f534 |
|
|
Mark Wielaard |
91f534 |
- /* Accept .rodata where mapped as rx (data), even if zero-sized */
|
|
Mark Wielaard |
91f534 |
+ /* Accept .rodata where mapped as rx or rw (data), even if zero-sized */
|
|
Mark Wielaard |
91f534 |
if (0 == VG_(strcmp)(name, ".rodata")) {
|
|
Mark Wielaard |
91f534 |
- if (inrx && !di->rodata_present) {
|
|
Mark Wielaard |
91f534 |
- di->rodata_present = True;
|
|
Mark Wielaard |
91f534 |
+ if (!di->rodata_present) {
|
|
Mark Wielaard |
91f534 |
di->rodata_svma = svma;
|
|
Mark Wielaard |
91f534 |
- di->rodata_avma = svma + inrx->bias;
|
|
Mark Wielaard |
91f534 |
+ di->rodata_avma = svma;
|
|
Mark Wielaard |
91f534 |
di->rodata_size = size;
|
|
Mark Wielaard |
91f534 |
- di->rodata_bias = inrx->bias;
|
|
Mark Wielaard |
91f534 |
di->rodata_debug_svma = svma;
|
|
Mark Wielaard |
91f534 |
- di->rodata_debug_bias = inrx->bias;
|
|
Mark Wielaard |
91f534 |
- /* NB was 'inrw' prior to r11794 */
|
|
Mark Wielaard |
91f534 |
+ if (inrx) {
|
|
Mark Wielaard |
91f534 |
+ di->rodata_avma += inrx->bias;
|
|
Mark Wielaard |
91f534 |
+ di->rodata_bias = inrx->bias;
|
|
Mark Wielaard |
91f534 |
+ di->rodata_debug_bias = inrx->bias;
|
|
Mark Wielaard |
91f534 |
+ } else if (inrw) {
|
|
Mark Wielaard |
91f534 |
+ di->rodata_avma += inrw->bias;
|
|
Mark Wielaard |
91f534 |
+ di->rodata_bias = inrw->bias;
|
|
Mark Wielaard |
91f534 |
+ di->rodata_debug_bias = inrw->bias;
|
|
Mark Wielaard |
91f534 |
+ } else {
|
|
Mark Wielaard |
91f534 |
+ BAD(".rodata");
|
|
Mark Wielaard |
91f534 |
+ }
|
|
Mark Wielaard |
91f534 |
+ di->rodata_present = True;
|
|
Mark Wielaard |
91f534 |
TRACE_SYMTAB("acquiring .rodata svma = %#lx .. %#lx\n",
|
|
Mark Wielaard |
91f534 |
di->rodata_svma,
|
|
Mark Wielaard |
91f534 |
di->rodata_svma + di->rodata_size - 1);
|