File tree 3 files changed +14
-2
lines changed
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -688,20 +688,25 @@ func (c *compilerContext) getGlobalInfo(g *ssa.Global) globalInfo {
688
688
// Check for //go: pragmas, which may change the link name (among others).
689
689
doc := c .astComments [info .linkName ]
690
690
if doc != nil {
691
- info .parsePragmas (doc )
691
+ info .parsePragmas (doc , g )
692
692
}
693
693
return info
694
694
}
695
695
696
696
// Parse //go: pragma comments from the source. In particular, it parses the
697
697
// //go:extern pragma on globals.
698
- func (info * globalInfo ) parsePragmas (doc * ast.CommentGroup ) {
698
+ func (info * globalInfo ) parsePragmas (doc * ast.CommentGroup , g * ssa. Global ) {
699
699
for _ , comment := range doc .List {
700
700
if ! strings .HasPrefix (comment .Text , "//go:" ) {
701
701
continue
702
702
}
703
703
parts := strings .Fields (comment .Text )
704
704
switch parts [0 ] {
705
+ case "//go:linkname" :
706
+ if len (parts ) == 3 && g .Name () == parts [1 ] {
707
+ info .linkName = parts [2 ]
708
+ info .extern = true
709
+ }
705
710
case "//go:extern" :
706
711
info .extern = true
707
712
if len (parts ) == 2 {
Original file line number Diff line number Diff line change @@ -2,6 +2,12 @@ package main
2
2
3
3
import _ "unsafe"
4
4
5
+ // Use the go:linkname mechanism to link this global to a different package.
6
+ // This is used in math/bits.
7
+ //
8
+ //go:linkname linknamedGlobal runtime.testLinknamedGlobal
9
+ var linknamedGlobal int
10
+
5
11
// Creates an external global with name extern_global.
6
12
//
7
13
//go:extern extern_global
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ source_filename = "pragma.go"
3
3
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
4
4
target triple = "wasm32-unknown-wasi"
5
5
6
+ @runtime.testLinknamedGlobal = external global i32 , align 4
6
7
@extern_global = external global [0 x i8 ], align 1
7
8
@main.alignedGlobal = hidden global [4 x i32 ] zeroinitializer , align 32
8
9
@main.alignedGlobal16 = hidden global [4 x i32 ] zeroinitializer , align 16
You can’t perform that action at this time.
0 commit comments