Skip to content

Commit

Permalink
cmd/link: correct type..importpath symbol handling
Browse files Browse the repository at this point in the history
The linker specially handles go.importpath symbols. But the
compiler doesn't actually generate such symbols. Instead, it
generates type..importpath symbols. It is already in the type
section as the name starts with "type.". Also set its alignment
to 1, as it is string data.

Change-Id: I771f5529a0ff41a5bb476b3a02c8cc75729792de
Reviewed-on: https://go-review.googlesource.com/c/go/+/353489
Trust: Cherry Mui <[email protected]>
Run-TryBot: Cherry Mui <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
  • Loading branch information
cherrymui committed Oct 1, 2021
1 parent 8d494b0 commit e5ad363
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/cmd/link/internal/ld/symtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,6 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
align := int32(1)
name := ldr.SymName(s)
switch {
case strings.HasPrefix(name, "go.importpath.") && ctxt.UseRelro():
// Keep go.importpath symbols in the same section as types and
// names, as they can be referred to by a section offset.
symGroupType[s] = sym.STYPERELRO

case strings.HasPrefix(name, "go.string."):
symGroupType[s] = sym.SGOSTRING
ldr.SetAttrNotInSymbolTable(s, true)
Expand Down Expand Up @@ -611,7 +606,7 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
ldr.SetCarrierSym(s, symtype)
}
}
if strings.HasPrefix(name, "type..namedata.") && ldr.SymAlign(s) == 0 {
if (strings.HasPrefix(name, "type..namedata.") || strings.HasPrefix(name, "type..importpath.")) && ldr.SymAlign(s) == 0 {
ldr.SetSymAlign(s, 1) // String data is just bytes, no padding.
}
}
Expand Down

0 comments on commit e5ad363

Please sign in to comment.