@@ -10,6 +10,8 @@ import (
1010 "text/template"
1111)
1212
13+ var ldArgs = []string {"-G 0" , "-S" , "-noinhibit-exec" , "-nostartfiles" , "-nodefaultlibs" , "-nostdinc" , "-M" }
14+
1315func createLdScript (w * Wave ) (string , error ) {
1416 t := `
1517ENTRY(_start)
@@ -115,30 +117,26 @@ func generateLdScript(w *Wave) (string, error) {
115117 return path , nil
116118}
117119
118- func LinkSpec (w * Wave , ld_command string ) (string , error ) {
120+ func LinkSpec (w * Wave , ldRunner Runner ) (string , error ) {
119121 name := w .Name
120122 log .Infof ("Linking spec \" %s\" ." , name )
121123 ld_path , err := generateLdScript (w )
122124 if err != nil {
123125 return "" , err
124126 }
125127 output_path := fmt .Sprintf ("%s.out" , name )
126- err = RunCmd ( ld_command , "-G 0" , "-S" , "-noinhibit-exec" , "-nostartfiles" , "-nodefaultlibs" , "-nostdinc" , "- dT" , ld_path , "-o" , output_path , "-M" )
128+ _ , err = ldRunner . Run ( /* stdin=*/ nil , append ( ldArgs , "-dT" , ld_path , "-o" , output_path ) )
127129 if err != nil {
128130 return "" , err
129131 }
130132 return output_path , err
131133}
132134
133- func BinarizeObject (obj_path string , objcopy_command string ) (* os.File , error ) {
134- output_bin := fmt .Sprintf ("%s.bin" , obj_path )
135- err := RunCmd (objcopy_command , "-O" , "binary" , obj_path , output_bin )
136- if err != nil {
137- return nil , err
138- }
139- file , err := os .Open (output_bin )
135+ func BinarizeObject (objPath string , objcopyRunner Runner ) (* os.File , error ) {
136+ outputBin := fmt .Sprintf ("%s.bin" , objPath )
137+ _ , err := objcopyRunner .Run ( /* stdin=*/ nil , []string {"-O" , "binary" , objPath , outputBin })
140138 if err != nil {
141139 return nil , err
142140 }
143- return file , err
141+ return os . Open ( outputBin )
144142}
0 commit comments