From c86a230089d7dabd83e779f8c4e0cdc24ef74b04 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Fri, 14 Apr 2017 16:08:55 -0700 Subject: [PATCH] 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 --- crypto/fipsmodule/CMakeLists.txt | 2 +- crypto/fipsmodule/inject-hash.go | 54 ++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/crypto/fipsmodule/CMakeLists.txt b/crypto/fipsmodule/CMakeLists.txt index 90dbc5f0..7250ccb6 100644 --- a/crypto/fipsmodule/CMakeLists.txt +++ b/crypto/fipsmodule/CMakeLists.txt @@ -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 $ + 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 $ DEPENDS bcm_hashunset inject-hash.go ar.go const.go WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) diff --git a/crypto/fipsmodule/inject-hash.go b/crypto/fipsmodule/inject-hash.go index 7f2c9c91..b2e91aaf 100644 --- a/crypto/fipsmodule/inject-hash.go +++ b/crypto/fipsmodule/inject-hash.go @@ -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) }