Skip to content

Commit

Permalink
fix #14 by exporting ArchiveMember.IsDataObj to allow users to create…
Browse files Browse the repository at this point in the history
… data archive members themselves
  • Loading branch information
capnspacehook committed Oct 21, 2020
1 parent 23d7355 commit cc437dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions goobj2/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
)

const (
CompilerObjName = "__.PKGDEF"

archiveHeaderLen = 60
initSymName = `""..inittask`
objHeaderLen = 80
)

// A Package is a parsed Go object file or archive defining a Go package.
Expand Down Expand Up @@ -60,20 +60,15 @@ type ArchiveMember struct {
NonPkgSymRefs []*Sym
SymRefs []SymRef

IsDataObj bool

textSyms []*Sym

symMap map[int]*Sym

isCompilerObj bool
isDataObj bool
}

func (a ArchiveMember) IsCompilerObj() bool {
return a.isCompilerObj
}

func (a ArchiveMember) IsDataObj() bool {
return a.isDataObj
return a.ArchiveHeader.Name == CompilerObjName
}

type ArchiveHeader struct {
Expand Down Expand Up @@ -534,7 +529,7 @@ func (r *objReader) parseArchive(importCfg ImportCfg, returnReader bool) (*goobj

var am *ArchiveMember
switch ar.Name {
case "__.PKGDEF":
case CompilerObjName:
ar.Data = make([]byte, size)
if err := r.readFull(ar.Data); err != nil {
return nil, err
Expand All @@ -545,7 +540,7 @@ func (r *objReader) parseArchive(importCfg ImportCfg, returnReader bool) (*goobj

am = new(ArchiveMember)
am.ArchiveHeader = ar
am.isCompilerObj = true
am.IsDataObj = true
default:
oldLimit := r.limit
r.limit = r.offset + size
Expand Down Expand Up @@ -573,7 +568,7 @@ func (r *objReader) parseArchive(importCfg ImportCfg, returnReader bool) (*goobj
if fsize != size {
ar.Data = append(ar.Data, 0x00)
}
am = &ArchiveMember{ArchiveHeader: ar, isDataObj: true}
am = &ArchiveMember{ArchiveHeader: ar, IsDataObj: true}
}

r.skip(r.limit - r.offset)
Expand Down
2 changes: 1 addition & 1 deletion goobj2/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (pkg *Package) Write(path string) (err error) {
b.Write(arhdr[:])
curObjStartOff = b.Offset()
b.Write(ar.Data)
if ctxt.isCompilerObj || ctxt.isDataObj {
if ctxt.IsDataObj {
continue
}

Expand Down

0 comments on commit cc437dc

Please sign in to comment.