1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

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>
This commit is contained in:
Petr Malat
2025-01-28 11:08:20 +01:00
committed by Adhemerval Zanella
parent a6fbe36b7f
commit 4c43173eba
5 changed files with 83 additions and 16 deletions

View File

@@ -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);
}
}
}