1
0
mirror of https://github.com/golang/go synced 2024-11-22 21:50:03 -07:00

cmd/gc: replace '·' as '.' in ELF/Mach-O symbol tables

Old versions of DTrace (as those shipped in OS X and FreeBSD)
don't support unicode characters in symbol names.  Replace '·'
to '.' to make DTrace happy.

Fixes #7493

LGTM=aram, rsc
R=aram, rsc, gobot, iant
CC=golang-codereviews
https://golang.org/cl/72280043
This commit is contained in:
Shenghou Ma 2014-03-14 10:07:51 -04:00
parent 199e703083
commit cbe777b2c7
2 changed files with 32 additions and 1 deletions

View File

@ -574,6 +574,7 @@ machosymtab(void)
{
int i;
LSym *symtab, *symstr, *s, *o;
char *p;
symtab = linklookup(ctxt, ".machosymtab", 0);
symstr = linklookup(ctxt, ".machosymstr", 0);
@ -585,7 +586,21 @@ machosymtab(void)
// Only add _ to C symbols. Go symbols have dot in the name.
if(strstr(s->extname, ".") == nil)
adduint8(ctxt, symstr, '_');
// replace "·" as ".", because DTrace cannot handle it.
if(strstr(s->extname, "·") == nil) {
addstring(symstr, s->extname);
} else {
p = s->extname;
while (*p++ != '\0') {
if(*p == '\xc2' && *(p+1) == '\xb7') {
adduint8(ctxt, symstr, '.');
p++;
} else {
adduint8(ctxt, symstr, *p);
}
}
adduint8(ctxt, symstr, '\0');
}
if(s->type == SDYNIMPORT || s->type == SHOSTOBJ) {
adduint8(ctxt, symtab, 0x01); // type N_EXT, external symbol
adduint8(ctxt, symtab, 0); // no section

View File

@ -40,6 +40,7 @@ static int
putelfstr(char *s)
{
int off, n;
char *p, *q;
if(elfstrsize == 0 && s[0] != 0) {
// first entry must be empty string
@ -54,6 +55,21 @@ putelfstr(char *s)
off = elfstrsize;
elfstrsize += n;
memmove(elfstrdat+off, s, n);
// replace "·" as ".", because DTrace cannot handle it.
p = strstr(s, "·");
if(p != nil) {
p = q = elfstrdat+off;
while (*q != '\0') {
if(*q == '\xc2' && *(q+1) == '\xb7') {
q += 2;
*p++ = '.';
elfstrsize--;
} else {
*p++ = *q++;
}
}
*p = '\0';
}
return off;
}