[PATCH] ld.so: Decorate BSS mappings
Petr Malat
oss@malat.biz
Tue Jan 21 09:25:12 GMT 2025
Decorate BSS mappings with [anon: .bss <file>], for example
[anon: .bss /lib/libc.so.6]. The string ".bss" is already used
by bionic so use the same, but add the filename as well.
Signed-off-by: Petr Malat <oss@malat.biz>
---
elf/dl-map-segments.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index 203b6c7b0b..cf6be4a783 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,31 @@ _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[80] = " .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 (l->l_name && *l->l_name)
+ {
+ int i = strlen(bssname), j = 0;
+ bssname[i++] = ' ';
+ if (strlen(l->l_name) > sizeof(bssname) - i - 1)
+ j = strlen(l->l_name) - (sizeof(bssname) - i - 1);
+ for (; l->l_name[j]; 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);
}
}
--
2.39.5
More information about the Libc-alpha
mailing list