dmd demangle

Arun Chandrasekaran via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 30 19:51:25 PDT 2017


On Thursday, 31 August 2017 at 02:31:24 UTC, Michael V. Franklin 
wrote:
> On Thursday, 31 August 2017 at 02:20:00 UTC, Arun 
> Chandrasekaran wrote:
>> Just a thought. Can dmd demangle the symbols before spitting 
>> the output of ld to stderr?
>
> dmd doesn't print the output of ld to stderr, ld does.
>
> I believe binutils has some support for D symbol demangling 
> thanks to the GDC folks.  I tried it once:  
> http://forum.dlang.org/post/bdmsrcczmizevhxorquo@forum.dlang.org
>
> So I think you need to find a way to pass --demangle=dlang to 
> ld.
>  Maybe `dmd program.d -L--demangle=dlang`?
>
> Mike

Thanks Mike.

I was looking at src/ddmd/link.d, has the below that reads the 
output of ld. So I was wondering if we can plugin the demangle 
logic in this function. Nevertheless, good to know the linker 
already supports it.

```
     private int findNoMainError(int fd)
     {
         version (OSX)
         {
             static __gshared const(char)* nmeErrorMessage = 
"\"__Dmain\", referenced from:";
         }
         else
         {
             static __gshared const(char)* nmeErrorMessage = 
"undefined reference to `_Dmain'";
         }
         FILE* stream = fdopen(fd, "r");
         if (stream is null)
             return -1;
         const(size_t) len = 64 * 1024 - 1;
         char[len + 1] buffer; // + '\0'
         size_t beg = 0, end = len;
         bool nmeFound = false;
         for (;;)
         {
             // read linker output
             const(size_t) n = fread(&buffer[beg], 1, len - beg, 
stream);
             if (beg + n < len && ferror(stream))
                 return -1;
             buffer[(end = beg + n)] = '\0';
             // search error message, stop at last complete line
             const(char)* lastSep = strrchr(buffer.ptr, '\n');
             if (lastSep)
                 buffer[(end = lastSep - &buffer[0])] = '\0';
             if (strstr(&buffer[0], nmeErrorMessage))
                 nmeFound = true;
             if (lastSep)
                 buffer[end++] = '\n';
             if (fwrite(&buffer[0], 1, end, stderr) < end)
                 return -1;
             if (beg + n < len && feof(stream))
                 break;
             // copy over truncated last line
             memcpy(&buffer[0], &buffer[end], (beg = len - end));
         }
         return nmeFound ? 1 : 0;
     }
```


More information about the Digitalmars-d mailing list