2015-01-22 10:48:02 -08:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// Package flags implements top-level flags and the usage message for the assembler.
|
|
|
|
|
package flags
|
|
|
|
|
|
|
|
|
|
import (
|
2017-10-05 15:37:13 -04:00
|
|
|
"cmd/internal/objabi"
|
2015-01-22 10:48:02 -08:00
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2015-01-28 15:41:12 -08:00
|
|
|
Debug = flag.Bool("debug", false, "dump instructions as they are parsed")
|
2016-05-18 13:27:11 -07:00
|
|
|
OutputFile = flag.String("o", "", "output file; default foo.o for /a/b/c/foo.s as first argument")
|
2015-01-28 15:41:12 -08:00
|
|
|
PrintOut = flag.Bool("S", false, "print assembly and machine code")
|
2015-02-24 14:28:49 -08:00
|
|
|
TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths")
|
2015-02-10 15:56:32 +13:00
|
|
|
Shared = flag.Bool("shared", false, "generate code that can be linked into a shared library")
|
2015-03-30 00:49:25 +00:00
|
|
|
Dynlink = flag.Bool("dynlink", false, "support references to Go symbols defined in other shared libraries")
|
2016-02-24 11:55:20 +01:00
|
|
|
AllErrors = flag.Bool("e", false, "no limit on number of errors reported")
|
2018-11-15 15:23:48 -05:00
|
|
|
SymABIs = flag.Bool("gensymabis", false, "write symbol ABI information to output file, don't assemble")
|
[dev.link] cmd/compile, cmd/asm: assign index to symbols
We are planning to use indices for symbol references, instead of
symbol names. Here we assign indices to symbols defined in the
package being compiled, and propagate the indices to the
dependent packages in the export data.
A symbol is referenced by a tuple, (package index, symbol index).
Normally, for a given symbol, this index is unique, and the
symbol index is globally consistent (but with exceptions, see
below). The package index is local to a compilation. For example,
when compiling the fmt package, fmt.Println gets assigned index
25, then all packages that reference fmt.Println will refer it
as (X, 25) with some X. X is the index for the fmt package, which
may differ in different compilations.
There are some symbols that do not have clear package affiliation,
such as dupOK symbols and linknamed symbols. We cannot give them
globally consistent indices. We categorize them as non-package
symbols, assign them with package index 1 and a symbol index that
is only meaningful locally.
Currently nothing will consume the indices.
All this is behind a flag, -newobj. The flag needs to be set for
all builds (-gcflags=all=-newobj -asmflags=all=-newobj), or none.
Change-Id: I18e489c531e9a9fbc668519af92c6116b7308cab
Reviewed-on: https://go-review.googlesource.com/c/go/+/196029
Reviewed-by: Than McIntosh <thanm@google.com>
2019-09-11 16:17:01 -04:00
|
|
|
Newobj = flag.Bool("newobj", false, "use new object file format")
|
2015-01-22 10:48:02 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
D MultiFlag
|
|
|
|
|
I MultiFlag
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
2016-02-24 11:55:20 +01:00
|
|
|
flag.Var(&D, "D", "predefined symbol with optional simple value -D=identifier=value; can be set multiple times")
|
2015-01-22 10:48:02 -08:00
|
|
|
flag.Var(&I, "I", "include directory; can be set multiple times")
|
2017-10-05 15:37:13 -04:00
|
|
|
objabi.AddVersionFlag() // -V
|
2015-01-22 10:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MultiFlag allows setting a value multiple times to collect a list, as in -I=dir1 -I=dir2.
|
|
|
|
|
type MultiFlag []string
|
|
|
|
|
|
|
|
|
|
func (m *MultiFlag) String() string {
|
2015-11-17 13:23:25 -08:00
|
|
|
if len(*m) == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2015-01-22 10:48:02 -08:00
|
|
|
return fmt.Sprint(*m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MultiFlag) Set(val string) error {
|
|
|
|
|
(*m) = append(*m, val)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Usage() {
|
2016-05-18 13:27:11 -07:00
|
|
|
fmt.Fprintf(os.Stderr, "usage: asm [options] file.s ...\n")
|
2015-01-22 10:48:02 -08:00
|
|
|
fmt.Fprintf(os.Stderr, "Flags:\n")
|
|
|
|
|
flag.PrintDefaults()
|
|
|
|
|
os.Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 13:28:17 -04:00
|
|
|
func Parse() {
|
2015-01-22 10:48:02 -08:00
|
|
|
flag.Usage = Usage
|
|
|
|
|
flag.Parse()
|
2016-05-18 13:27:11 -07:00
|
|
|
if flag.NArg() == 0 {
|
2015-01-22 10:48:02 -08:00
|
|
|
flag.Usage()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flag refinement.
|
|
|
|
|
if *OutputFile == "" {
|
2016-05-18 13:27:11 -07:00
|
|
|
if flag.NArg() != 1 {
|
|
|
|
|
flag.Usage()
|
|
|
|
|
}
|
2015-01-22 10:48:02 -08:00
|
|
|
input := filepath.Base(flag.Arg(0))
|
|
|
|
|
if strings.HasSuffix(input, ".s") {
|
|
|
|
|
input = input[:len(input)-2]
|
|
|
|
|
}
|
2015-05-21 13:28:17 -04:00
|
|
|
*OutputFile = fmt.Sprintf("%s.o", input)
|
2015-01-22 10:48:02 -08:00
|
|
|
}
|
|
|
|
|
}
|