Skip to content

Commit eb73c6d

Browse files
committed
Merge branch 'master' of github.com:kevin-valerio/go-arithmetic-panik
2 parents 200f229 + 73b8df2 commit eb73c6d

File tree

103 files changed

+1047
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1047
-662
lines changed

doc/godebug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ crypto/x509.CreateCertificate. The setting `x509sha256skid=0` reverts to SHA-1.
189189
Go 1.25 corrected the semantics of contention reports for runtime-internal locks,
190190
and so removed the [`runtimecontentionstacks` setting](/pkg/runtime#hdr-Environment_Variables).
191191

192+
Go 1.25 (starting with Go 1.25 RC 2) disabled build information stamping when
193+
multiple VCS are detected due to concerns around VCS injection attacks. This
194+
behavior and setting was backported to Go 1.24.5 and Go 1.23.11. This behavior
195+
can be renabled with the setting `allowmultiplevcs=1`.
196+
192197
### Go 1.24
193198

194199
Go 1.24 added a new `fips140` setting that controls whether the Go

src/cmd/cgo/internal/testsanitizers/asan_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package sanitizers_test
88

99
import (
1010
"bytes"
11+
"crypto/fips140"
1112
"fmt"
1213
"internal/platform"
1314
"internal/testenv"
@@ -157,6 +158,10 @@ func mustHaveASAN(t *testing.T) *config {
157158
t.Skipf("skipping on %s/%s; -asan option is not supported.", goos, goarch)
158159
}
159160

161+
if fips140.Enabled() {
162+
t.Skipf("skipping with FIPS 140 mode; -asan option is not supported.")
163+
}
164+
160165
// The current implementation is only compatible with the ASan library from version
161166
// v7 to v9 (See the description in src/runtime/asan/asan.go). Therefore, using the
162167
// -asan option must use a compatible version of ASan library, which requires that

src/cmd/compile/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ The //go:nosplit directive must be followed by a function declaration.
253253
It specifies that the function must omit its usual stack overflow check.
254254
This is most commonly used by low-level runtime code invoked
255255
at times when it is unsafe for the calling goroutine to be preempted.
256+
Using this directive outside of low-level runtime code is not safe,
257+
because it permits the nosplit function to overwrite the end of stack,
258+
leading to memory corruption and arbitrary program failure.
256259
257260
# Linkname Directive
258261

src/cmd/compile/internal/base/debug.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type DebugFlags struct {
4040
InlFuncsWithClosures int `help:"allow functions with closures to be inlined" concurrent:"ok"`
4141
InlStaticInit int `help:"allow static initialization of inlined calls" concurrent:"ok"`
4242
Libfuzzer int `help:"enable coverage instrumentation for libfuzzer"`
43+
LiteralAllocHash string `help:"hash value for use in debugging literal allocation optimizations" concurrent:"ok"`
4344
LoopVar int `help:"shared (0, default), 1 (private loop variables), 2, private + log"`
4445
LoopVarHash string `help:"for debugging changes in loop behavior. Overrides experiment and loopvar flag."`
4546
LocationLists int `help:"print information about DWARF location list creation"`

src/cmd/compile/internal/base/flag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func ParseFlags() {
268268
if Debug.PGOHash != "" {
269269
PGOHash = NewHashDebug("pgohash", Debug.PGOHash, nil)
270270
}
271+
if Debug.LiteralAllocHash != "" {
272+
LiteralAllocHash = NewHashDebug("literalalloc", Debug.LiteralAllocHash, nil)
273+
}
274+
271275
if Debug.MergeLocalsHash != "" {
272276
MergeLocalsHash = NewHashDebug("mergelocals", Debug.MergeLocalsHash, nil)
273277
}

src/cmd/compile/internal/base/hashdebug.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var hashDebug *HashDebug
5656
var FmaHash *HashDebug // for debugging fused-multiply-add floating point changes
5757
var LoopVarHash *HashDebug // for debugging shared/private loop variable changes
5858
var PGOHash *HashDebug // for debugging PGO optimization decisions
59+
var LiteralAllocHash *HashDebug // for debugging literal allocation optimizations
5960
var MergeLocalsHash *HashDebug // for debugging local stack slot merging changes
6061
var VariableMakeHash *HashDebug // for debugging variable-sized make optimizations
6162

src/cmd/compile/internal/escape/escape.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,6 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
534534
if n.Op() != ir.OMAKESLICE && n.Op() != ir.OCONVIFACE {
535535
return
536536
}
537-
if base.Flag.Cfg.CoverageInfo != nil {
538-
// Avoid altering coverage results.
539-
return
540-
}
541537

542538
// Look up a cached ReassignOracle for the function, lazily computing one if needed.
543539
ro := b.reassignOracle(fn)
@@ -571,6 +567,10 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
571567
base.Fatalf("unexpected BasicLit Kind")
572568
}
573569
if constant.Compare(lit.Val(), token.GEQ, constant.MakeInt64(0)) {
570+
if !base.LiteralAllocHash.MatchPos(n.Pos(), nil) {
571+
// De-selected by literal alloc optimizations debug hash.
572+
return
573+
}
574574
// Preserve any side effects of the original expression, then replace it.
575575
assignTemp(*r, n.PtrInit())
576576
*r = lit
@@ -584,6 +584,10 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
584584
if conv.X.Op() != ir.OLITERAL && !conv.X.Type().IsInterface() {
585585
v := ro.StaticValue(conv.X)
586586
if v != nil && v.Op() == ir.OLITERAL && ir.ValidTypeForConst(conv.X.Type(), v.Val()) {
587+
if !base.LiteralAllocHash.MatchPos(n.Pos(), nil) {
588+
// De-selected by literal alloc optimizations debug hash.
589+
return
590+
}
587591
if base.Debug.EscapeDebug >= 3 {
588592
base.WarnfAt(n.Pos(), "rewriting OCONVIFACE value from %v (%v) to %v (%v)", conv.X, conv.X.Type(), v, v.Type())
589593
}

src/cmd/compile/internal/ssa/prove.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,15 +1917,22 @@ func (ft *factsTable) flowLimit(v *Value) bool {
19171917

19181918
// See if we can get any facts because v is the result of signed mod by a constant.
19191919
// The mod operation has already been rewritten, so we have to try and reconstruct it.
1920-
// x % d
1920+
//
1921+
// x % d
1922+
//
19211923
// is rewritten as
1922-
// x - (x / d) * d
1924+
//
1925+
// x - (x / d) * d
1926+
//
19231927
// furthermore, the divide itself gets rewritten. If d is a power of 2 (d == 1<<k), we do
1924-
// (x / d) * d = ((x + adj) >> k) << k
1925-
// = (x + adj) & (-1<<k)
1928+
//
1929+
// (x / d) * d = ((x + adj) >> k) << k
1930+
// = (x + adj) & (-1<<k)
1931+
//
19261932
// with adj being an adjustment in case x is negative (see below).
19271933
// if d is not a power of 2, we do
1928-
// x / d = ... TODO ...
1934+
//
1935+
// x / d = ... TODO ...
19291936
func (ft *factsTable) detectSignedMod(v *Value) bool {
19301937
if ft.detectSignedModByPowerOfTwo(v) {
19311938
return true

src/cmd/compile/internal/ssa/stmtlines_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func TestStmtLines(t *testing.T) {
120120
break
121121
}
122122
must(err)
123+
if le.EndSequence {
124+
// When EndSequence is true only
125+
// le.Address is meaningful, skip.
126+
continue
127+
}
123128
fl := Line{le.File.Name, le.Line}
124129
lines[fl] = lines[fl] || le.IsStmt
125130
}

src/cmd/compile/internal/walk/order.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,18 @@ func (o *orderState) addrTemp(n ir.Node) ir.Node {
246246
if v == nil {
247247
v = n
248248
}
249+
optEnabled := func(n ir.Node) bool {
250+
// Do this optimization only when enabled for this node.
251+
return base.LiteralAllocHash.MatchPos(n.Pos(), nil)
252+
}
249253
if (v.Op() == ir.OSTRUCTLIT || v.Op() == ir.OARRAYLIT) && !base.Ctxt.IsFIPS() {
250-
if ir.IsZero(v) && 0 < v.Type().Size() && v.Type().Size() <= abi.ZeroValSize {
254+
if ir.IsZero(v) && 0 < v.Type().Size() && v.Type().Size() <= abi.ZeroValSize && optEnabled(n) {
251255
// This zero value can be represented by the read-only zeroVal.
252256
zeroVal := ir.NewLinksymExpr(v.Pos(), ir.Syms.ZeroVal, n.Type())
253257
vstat := typecheck.Expr(zeroVal).(*ir.LinksymOffsetExpr)
254258
return vstat
255259
}
256-
if isStaticCompositeLiteral(v) {
260+
if isStaticCompositeLiteral(v) && optEnabled(n) {
257261
// v can be directly represented in the read-only data section.
258262
lit := v.(*ir.CompLitExpr)
259263
vstat := readonlystaticname(n.Type())

0 commit comments

Comments
 (0)