Skip to content

Commit

Permalink
liblink: make GO_ARGS the default for functions beginning with ·
Browse files Browse the repository at this point in the history
If there is a leading ·, assume there is a Go prototype and
attach the Go prototype information to the function.
If the function is not called from Go and does not need a
Go prototype, it can be made file-local instead (using name<>(SB)).

This fixes the current BSD build failures, by giving functions like
sync/atomic.StoreUint32 argument stack map information.

Fixes golang#8753.

LGTM=khr, iant
R=golang-codereviews, iant, khr, bradfitz
CC=golang-codereviews, r, rlh
https://golang.org/cl/142150043
  • Loading branch information
rsc committed Sep 16, 2014
1 parent f1abe0d commit 653fb6d
Show file tree
Hide file tree
Showing 25 changed files with 42 additions and 112 deletions.
23 changes: 22 additions & 1 deletion src/liblink/objfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static LSym *rdsym(Link*, Biobuf*, char*);
void
writeobj(Link *ctxt, Biobuf *b)
{
int flag;
int flag, found;
Hist *h;
LSym *s, *text, *etext, *curtext, *data, *edata;
Plist *pl;
Expand Down Expand Up @@ -251,6 +251,27 @@ writeobj(Link *ctxt, Biobuf *b)
s->etext = p;
}
}

// Add reference to Go arguments for C or assembly functions without them.
for(s = text; s != nil; s = s->next) {
if(strncmp(s->name, "\"\".", 3) != 0)
continue;
found = 0;
for(p = s->text; p != nil; p = p->link) {
if(p->as == ctxt->arch->AFUNCDATA && p->from.type == ctxt->arch->D_CONST && p->from.offset == FUNCDATA_ArgsPointerMaps) {
found = 1;
break;
}
}
if(!found) {
p = appendp(ctxt, s->text);
p->as = ctxt->arch->AFUNCDATA;
p->from.type = ctxt->arch->D_CONST;
p->from.offset = FUNCDATA_ArgsPointerMaps;
p->to.type = ctxt->arch->D_EXTERN;
p->to.sym = linklookup(ctxt, smprint("%s.args_stackmap", s->name), s->version);
}
}

