/
tool_asm.go
71 lines (60 loc) · 1.35 KB
/
tool_asm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 The Prime Citizens
package toolchain
import (
"os"
"path/filepath"
"strings"
"github.com/primecitizens/pcz/cmd/utils/fsutils"
)
func (t *Toolchain) asm(
p *Package,
symabiFile string,
asmhdrFile string,
) (objFiles []string, err error) {
if len(p.SFiles) == 0 {
return
}
for _, file := range p.SFiles {
output := t.getPathInBuildDir(p, strings.TrimSuffix(file, ".s")+".o")
err = fsutils.TemporaryWritable(
func() error {
return t.run(p.Dir, nil, os.Stdout, os.Stderr,
t.createASMArgs(p, nil,
"-I", filepath.Dir(asmhdrFile),
"-o", output,
file,
)...,
)
},
output,
)
if err != nil {
return
}
objFiles = append(objFiles, output)
}
return
}
func (t *Toolchain) createASMArgs(p *Package, sfiles []string, args ...string) []string {
flags := t.opts.AppendASMFlags(
t.binAsm,
"-I", p.Dir,
"-I", GoDefaultIncludeDir,
"-e", // no limit on number of errors reported
"-shared",
"-compiling-runtime", // always compile as runtime (so that we can use ABIInternal)
"-p", p.ImportComment,
)
if t.opts.Trimpath {
flags = t.appendTrimpathFlag(p, flags)
}
flags = append(flags, args...)
for _, sfile := range sfiles {
if !filepath.IsAbs(sfile) {
sfile = filepath.Join(p.Dir, sfile)
}
flags = append(flags, sfile)
}
return flags
}