Skip to content

Commit 306fbf7

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Use hybrid_binary(...) to avoid code duplication
The implementation in as_mode.cpp was effectively doing the same, just using different variable names.
1 parent 3957f80 commit 306fbf7

File tree

1 file changed

+6
-71
lines changed

1 file changed

+6
-71
lines changed

src/goto-cc/as_mode.cpp

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Author: Michael Tautschnig
3030
#include <util/version.h>
3131

3232
#include "compile.h"
33+
#include "hybrid_binary.h"
3334

3435
static std::string assembler_name(
3536
const cmdlinet &cmdline,
@@ -287,9 +288,8 @@ int as_modet::as_hybrid_binary()
287288
<< " to generate hybrid binary" << eom;
288289

289290
// save the goto-cc output file
290-
int result=rename(
291-
output_file.c_str(),
292-
(output_file+".goto-cc-saved").c_str());
291+
std::string saved = output_file + ".goto-cc-saved";
292+
int result = rename(output_file.c_str(), saved.c_str());
293293
if(result!=0)
294294
{
295295
error() << "Rename failed: " << std::strerror(errno) << eom;
@@ -298,77 +298,12 @@ int as_modet::as_hybrid_binary()
298298

299299
result=run_as();
300300

301-
// merge output from as with goto-binaries
302-
// using objcopy, or do cleanup if an earlier call failed
303-
debug() << "merging " << output_file << eom;
304-
std::string saved=output_file+".goto-cc-saved";
305-
306-
#if defined(__linux__) || defined(__FreeBSD_kernel__)
307-
if(result==0)
308-
{
309-
// remove any existing goto-cc section
310-
std::vector<std::string> objcopy_argv;
311-
312-
objcopy_argv.push_back("objcopy");
313-
objcopy_argv.push_back("--remove-section=goto-cc");
314-
objcopy_argv.push_back(output_file);
315-
316-
result = run(objcopy_argv[0], objcopy_argv);
317-
}
318-
319-
if(result==0)
301+
if(result == 0)
320302
{
321-
// now add goto-binary as goto-cc section
322-
std::vector<std::string> objcopy_argv;
323-
324-
objcopy_argv.push_back("objcopy");
325-
objcopy_argv.push_back("--add-section");
326-
objcopy_argv.push_back("goto-cc="+saved);
327-
objcopy_argv.push_back(output_file);
328-
329-
result = run(objcopy_argv[0], objcopy_argv);
303+
result = hybrid_binary(
304+
native_tool_name, saved, output_file, get_message_handler());
330305
}
331306

332-
int remove_result=remove(saved.c_str());
333-
if(remove_result!=0)
334-
{
335-
error() << "Remove failed: " << std::strerror(errno) << eom;
336-
if(result==0)
337-
result=remove_result;
338-
}
339-
340-
#elif defined(__APPLE__)
341-
// Mac
342-
if(result==0)
343-
{
344-
std::vector<std::string> lipo_argv;
345-
346-
// now add goto-binary as hppa7100LC section
347-
lipo_argv.push_back("lipo");
348-
lipo_argv.push_back(output_file);
349-
lipo_argv.push_back("-create");
350-
lipo_argv.push_back("-arch");
351-
lipo_argv.push_back("hppa7100LC");
352-
lipo_argv.push_back(saved);
353-
lipo_argv.push_back("-output");
354-
lipo_argv.push_back(output_file);
355-
356-
result = run(lipo_argv[0], lipo_argv);
357-
}
358-
359-
int remove_result=remove(saved.c_str());
360-
if(remove_result!=0)
361-
{
362-
error() << "Remove failed: " << std::strerror(errno) << eom;
363-
if(result==0)
364-
result=remove_result;
365-
}
366-
367-
#else
368-
error() << "binary merging not implemented for this platform" << eom;
369-
result = 1;
370-
#endif
371-
372307
return result;
373308
}
374309

0 commit comments

Comments
 (0)