@@ -48,6 +48,7 @@ Author: CM Wintersteiger, 2006
48
48
49
49
#include < cbmc/version.h>
50
50
51
+ #include " hybrid_binary.h"
51
52
#include " linker_script_merge.h"
52
53
53
54
static std::string compiler_name (
@@ -106,8 +107,6 @@ gcc_modet::gcc_modet(
106
107
bool _produce_hybrid_binary):
107
108
goto_cc_modet(_cmdline, _base_name, gcc_message_handler),
108
109
produce_hybrid_binary(_produce_hybrid_binary),
109
- act_as_ld(base_name==" ld" ||
110
- base_name.find(" goto-ld" )!=std::string::npos),
111
110
goto_binary_tmp_suffix(" .goto-cc-saved" ),
112
111
113
112
// Keys are architectures specified in configt::set_arch().
@@ -326,8 +325,6 @@ int gcc_modet::doit()
326
325
}
327
326
328
327
native_tool_name=
329
- act_as_ld ?
330
- linker_name (cmdline, base_name) :
331
328
compiler_name (cmdline, base_name);
332
329
333
330
auto default_verbosity = (cmdline.isset (" Wall" ) || cmdline.isset (" Wextra" )) ?
@@ -345,10 +342,7 @@ int gcc_modet::doit()
345
342
// "-v" a) prints the version and b) increases verbosity.
346
343
// Compilation continues, don't exit!
347
344
348
- if (act_as_ld)
349
- std::cout << " GNU ld version 2.16.91 20050610 (goto-cc " CBMC_VERSION
350
- << " )\n " ;
351
- else if (act_as_bcc)
345
+ if (act_as_bcc)
352
346
std::cout << " bcc: version 0.16.17 (goto-cc " CBMC_VERSION " )\n " ;
353
347
else
354
348
std::cout << " gcc version 3.4.4 (goto-cc " CBMC_VERSION " )\n " ;
@@ -395,14 +389,7 @@ int gcc_modet::doit()
395
389
return EX_OK;
396
390
}
397
391
398
- if (act_as_ld)
399
- {
400
- if (produce_hybrid_binary)
401
- debug () << " LD mode (hybrid)" << eom;
402
- else
403
- debug () << " LD mode" << eom;
404
- }
405
- else if (act_as_bcc)
392
+ if (act_as_bcc)
406
393
{
407
394
if (produce_hybrid_binary)
408
395
debug () << " BCC mode (hybrid)" << eom;
@@ -418,9 +405,7 @@ int gcc_modet::doit()
418
405
}
419
406
420
407
// determine actions to be undertaken
421
- if (act_as_ld)
422
- compiler.mode =compilet::LINK_LIBRARY;
423
- else if (cmdline.isset (' S' ))
408
+ if (cmdline.isset (' S' ))
424
409
compiler.mode =compilet::ASSEMBLE_ONLY;
425
410
else if (cmdline.isset (' c' ))
426
411
compiler.mode =compilet::COMPILE_ONLY;
@@ -437,13 +422,10 @@ int gcc_modet::doit()
437
422
// * preprocessing (-E)
438
423
// * no input files given
439
424
440
- if (act_as_ld)
441
- {
442
- }
443
- else if (cmdline.isset (' M' ) ||
444
- cmdline.isset (" MM" ) ||
445
- cmdline.isset (' E' ) ||
446
- !cmdline.have_infile_arg ())
425
+ if (cmdline.isset (' M' ) ||
426
+ cmdline.isset (" MM" ) ||
427
+ cmdline.isset (' E' ) ||
428
+ !cmdline.have_infile_arg ())
447
429
return run_gcc (compiler); // exit!
448
430
449
431
// get configuration
@@ -819,7 +801,7 @@ int gcc_modet::run_gcc(const compilet &compiler)
819
801
for (const auto &a : cmdline.parsed_argv )
820
802
new_argv.push_back (a.arg );
821
803
822
- if (!act_as_ld && compiler.wrote_object_files ())
804
+ if (compiler.wrote_object_files ())
823
805
{
824
806
// Undefine all __CPROVER macros for the system compiler
825
807
std::map<irep_idt, std::size_t > arities;
@@ -922,103 +904,38 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
922
904
goto_binaries.push_back (bin_name);
923
905
}
924
906
925
- std::string objcopy_cmd;
926
- if (has_suffix (linker_name (cmdline, base_name), " -ld" ))
927
- {
928
- objcopy_cmd=linker_name (cmdline, base_name);
929
- objcopy_cmd.erase (objcopy_cmd.size ()-2 );
930
- }
931
- else if (has_suffix (compiler_name (cmdline, base_name), " -gcc" ))
932
- {
933
- objcopy_cmd=compiler_name (cmdline, base_name);
934
- objcopy_cmd.erase (objcopy_cmd.size ()-3 );
935
- }
936
- objcopy_cmd+=" objcopy" ;
937
-
938
907
int result=run_gcc (compiler);
939
908
940
- if (result==0 )
909
+ if (result==0 &&
910
+ cmdline.isset (' T' ) &&
911
+ goto_binaries.size ()==1 &&
912
+ output_files.size ()==1 )
941
913
{
942
914
linker_script_merget ls_merge (
943
- compiler, output_files, goto_binaries, cmdline, gcc_message_handler);
915
+ compiler, output_files.front (), goto_binaries.front (),
916
+ cmdline, gcc_message_handler);
944
917
result=ls_merge.add_linker_script_definitions ();
945
918
}
946
919
920
+ std::string native_tool;
921
+
922
+ if (has_suffix (linker_name (cmdline, base_name), " -ld" ))
923
+ native_tool=linker_name (cmdline, base_name);
924
+ else if (has_suffix (compiler_name (cmdline, base_name), " -gcc" ))
925
+ native_tool=compiler_name (cmdline, base_name);
926
+
947
927
// merge output from gcc with goto-binaries
948
928
// using objcopy, or do cleanup if an earlier call failed
949
929
for (std::list<std::string>::const_iterator
950
930
it=output_files.begin ();
951
931
it!=output_files.end ();
952
932
it++)
953
933
{
954
- debug () << " merging " << *it << eom;
955
- std::string saved=*it+goto_binary_tmp_suffix;
956
-
957
- #ifdef __linux__
958
- if (result==0 && !cmdline.isset (' c' ))
959
- {
960
- // remove any existing goto-cc section
961
- std::vector<std::string> objcopy_argv;
962
-
963
- objcopy_argv.push_back (objcopy_cmd);
964
- objcopy_argv.push_back (" --remove-section=goto-cc" );
965
- objcopy_argv.push_back (*it);
934
+ std::string goto_binary=*it+goto_binary_tmp_suffix;
966
935
967
- result=run (objcopy_argv[0 ], objcopy_argv, " " , " " );
968
- }
969
-
970
- if (result==0 )
971
- {
972
- // now add goto-binary as goto-cc section
973
- std::vector<std::string> objcopy_argv;
974
-
975
- objcopy_argv.push_back (objcopy_cmd);
976
- objcopy_argv.push_back (" --add-section" );
977
- objcopy_argv.push_back (" goto-cc=" +saved);
978
- objcopy_argv.push_back (*it);
979
-
980
- result=run (objcopy_argv[0 ], objcopy_argv, " " , " " );
981
- }
982
-
983
- int remove_result=remove (saved.c_str ());
984
- if (remove_result!=0 )
985
- {
986
- error () << " Remove failed: " << std::strerror (errno) << eom;
987
- if (result==0 )
988
- result=remove_result;
989
- }
990
-
991
- #elif defined(__APPLE__)
992
- // Mac
993
936
if (result==0 )
994
- {
995
- std::vector<std::string> lipo_argv;
996
-
997
- // now add goto-binary as hppa7100LC section
998
- lipo_argv.push_back (" lipo" );
999
- lipo_argv.push_back (*it);
1000
- lipo_argv.push_back (" -create" );
1001
- lipo_argv.push_back (" -arch" );
1002
- lipo_argv.push_back (" hppa7100LC" );
1003
- lipo_argv.push_back (saved);
1004
- lipo_argv.push_back (" -output" );
1005
- lipo_argv.push_back (*it);
1006
-
1007
- result=run (lipo_argv[0 ], lipo_argv, " " , " " );
1008
- }
1009
-
1010
- int remove_result=remove (saved.c_str ());
1011
- if (remove_result!=0 )
1012
- {
1013
- error () << " Remove failed: " << std::strerror (errno) << eom;
1014
- if (result==0 )
1015
- result=remove_result;
1016
- }
1017
-
1018
- #else
1019
- error () << " binary merging not implemented for this platform" << eom;
1020
- return 1 ;
1021
- #endif
937
+ result = hybrid_binary (
938
+ native_tool, goto_binary, *it, get_message_handler ());
1022
939
}
1023
940
1024
941
return result;
@@ -1112,10 +1029,6 @@ int gcc_modet::asm_output(
1112
1029
// / display command line help
1113
1030
void gcc_modet::help_mode ()
1114
1031
{
1115
- if (act_as_ld)
1116
- std::cout << " goto-ld understands the options of "
1117
- << " ld plus the following.\n\n " ;
1118
- else
1119
- std::cout << " goto-cc understands the options of "
1120
- << " gcc plus the following.\n\n " ;
1032
+ std::cout << " goto-cc understands the options of "
1033
+ << " gcc plus the following.\n\n " ;
1121
1034
}
0 commit comments