]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/asm: new -p option, changes to DWARF generation
authorThan McIntosh <thanm@google.com>
Fri, 6 Mar 2020 17:43:59 +0000 (12:43 -0500)
committerThan McIntosh <thanm@google.com>
Tue, 10 Mar 2020 18:59:06 +0000 (18:59 +0000)
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>
src/cmd/asm/internal/flags/flags.go
src/cmd/asm/main.go
src/cmd/go/internal/work/gc.go
src/cmd/internal/obj/plist.go

index 5fe3fd9d53c6f04afb8bce2d7750a99a423751fd..6aefc96639747d1cf9be235ca1e4cff12d6de9b3 100644 (file)
@@ -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 (
index 51f995055c9acd413a0df40bf5a05e97b52aeaef..d42093a48f3448065178753f9f413a5db7d3fa38 100644 (file)
@@ -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 {
index 7d17c0c01eda8c29099f0b3d96b8e1028df141d0..78db845ae7766aa71a99b469394a71d424fecf46 100644 (file)
@@ -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" {
index 7579dd0390694e30876fd39e11839611e55731e4..4d02042956a84e026e2cf4a145c7bd3053ef5694 100644 (file)
@@ -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)
+               }
        }
 }