21 #if defined(__APPLE__)
22 # include <sys/stat.h>
29 std::string objcopy_cmd = compiler_or_linker;
30 objcopy_cmd.erase(objcopy_cmd.size() - 2);
31 objcopy_cmd +=
"objcopy";
40 const std::string &compiler_or_linker,
41 const std::string &goto_binary_file,
42 const std::string &output_file,
43 bool building_executable,
51 #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
53 (void)building_executable;
59 message.
debug() <<
"merging " << output_file <<
" and " << goto_binary_file
60 <<
" using " << objcopy_cmd
66 std::vector<std::string> objcopy_argv = {
68 "--remove-section",
"goto-cc",
69 "--add-section",
"goto-cc=" + goto_binary_file, output_file};
71 const int add_section_result =
run(objcopy_argv[0], objcopy_argv);
72 if(add_section_result != 0)
75 message.
warning() <<
"cannot merge EFI binaries: goto-cc section lost"
78 result = add_section_result;
86 message.
error() <<
"Remove failed: " << std::strerror(errno)
89 result = remove_result;
92 #elif defined(__APPLE__)
95 message.
debug() <<
"merging " << output_file <<
" and " << goto_binary_file
96 <<
" using " << (building_executable ?
"lipo" :
"ld")
99 if(building_executable)
103 std::vector<std::string> lipo_argv = {
104 "lipo", output_file,
"-create",
"-arch",
"hppa7100LC", goto_binary_file,
105 "-output", output_file };
107 result =
run(lipo_argv[0], lipo_argv);
114 mode_t current_umask = umask(0);
115 umask(current_umask);
116 int chmod_result = chmod(
117 output_file.c_str(), (S_IRWXU | S_IRWXG | S_IRWXO) & ~current_umask);
118 if(chmod_result != 0)
120 message.
error() <<
"Setting execute permissions failed: "
122 result = chmod_result;
129 std::vector<std::string> ld_argv = {
"ld",
139 result =
run(ld_argv[0], ld_argv);
143 bool remove_result =
file_remove(goto_binary_file);
146 message.
error() <<
"Remove failed: " << std::strerror(errno)
149 result = remove_result;
154 (void)compiler_or_linker;
155 (void)goto_binary_file;
157 (void)building_executable;
158 message.
error() <<
"binary merging not implemented for this platform"