| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2018 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Loads of 8 byte go.strings cannot use DS relocation |
| 8 |
// in case the alignment is not a multiple of 4. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
import ( |
| 13 |
"fmt" |
| 14 |
) |
| 15 |
|
| 16 |
type Level string |
| 17 |
|
| 18 |
// The following are all go.strings. A link time error can |
| 19 |
// occur if an 8 byte load is used to load a go.string that is |
| 20 |
// not aligned to 4 bytes due to the type of relocation that |
| 21 |
// is generated for the instruction. A fix was made to avoid |
| 22 |
// generating an instruction with DS relocation for go.strings |
| 23 |
// since their alignment is not known until link time. |
| 24 |
|
| 25 |
// This problem only affects go.string since other types have |
| 26 |
// correct alignment. |
| 27 |
|
| 28 |
const ( |
| 29 |
LevelBad Level = "badvals" |
| 30 |
LevelNone Level = "No" |
| 31 |
LevelMetadata Level = "Metadata" |
| 32 |
LevelRequest Level = "Request" |
| 33 |
LevelRequestResponse Level = "RequestResponse" |
| 34 |
) |
| 35 |
|
| 36 |
func ordLevel(l Level) int { |
| 37 |
switch l { |
| 38 |
case LevelMetadata: |
| 39 |
return 1 |
| 40 |
case LevelRequest: |
| 41 |
return 2 |
| 42 |
case LevelRequestResponse: |
| 43 |
return 3 |
| 44 |
default: |
| 45 |
return 0 |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
//go:noinline |
| 50 |
func test(l Level) { |
| 51 |
if ordLevel(l) < ordLevel(LevelMetadata) { |
| 52 |
fmt.Printf("OK\n") |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
func main() { |
| 57 |
test(LevelMetadata) |
| 58 |
} |