Allow raw object files to be passed into inject-hash.go.
CMake loves making archives, but that's not universal. Change-Id: I5356b4701982748a46817e0094ad838605dcada6 Reviewed-on: https://boringssl-review.googlesource.com/15144 Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
08c9b84410
commit
c86a230089
@ -148,7 +148,7 @@ if(FIPS)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT bcm.o
|
||||
COMMAND ${GO_EXECUTABLE} run crypto/fipsmodule/inject-hash.go crypto/fipsmodule/ar.go crypto/fipsmodule/const.go -o ${CMAKE_CURRENT_BINARY_DIR}/bcm.o -in $<TARGET_FILE:bcm_hashunset>
|
||||
COMMAND ${GO_EXECUTABLE} run crypto/fipsmodule/inject-hash.go crypto/fipsmodule/ar.go crypto/fipsmodule/const.go -o ${CMAKE_CURRENT_BINARY_DIR}/bcm.o -in-archive $<TARGET_FILE:bcm_hashunset>
|
||||
DEPENDS bcm_hashunset inject-hash.go ar.go const.go
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
@ -30,25 +30,38 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func do(outPath, arInput string) error {
|
||||
arFile, err := os.Open(arInput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer arFile.Close()
|
||||
|
||||
ar, err := ParseAR(arFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ar) != 1 {
|
||||
return fmt.Errorf("expected one file in archive, but found %d", len(ar))
|
||||
}
|
||||
|
||||
func do(outPath, oInput string, arInput string) error {
|
||||
var objectBytes []byte
|
||||
for _, contents := range ar {
|
||||
objectBytes = contents
|
||||
if len(arInput) > 0 {
|
||||
if len(oInput) > 0 {
|
||||
return fmt.Errorf("-in-archive and -in-object are mutually exclusive")
|
||||
}
|
||||
|
||||
arFile, err := os.Open(arInput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer arFile.Close()
|
||||
|
||||
ar, err := ParseAR(arFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ar) != 1 {
|
||||
return fmt.Errorf("expected one file in archive, but found %d", len(ar))
|
||||
}
|
||||
|
||||
for _, contents := range ar {
|
||||
objectBytes = contents
|
||||
}
|
||||
} else if len(oInput) > 0 {
|
||||
var err error
|
||||
if objectBytes, err = ioutil.ReadFile(oInput); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("exactly one of -in-archive or -in-object is required")
|
||||
}
|
||||
|
||||
object, err := elf.NewFile(bytes.NewReader(objectBytes))
|
||||
@ -147,12 +160,13 @@ func do(outPath, arInput string) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
arInput := flag.String("in", "", "Path to a .a file")
|
||||
arInput := flag.String("in-archive", "", "Path to a .a file")
|
||||
oInput := flag.String("in-object", "", "Path to a .o file")
|
||||
outPath := flag.String("o", "", "Path to output object")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if err := do(*outPath, *arInput); err != nil {
|
||||
if err := do(*outPath, *oInput, *arInput); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user