Skip to content

Commit 1a3e66c

Browse files
committed
cmd/compile: make all positions x.go:1:1
This shrinks binaries by about 6%, if you're using -ldflags=-w. Backtraces should still work, with function names and PCs and arguments, but all line numbers will display as x.go:1. This breaks any tests that depend on correct line numbers. For example, net/http: --- FAIL: TestWriteHeaderNoCodeCheck_h1hijack (0.00s) x.go:1: stderr output = "http: response.WriteHeader on hijacked connection from net/http_test.testWriteHeaderAfterWrite.func1 (x.go:1)"; want "http: response.WriteHeader on hijacked connection from net/http_test.testWriteHeaderAfterWrite.func1 (clientserver_test.go:" --- FAIL: TestWriteHeaderNoCodeCheck_h1 (0.01s) x.go:1: stderr output = "http: superfluous response.WriteHeader call from net/http_test.testWriteHeaderAfterWrite.func1 (x.go:1)"; want "http: superfluous response.WriteHeader call from net/http_test.testWriteHeaderAfterWrite.func1 (clientserver_test.go:" FAIL FAIL net/http 13.940s Remove an invariant check in dwinl.go that's broken by this. See golang#38698. That may break debugging. But if you care enough about binary size to use this, you're already stripping binaries with -ldflags=-w. Remove a security check around cgo pragma placements. Unfortunate, but if you're using a hacked toolchain, you should always make sure your code still builds and passes tests with a regular toolchain. Change-Id: I56c7540ea856a3bdccf8d44b5c3dbd4803545015
1 parent 9d812cf commit 1a3e66c

File tree

3 files changed

+2
-10
lines changed

3 files changed

+2
-10
lines changed

src/cmd/compile/internal/gc/dwinl.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ func makePreinlineDclMap(fnsym *obj.LSym) map[varPos]int {
221221
DeclLine: pos.RelLine(),
222222
DeclCol: pos.Col(),
223223
}
224-
if _, found := m[vp]; found {
225-
Fatalf("child dcl collision on symbol %s within %v\n", n.Sym.Name, fnsym.Name)
226-
}
227224
m[vp] = i
228225
}
229226
return m

src/cmd/compile/internal/gc/noder.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,12 +1584,6 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P
15841584
}
15851585
fallthrough
15861586
case strings.HasPrefix(text, "go:cgo_"):
1587-
// For security, we disallow //go:cgo_* directives other
1588-
// than cgo_import_dynamic outside cgo-generated files.
1589-
// Exception: they are allowed in the standard library, for runtime and syscall.
1590-
if !isCgoGeneratedFile(pos) && !compiling_std {
1591-
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s only allowed in cgo-generated code", text)})
1592-
}
15931587
p.pragcgo(pos, text)
15941588
fallthrough // because of //go:cgo_unsafe_args
15951589
default:

src/cmd/compile/internal/syntax/pos.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Pos struct {
2121
}
2222

2323
// MakePos returns a new Pos for the given PosBase, line and column.
24-
func MakePos(base *PosBase, line, col uint) Pos { return Pos{base, sat32(line), sat32(col)} }
24+
func MakePos(base *PosBase, line, col uint) Pos { return Pos{base, 1, 1} }
2525

2626
// TODO(gri) IsKnown makes an assumption about linebase < 1.
2727
// Maybe we should check for Base() != nil instead.
@@ -99,6 +99,7 @@ type PosBase struct {
9999
// A file PosBase's position is relative to itself, with the
100100
// position being filename:1:1.
101101
func NewFileBase(filename string) *PosBase {
102+
filename = "x.go"
102103
base := &PosBase{MakePos(nil, linebase, colbase), filename, linebase, colbase}
103104
base.pos.base = base
104105
return base

0 commit comments

Comments
 (0)