mirror of
https://github.com/golang/go.git
synced 2025-05-18 22:04:38 +00:00
[dev.link] cmd/asm: new -p option, changes to DWARF generation
Adds a new "-p" option to the assembler, for specifying the import path of the package being compiled. DWARF generation is now conditional on having a valid package path -- if we don't know the package path, then don't emit DWARF. This is intended to lay the groundwork for removing the various "patchDWARFname" hacks in the linker. Change-Id: I5f8315c0881791eb8fe1f2ba32f5bb0ae76f6b98 Reviewed-on: https://go-review.googlesource.com/c/go/+/222718 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
cdc1b19513
commit
9cae3b33c3
@ -23,6 +23,7 @@ var (
|
||||
Dynlink = flag.Bool("dynlink", false, "support references to Go symbols defined in other shared libraries")
|
||||
AllErrors = flag.Bool("e", false, "no limit on number of errors reported")
|
||||
SymABIs = flag.Bool("gensymabis", false, "write symbol ABI information to output file, don't assemble")
|
||||
Importpath = flag.String("p", "", "set expected package import to path")
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -73,7 +73,7 @@ func main() {
|
||||
pList.Firstpc, ok = parser.Parse()
|
||||
// reports errors to parser.Errorf
|
||||
if ok {
|
||||
obj.Flushplist(ctxt, pList, nil, "")
|
||||
obj.Flushplist(ctxt, pList, nil, *flags.Importpath)
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
|
@ -37,6 +37,17 @@ func (gcToolchain) linker() string {
|
||||
return base.Tool("link")
|
||||
}
|
||||
|
||||
func pkgPath(a *Action) string {
|
||||
p := a.Package
|
||||
ppath := p.ImportPath
|
||||
if cfg.BuildBuildmode == "plugin" {
|
||||
ppath = pluginPath(a)
|
||||
} else if p.Name == "main" && !p.Internal.ForceLibrary {
|
||||
ppath = "main"
|
||||
}
|
||||
return ppath
|
||||
}
|
||||
|
||||
func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, symabis string, asmhdr bool, gofiles []string) (ofile string, output []byte, err error) {
|
||||
p := a.Package
|
||||
objdir := a.Objdir
|
||||
@ -47,12 +58,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, s
|
||||
ofile = objdir + out
|
||||
}
|
||||
|
||||
pkgpath := p.ImportPath
|
||||
if cfg.BuildBuildmode == "plugin" {
|
||||
pkgpath = pluginPath(a)
|
||||
} else if p.Name == "main" && !p.Internal.ForceLibrary {
|
||||
pkgpath = "main"
|
||||
}
|
||||
pkgpath := pkgPath(a)
|
||||
gcargs := []string{"-p", pkgpath}
|
||||
if p.Module != nil && p.Module.GoVersion != "" && allowedVersion(p.Module.GoVersion) {
|
||||
gcargs = append(gcargs, "-lang=go"+p.Module.GoVersion)
|
||||
@ -240,7 +246,8 @@ func (a *Action) trimpath() string {
|
||||
func asmArgs(a *Action, p *load.Package) []interface{} {
|
||||
// Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files.
|
||||
inc := filepath.Join(cfg.GOROOT, "pkg", "include")
|
||||
args := []interface{}{cfg.BuildToolexec, base.Tool("asm"), "-trimpath", a.trimpath(), "-I", a.Objdir, "-I", inc, "-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch, forcedAsmflags, p.Internal.Asmflags}
|
||||
pkgpath := pkgPath(a)
|
||||
args := []interface{}{cfg.BuildToolexec, base.Tool("asm"), "-p", pkgpath, "-trimpath", a.trimpath(), "-I", a.Objdir, "-I", inc, "-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch, forcedAsmflags, p.Internal.Asmflags}
|
||||
if p.ImportPath == "runtime" && cfg.Goarch == "386" {
|
||||
for _, arg := range forcedAsmflags {
|
||||
if arg == "-dynlink" {
|
||||
|
@ -109,7 +109,9 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc, myimportpath string
|
||||
continue
|
||||
}
|
||||
linkpcln(ctxt, s)
|
||||
ctxt.populateDWARF(plist.Curfn, s, myimportpath)
|
||||
if myimportpath != "" {
|
||||
ctxt.populateDWARF(plist.Curfn, s, myimportpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user