Skip to content

Commit f766b68

Browse files
committed
cmd/asm: accept TEXT f+0(SB) in -gensymabis mode
f+0(SB) is a non-standard but acceptable alias for f(SB). Fixes golang#30968. Change-Id: I499ccee4d3ff3ab4e47f75d99407aace858e59aa Reviewed-on: https://go-review.googlesource.com/c/go/+/174537 Reviewed-by: Austin Clements <[email protected]>
1 parent 856b57e commit f766b68

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/cmd/asm/internal/asm/operand_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,18 @@ func TestFuncAddress(t *testing.T) {
145145

146146
isFuncSym := strings.HasSuffix(test.input, "(SB)") &&
147147
// Ignore static symbols.
148-
!strings.Contains(test.input, "<>") &&
149-
// Ignore symbols with offsets.
150-
!strings.Contains(test.input, "+")
148+
!strings.Contains(test.input, "<>")
151149

152150
wantName := ""
153151
if isFuncSym {
154-
// Strip $|* and (SB).
152+
// Strip $|* and (SB) and +Int.
155153
wantName = test.output[:len(test.output)-4]
156154
if strings.HasPrefix(wantName, "$") || strings.HasPrefix(wantName, "*") {
157155
wantName = wantName[1:]
158156
}
157+
if i := strings.Index(wantName, "+"); i >= 0 {
158+
wantName = wantName[:i]
159+
}
159160
}
160161
if ok != isFuncSym || name != wantName {
161162
t.Errorf("fail at %s as function address: got %s, %v; expected %s, %v", test.input, name, ok, wantName, isFuncSym)

src/cmd/asm/internal/asm/parse.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,9 @@ func (p *Parser) setPseudoRegister(addr *obj.Addr, reg string, isStatic bool, pr
800800

801801
// funcAddress parses an external function address. This is a
802802
// constrained form of the operand syntax that's always SB-based,
803-
// non-static, and has no additional offsets:
803+
// non-static, and has at most a simple integer offset:
804804
//
805-
// [$|*]sym(SB)
805+
// [$|*]sym[+Int](SB)
806806
func (p *Parser) funcAddress() (string, bool) {
807807
switch p.peek() {
808808
case '$', '*':
@@ -815,7 +815,14 @@ func (p *Parser) funcAddress() (string, bool) {
815815
if tok.ScanToken != scanner.Ident || p.atStartOfRegister(name) {
816816
return "", false
817817
}
818-
if p.next().ScanToken != '(' {
818+
tok = p.next()
819+
if tok.ScanToken == '+' {
820+
if p.next().ScanToken != scanner.Int {
821+
return "", false
822+
}
823+
tok = p.next()
824+
}
825+
if tok.ScanToken != '(' {
819826
return "", false
820827
}
821828
if reg := p.next(); reg.ScanToken != scanner.Ident || reg.String() != "SB" {

0 commit comments

Comments
 (0)