]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: replace '·' as '.' in ELF/Mach-O symbol tables
authorShenghou Ma <minux.ma@gmail.com>
Fri, 14 Mar 2014 14:07:51 +0000 (10:07 -0400)
committerShenghou Ma <minux.ma@gmail.com>
Fri, 14 Mar 2014 14:07:51 +0000 (10:07 -0400)
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

src/cmd/ld/macho.c
src/cmd/ld/symtab.c

index 49db83eea252d86a82e1c61e32b9cde4f5a31bd3..0f9b0d2d2d46317b50388296af1625d3eec1cccf 100644 (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, '_');
-               addstring(symstr, s->extname);
+               // 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
index d26ea0d04ef5533656f47498a4ead26885b26875..22e5bb5d953f2b5bbf0c3220ccea6a639635238a 100644 (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;
 }