@@ -20,13 +20,17 @@ int hybrid_binary(
2020 const std::string &compiler_or_linker,
2121 const std::string &goto_binary_file,
2222 const std::string &output_file,
23+ bool building_executable,
2324 message_handlert &message_handler)
2425{
2526 messaget message (message_handler);
2627
2728 int result;
2829
2930#if defined(__linux__) || defined(__FreeBSD_kernel__)
31+ // we can use objcopy for both object files and executables
32+ (void )building_executable;
33+
3034 std::string objcopy_cmd;
3135
3236 if (has_suffix (compiler_or_linker, " -ld" ))
@@ -69,9 +73,10 @@ int hybrid_binary(
6973 // Mac
7074
7175 message.debug () << " merging " << output_file << " and " << goto_binary_file
72- << " using lipo"
76+ << " using " << (building_executable ? " lipo" : " ld " )
7377 << messaget::eom;
7478
79+ if (building_executable)
7580 {
7681 // Add goto-binary as hppa7100LC section.
7782 // This overwrites if there's already one.
@@ -81,6 +86,21 @@ int hybrid_binary(
8186
8287 result = run (lipo_argv[0 ], lipo_argv);
8388 }
89+ else
90+ {
91+ // This fails if there's already one.
92+ std::vector<std::string> ld_argv = {" ld" ,
93+ " -r" ,
94+ " -sectcreate" ,
95+ " __TEXT" ,
96+ " goto-cc" ,
97+ goto_binary_file,
98+ output_file,
99+ " -o" ,
100+ output_file};
101+
102+ result = run (ld_argv[0 ], ld_argv);
103+ }
84104
85105 // delete the goto binary
86106 int remove_result = remove (goto_binary_file.c_str ());
@@ -97,6 +117,7 @@ int hybrid_binary(
97117 (void )compiler_or_linker;
98118 (void )goto_binary_file;
99119 (void )output_file;
120+ (void )building_executable;
100121 message.error () << " binary merging not implemented for this platform"
101122 << messaget::eom;
102123 result = 1 ;
0 commit comments