various minor TODO cleanups

computeLinkerVariableStrinsg had an unusedargument.

Only skip obfuscating the name "FS" in the "embed" package.

The reflect methods no longer use the transformer receiver type,
so that TODO now feels unnecessary. Many methods need to be aware
of what the current types.Package is, and that seems reasonable.

We no longer use writeFileExclusive for our own cache on disk,
so the TODO about using locking or atomic writes is no longer relevant.
pull/760/head
Daniel Martí 1 year ago
parent 31d2d9263a
commit 59222cb14b

@ -952,7 +952,7 @@ func (tf *transformer) transformCompile(args []string) ([]string, error) {
// These maps are not kept in pkgCache, since they are only needed to obfuscate curPkg.
tf.fieldToStruct = computeFieldToStruct(tf.info)
if flagLiterals {
if tf.linkerVariableStrings, err = computeLinkerVariableStrings(tf.pkg, files); err != nil {
if tf.linkerVariableStrings, err = computeLinkerVariableStrings(tf.pkg); err != nil {
return nil, err
}
}
@ -1466,7 +1466,7 @@ func computePkgCache(fsCache *cache.Cache, lpkg *listedPackage, pkg *types.Packa
// computeLinkerVariableStrings iterates over the -ldflags arguments,
// filling a map with all the string values set via the linker's -X flag.
// TODO: can we put this in sharedCache, using objectString as a key?
func computeLinkerVariableStrings(pkg *types.Package, files []*ast.File) (map[*types.Var]string, error) {
func computeLinkerVariableStrings(pkg *types.Package) (map[*types.Var]string, error) {
linkerVariableStrings := make(map[*types.Var]string)
// TODO: this is a linker flag that affects how we obfuscate a package at
@ -1823,9 +1823,9 @@ func (tf *transformer) transformGoFile(file *ast.File) *ast.File {
}
case "embed":
// FS is detected by the compiler for //go:embed.
// TODO: We probably want a conditional, otherwise we're not
// obfuscating the embed package at all.
return name == "FS"
if name == "FS" {
return true
}
case "reflect":
switch name {
// Per the linker's deadcode.go docs,

@ -369,9 +369,6 @@ func (ri *reflectInspector) recursivelyRecordUsedForReflect(t types.Type) {
switch t := t.(type) {
case *types.Named:
obj := t.Obj()
// TODO: the transformer is only needed in this function, there is
// probably a way to do this with only the ssa information.
if obj.Pkg() == nil || obj.Pkg() != ri.pkg {
return // not from the specified package
}

@ -111,9 +111,6 @@ func createExclusive(name string) (*os.File, error) {
return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666)
}
// TODO(mvdan): consider using proper atomic file writes.
// Or possibly even "lockedfile", mimicking cmd/go.
func writeFileExclusive(name string, data []byte) error {
f, err := createExclusive(name)
if err != nil {

Loading…
Cancel
Save