// Turn functions into machine code images.
for(s = text; s != nil; s = s->next) {
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/asm_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,13 @@ TEXT gosave<>(SB),NOSPLIT,$0
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT runtime·asmcgocall(SB),NOSPLIT,$0-8
GO_ARGS
TEXT ·asmcgocall(SB),NOSPLIT,$0-8
MOVL fn+0(FP), AX
MOVL arg+4(FP), BX
CALL asmcgocall<>(SB)
RET

TEXT runtime·asmcgocall_errno(SB),NOSPLIT,$0-12
GO_ARGS
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-12
MOVL fn+0(FP), AX
MOVL arg+4(FP), BX
CALL asmcgocall<>(SB)
Expand Down Expand Up @@ -714,8 +712,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$12-12

// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
// See cgocall.c for more details.
TEXT runtime·cgocallback_gofunc(SB),NOSPLIT,$12-12
GO_ARGS
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$12-12
NO_LOCAL_POINTERS

// If g is nil, Go did not create the current thread.
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,13 @@ TEXT gosave<>(SB),NOSPLIT,$0
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT runtime·asmcgocall(SB),NOSPLIT,$0-16
GO_ARGS
TEXT ·asmcgocall(SB),NOSPLIT,$0-16
MOVQ fn+0(FP), AX
MOVQ arg+8(FP), BX
CALL asmcgocall<>(SB)
RET

TEXT runtime·asmcgocall_errno(SB),NOSPLIT,$0-20
GO_ARGS
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-20
MOVQ fn+0(FP), AX
MOVQ arg+8(FP), BX
CALL asmcgocall<>(SB)
Expand Down Expand Up @@ -700,8 +698,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$24-24

// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
// See cgocall.c for more details.
TEXT runtime·cgocallback_gofunc(SB),NOSPLIT,$8-24
GO_ARGS
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$8-24
NO_LOCAL_POINTERS

// If g is nil, Go did not create the current thread.
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/asm_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,13 @@ TEXT gosave<>(SB),NOSPLIT,$0
// Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI.
// See cgocall.c for more details.
TEXT runtime·asmcgocall(SB),NOSPLIT,$0-8
GO_ARGS
TEXT ·asmcgocall(SB),NOSPLIT,$0-8
MOVW fn+0(FP), R1
MOVW arg+4(FP), R0
BL asmcgocall<>(SB)
RET

TEXT runtime·asmcgocall_errno(SB),NOSPLIT,$0-12
GO_ARGS
TEXT ·asmcgocall_errno(SB),NOSPLIT,$0-12
MOVW fn+0(FP), R1
MOVW arg+4(FP), R0
BL asmcgocall<>(SB)
Expand Down Expand Up @@ -551,8 +549,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$12-12

// cgocallback_gofunc(void (*fn)(void*), void *frame, uintptr framesize)
// See cgocall.c for more details.
TEXT runtime·cgocallback_gofunc(SB),NOSPLIT,$8-12
GO_ARGS
TEXT ·cgocallback_gofunc(SB),NOSPLIT,$8-12
NO_LOCAL_POINTERS

// Load m and g from thread-local storage.
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/asm_darwin_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// Trap # in AX, args on stack above caller pc.

TEXT ·Syscall(SB),NOSPLIT,$0-28
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand All @@ -42,7 +41,6 @@ ok:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-40
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand Down Expand Up @@ -70,7 +68,6 @@ ok6:
RET

TEXT ·Syscall9(SB),NOSPLIT,$0-52
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand Down Expand Up @@ -101,7 +98,6 @@ ok9:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-28
GO_ARGS
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
LEAL 8(SP), SI
Expand All @@ -123,7 +119,6 @@ ok1:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
GO_ARGS
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
LEAL 8(SP), SI
Expand Down
4 changes: 0 additions & 4 deletions src/syscall/asm_darwin_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// Trap # in AX, args in DI SI DX, return in AX DX

TEXT ·Syscall(SB),NOSPLIT,$0-56
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
Expand All @@ -42,7 +41,6 @@ ok:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-80
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
Expand All @@ -67,7 +65,6 @@ ok6:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-56
GO_ARGS
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
Expand All @@ -89,7 +86,6 @@ ok1:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
GO_ARGS
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/asm_dragonfly_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Trap # in AX, args on stack above caller pc.

TEXT ·Syscall(SB),NOSPLIT,$0-32
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand All @@ -39,7 +38,6 @@ ok:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-44
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand Down Expand Up @@ -67,7 +65,6 @@ ok6:
RET

TEXT ·Syscall9(SB),NOSPLIT,$0-56
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand Down Expand Up @@ -98,7 +95,6 @@ ok9:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-32
GO_ARGS
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
LEAL 8(SP), SI
Expand All @@ -120,7 +116,6 @@ ok1:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-44
GO_ARGS
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
LEAL 8(SP), SI
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/asm_dragonfly_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// Trap # in AX, args in DI SI DX, return in AX DX

TEXT ·Syscall(SB),NOSPLIT,$0-64
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
Expand All @@ -39,7 +38,6 @@ ok:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-88
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
Expand All @@ -63,7 +61,6 @@ ok6:
RET

TEXT ·Syscall9(SB),NOSPLIT,$0-112
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 8(SP), AX
MOVQ 16(SP), DI
Expand Down Expand Up @@ -97,7 +94,6 @@ ok9:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-64
GO_ARGS
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
Expand All @@ -118,7 +114,6 @@ ok1:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-88
GO_ARGS
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/asm_freebsd_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// Trap # in AX, args on stack above caller pc.

TEXT ·Syscall(SB),NOSPLIT,$0-28
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand All @@ -42,7 +41,6 @@ ok:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-40
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand Down Expand Up @@ -70,7 +68,6 @@ ok6:
RET

TEXT ·Syscall9(SB),NOSPLIT,$0-52
GO_ARGS
CALL runtime·entersyscall(SB)
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
Expand Down Expand Up @@ -101,7 +98,6 @@ ok9:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-28
GO_ARGS
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
LEAL 8(SP), SI
Expand All @@ -123,7 +119,6 @@ ok1:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
GO_ARGS
MOVL 4(SP), AX // syscall entry
// slide args down on top of system call number
LEAL 8(SP), SI
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/asm_freebsd_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// Trap # in AX, args in DI SI DX, return in AX DX

TEXT ·Syscall(SB),NOSPLIT,$0-56
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
Expand All @@ -47,7 +46,6 @@ ok:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-80
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 16(SP), DI
MOVQ 24(SP), SI
Expand All @@ -71,7 +69,6 @@ ok6:
RET

TEXT ·Syscall9(SB),NOSPLIT,$0-104
GO_ARGS
CALL runtime·entersyscall(SB)
MOVQ 8(SP), AX
MOVQ 16(SP), DI
Expand Down Expand Up @@ -105,7 +102,6 @@ ok9:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-56
GO_ARGS
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
Expand All @@ -126,7 +122,6 @@ ok1:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
GO_ARGS
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/asm_freebsd_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, errno uintptr)

TEXT ·Syscall(SB),NOSPLIT,$0-28
GO_ARGS
BL runtime·entersyscall(SB)
MOVW 0(FP), R7 // syscall number
MOVW 4(FP), R0 // a1
Expand All @@ -37,7 +36,6 @@ error:
RET

TEXT ·Syscall6(SB),NOSPLIT,$0-40
GO_ARGS
BL runtime·entersyscall(SB)
MOVW 0(FP), R7 // syscall number
MOVW 4(FP), R0 // a1
Expand All @@ -64,7 +62,6 @@ error6:
RET

TEXT ·Syscall9(SB),NOSPLIT,$0-52
GO_ARGS
BL runtime·entersyscall(SB)
MOVW 0(FP), R7 // syscall number
MOVW 4(FP), R0 // a1
Expand All @@ -91,7 +88,6 @@ error9:
RET

TEXT ·RawSyscall(SB),NOSPLIT,$0-28
GO_ARGS
MOVW 0(FP), R7 // syscall number
MOVW 4(FP), R0 // a1
MOVW 8(FP), R1 // a2
Expand All @@ -111,7 +107,6 @@ errorr:
RET

TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
GO_ARGS
MOVW 0(FP), R7 // syscall number
MOVW 4(FP), R0 // a1
MOVW 8(FP), R1 // a2
Expand Down
Loading

0 comments on commit 653fb6d

Please sign in to comment.