Fix cgo for GCC 4.4

Firstly, with -Werror, GCC switched to printing warnings starting
with "error:". Widening the string matches solves this as the messages
are otherwise unchanged.

Secondly, GCC 4.4 outputs DWARF sections with with NUL bytes in all
the offsets and requires the relocation section for .debug_info to be
processed in order to result in valid DWARF data. Thus we add minimal
handling for relocation sections, which is sufficient for our needs.

BUG=1
Fixes #1.

R=rsc, iant
CC=go-dev
http://go/go-review/1017003
This commit is contained in:
Adam Langley 2009-11-02 12:02:16 -08:00
parent 6358cac7d8
commit 72ec930fa7
7 changed files with 236 additions and 6 deletions

View file

@ -78,9 +78,9 @@ func (p *Prog) loadDebugInfo() {
switch {
default:
continue;
case strings.Index(line, "warning: useless type name in empty declaration") >= 0:
case strings.Index(line, ": useless type name in empty declaration") >= 0:
what = "type";
case strings.Index(line, "warning: statement with no effect") >= 0:
case strings.Index(line, ": statement with no effect") >= 0:
what = "value";
case strings.Index(line, "undeclared") >= 0:
what = "error";
@ -114,7 +114,7 @@ func (p *Prog) loadDebugInfo() {
fatal("gcc failed:\n%s\non input:\n%s", stderr, b.Bytes());
}
// Scan DWARF info for top-level TagVariable entries with AttrName __cgo__i.
// Scan DWARF info for top-level TagVariable entries with AttrName __cgo__i.
types := make([]dwarf.Type, len(names));
r := d.Reader();
for {
@ -198,10 +198,10 @@ func (p *Prog) gccDebug(stdin []byte) (*dwarf.Data, string) {
machine,
"-Wall", // many warnings
"-Werror", // warnings are errors
"-o"+tmp, // write object to tmp
"-gdwarf-2", // generate DWARF v2 debugging symbols
"-o"+tmp, // write object to tmp
"-gdwarf-2", // generate DWARF v2 debugging symbols
"-c", // do not link
"-xc", // input language is C
"-xc", // input language is C
"-", // read input from standard input
};
_, stderr, ok := run(stdin, concat(base, p.GccOptions));