aboutsummaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
authorPetr Malat <oss@malat.biz>2025-01-28 11:08:20 +0100
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2025-01-30 10:16:37 -0300
commit4c43173eba874039c96eca893041745c6d7be38a (patch)
tree92c4c4d375832168075395633b0a9f9ce6a95b5e /elf
parenta6fbe36b7f31292981422692236465ab56670ea9 (diff)
downloadglibc-4c43173eba874039c96eca893041745c6d7be38a.tar.xz
glibc-4c43173eba874039c96eca893041745c6d7be38a.zip
ld.so: Decorate BSS mappings
Decorate BSS mappings with [anon: glibc: .bss <file>], for example [anon: glibc: .bss /lib/libc.so.6]. The string ".bss" is already used by bionic so use the same, but add the filename as well. If the name would be longer than what the kernel allows, drop the directory part of the path. Refactor glibc.mem.decorate_maps check to a separate function and use it to avoid assembling a name, which would not be used later. Signed-off-by: Petr Malat <oss@malat.biz> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-map-segments.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index 203b6c7b0b..ee68dda550 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -18,6 +18,7 @@
<https://www.gnu.org/licenses/>. */
#include <dl-load.h>
+#include <setvmaname.h>
/* Map a segment and align it properly. */
@@ -182,12 +183,41 @@ _dl_map_segments (struct link_map *l, int fd,
if (zeroend > zeropage)
{
/* Map the remaining zero pages in from the zero fill FD. */
+ char bssname[ANON_VMA_NAME_MAX_LEN] = " glibc: .bss";
+
caddr_t mapat;
mapat = __mmap ((caddr_t) zeropage, zeroend - zeropage,
c->prot, MAP_ANON|MAP_PRIVATE|MAP_FIXED,
-1, 0);
if (__glibc_unlikely (mapat == MAP_FAILED))
return DL_MAP_SEGMENTS_ERROR_MAP_ZERO_FILL;
+ if (__is_decorate_maps_enabled ())
+ {
+ if (l->l_name != NULL && *l->l_name != '\0')
+ {
+ int i = strlen (bssname), j = 0;
+ int namelen = strlen (l->l_name);
+
+ bssname[i++] = ' ';
+ if (namelen > sizeof (bssname) - i - 1)
+ for (j = namelen - 1; j > 0; j--)
+ if (l->l_name[j - 1] == '/')
+ break;
+
+ for (; l->l_name[j] != '\0' && i < sizeof (bssname) - 1;
+ i++, j++)
+ {
+ char ch = l->l_name[j];
+ /* Replace non-printable characters and
+ \, `, $, [ and ]. */
+ if (ch <= 0x1f || ch >= 0x7f || strchr("\\`$[]", ch))
+ ch = '!';
+ bssname[i] = ch;
+ }
+ bssname[i] = 0;
+ }
+ __set_vma_name ((void*)zeropage, zeroend - zeropage, bssname);
+ }
}
}