Avoid modifying the object string table when patching USDT probes.

dtrace converts pairs of consecutive underscores in a probe name to dashes.
When dtrace -G processes relocations corresponding to USDT probe sites, it
performs this conversion on the corresponding symbol names prior to looking
up the resulting probe names in the USDT provider definition. However, in
so doing it would actually modify the input object's string table, which
breaks the string suffix merging done by recent binutils. Because we don't
care about the symbol name once the probe site is recorded, just perform the
probe lookup using a temporary copy.

Reported by:	hrs, swills
MFC after:	3 weeks
This commit is contained in:
Mark Johnston 2016-12-20 18:25:41 +00:00
parent 85b6e3b227
commit 3a3e3279e7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310332

View File

@ -1223,6 +1223,7 @@ process_obj(dtrace_hdl_t *dtp, const char *obj, int *eprobesp)
static const char dt_enabled[] = "enabled";
static const char dt_symprefix[] = "$dtrace";
static const char dt_symfmt[] = "%s%ld.%s";
char probename[DTRACE_NAMELEN];
int fd, i, ndx, eprobe, mod = 0;
Elf *elf = NULL;
GElf_Ehdr ehdr;
@ -1576,8 +1577,6 @@ process_obj(dtrace_hdl_t *dtp, const char *obj, int *eprobesp)
bcopy(s, pname, p - s);
pname[p - s] = '\0';
p = strhyphenate(p + 3); /* strlen("___") */
if (dt_symtab_lookup(data_sym, isym, rela.r_offset,
shdr_rel.sh_info, &fsym,
(emachine1 == EM_PPC64), elf) != 0)
@ -1628,10 +1627,14 @@ process_obj(dtrace_hdl_t *dtp, const char *obj, int *eprobesp)
"no such provider %s", pname));
}
if ((prp = dt_probe_lookup(pvp, p)) == NULL) {
if (strlcpy(probename, p + 3, sizeof (probename)) >=
sizeof (probename))
return (dt_link_error(dtp, elf, fd, bufs,
"no such probe %s", p));
}
"invalid probe name %s", probename));
(void) strhyphenate(probename);
if ((prp = dt_probe_lookup(pvp, probename)) == NULL)
return (dt_link_error(dtp, elf, fd, bufs,
"no such probe %s", probename));
assert(fsym.st_value <= rela.r_offset);