@@ -191,28 +191,25 @@ def simplify(logger, args, asm_input, asm_output=None):
191191 # Create temporary object files for byte code before/after simplification
192192 with tempfile .NamedTemporaryFile (
193193 suffix = ".o" , delete = False
194- ) as tmp0 , tempfile .NamedTemporaryFile (suffix = ".o" , delete = False ) as tmp1 :
194+ ) as tmp0 , tempfile .NamedTemporaryFile (suffix = ".o" , delete = False ) as tmp1 , tempfile . NamedTemporaryFile ( suffix = ".o" , delete = False ) as tmp0_pre :
195195
196196 tmp_objfile0 = tmp0 .name
197+ tmp_objfile0_pre = tmp0_pre .name
197198 tmp_objfile1 = tmp1 .name
198199
199200 cmd = (
200201 [args .cc , "-c" , "-x" , "assembler-with-cpp" ]
201202 + cflags
202- + ["-o" , tmp_objfile0 , "-" ]
203+ + ["-o" , tmp_objfile0_pre , "-" ]
203204 )
204205 logger .debug (f"Assembling { asm_input } ..." )
205206 asm_no_if = "\n " .join (drop_if_from_header (header ) + body + footer )
206207 run_cmd (cmd , input = asm_no_if )
207208
208- # Remember the binary contents of the object file for later
209- tmp0 .seek (0 )
210- orig_obj = tmp0 .read ()
211-
212209 # Check that there is exactly one global symbol at location 0
213- cmd = [args .nm , "--extern-only" , tmp_objfile0 ]
210+ cmd = [args .nm , "--extern-only" , tmp_objfile0_pre ]
214211 logger .debug (
215- f"Extracting symbols from temporary object file { tmp_objfile0 } ..."
212+ f"Extracting symbols from temporary object file { tmp_objfile0_pre } ..."
216213 )
217214 r = run_cmd (cmd )
218215
@@ -245,6 +242,14 @@ def simplify(logger, args, asm_input, asm_output=None):
245242 sym = sym_info [2 ]
246243 logger .debug (f"Using raw global symbol { sym } going forward ..." )
247244
245+ # Link to get rid of potential relocation symbols in the assembly
246+ cmd = [args .cc , "-nostartfiles" , "-e" , sym_info [2 ], '-o' , tmp_objfile0_pre , tmp_objfile0 ]
247+ r = run_cmd (cmd )
248+
249+ # Remember the binary contents of the object file for later
250+ tmp0 .seek (0 )
251+ orig_obj = tmp0 .read ()
252+
248253 cmd = [args .objdump , "--disassemble" , tmp_objfile0 ]
249254 if platform .system () == "Darwin" and args .arch == "aarch64" :
250255 cmd += ["--triple=aarch64" ]
@@ -319,7 +324,7 @@ def simplify(logger, args, asm_input, asm_output=None):
319324 f .write ("\n " .join (full_simplified ))
320325
321326 cmd = (
322- [args .cc , "-c" , "-x" , "assembler-with-cpp" ]
327+ [args .cc , "-nostartfiles" , "-e" , sym_info [ 2 ] , "-x" , "assembler-with-cpp" ]
323328 + cflags
324329 + ["-o" , tmp_objfile1 , "-" ]
325330 )
0 commit comments