19 #if defined(__APPLE__)
20 # include <sys/stat.h>
24 const std::string &compiler_or_linker,
25 const std::string &goto_binary_file,
26 const std::string &output_file,
27 bool building_executable,
34 #if defined(__linux__) || defined(__FreeBSD_kernel__)
36 (void)building_executable;
38 std::string objcopy_cmd;
42 objcopy_cmd = compiler_or_linker;
43 objcopy_cmd.erase(objcopy_cmd.size() - 2);
44 objcopy_cmd +=
"objcopy";
47 objcopy_cmd =
"objcopy";
51 message.debug() <<
"merging " << output_file <<
" and " << goto_binary_file
52 <<
" using " << objcopy_cmd
58 std::vector<std::string> objcopy_argv = {
60 "--remove-section",
"goto-cc",
61 "--add-section",
"goto-cc=" + goto_binary_file, output_file};
63 result =
run(objcopy_argv[0], objcopy_argv);
67 int remove_result = remove(goto_binary_file.c_str());
68 if(remove_result != 0)
70 message.error() <<
"Remove failed: " << std::strerror(errno)
73 result = remove_result;
76 #elif defined(__APPLE__)
79 message.debug() <<
"merging " << output_file <<
" and " << goto_binary_file
80 <<
" using " << (building_executable ?
"lipo" :
"ld")
83 if(building_executable)
87 std::vector<std::string> lipo_argv = {
88 "lipo", output_file,
"-create",
"-arch",
"hppa7100LC", goto_binary_file,
89 "-output", output_file };
91 result =
run(lipo_argv[0], lipo_argv);
98 mode_t current_umask = umask(0);
100 int chmod_result = chmod(
101 output_file.c_str(), (S_IRWXU | S_IRWXG | S_IRWXO) & ~current_umask);
102 if(chmod_result != 0)
104 message.error() <<
"Setting execute permissions failed: "
106 result = chmod_result;
113 std::vector<std::string> ld_argv = {
"ld",
123 result =
run(ld_argv[0], ld_argv);
127 int remove_result = remove(goto_binary_file.c_str());
128 if(remove_result != 0)
130 message.error() <<
"Remove failed: " << std::strerror(errno)
133 result = remove_result;
138 (void)compiler_or_linker;
139 (void)goto_binary_file;
141 (void)building_executable;
142 message.error() <<
"binary merging not implemented for this platform"