|
38 | 38 |
|
39 | 39 | #include <asl.h> |
40 | 40 | #include <crt_externs.h> |
| 41 | +#include <dlfcn.h> |
41 | 42 | #include <grp.h> |
42 | 43 | #include <libproc.h> |
43 | 44 | #include <pwd.h> |
@@ -1108,6 +1109,55 @@ static Status LaunchProcessPosixSpawn(const char *exe_path, |
1108 | 1109 | } |
1109 | 1110 | } |
1110 | 1111 |
|
| 1112 | + // Don't set the binpref if a shell was provided. After all, that's only |
| 1113 | + // going to affect what version of the shell is launched, not what fork of |
| 1114 | + // the binary is launched. We insert "arch --arch <ARCH> as part of the |
| 1115 | + // shell invocation to do that job on OSX. |
| 1116 | + if (launch_info.GetShell() == FileSpec()) { |
| 1117 | + const ArchSpec &arch_spec = launch_info.GetArchitecture(); |
| 1118 | + cpu_type_t cpu_type = arch_spec.GetMachOCPUType(); |
| 1119 | + cpu_type_t cpu_subtype = arch_spec.GetMachOCPUSubType(); |
| 1120 | + const bool set_cpu_type = |
| 1121 | + cpu_type != 0 && cpu_type != static_cast<cpu_type_t>(UINT32_MAX) && |
| 1122 | + cpu_type != static_cast<cpu_type_t>(LLDB_INVALID_CPUTYPE); |
| 1123 | + const bool set_cpu_subtype = |
| 1124 | + cpu_subtype != 0 && |
| 1125 | + cpu_subtype != static_cast<cpu_subtype_t>(UINT32_MAX) && |
| 1126 | + cpu_subtype != CPU_SUBTYPE_X86_64_H; |
| 1127 | + if (set_cpu_type) { |
| 1128 | + size_t ocount = 0; |
| 1129 | + typedef int (*posix_spawnattr_setarchpref_np_t)( |
| 1130 | + posix_spawnattr_t *, size_t, cpu_type_t *, cpu_subtype_t *, size_t *); |
| 1131 | + posix_spawnattr_setarchpref_np_t posix_spawnattr_setarchpref_np_fn = |
| 1132 | + (posix_spawnattr_setarchpref_np_t)dlsym( |
| 1133 | + RTLD_DEFAULT, "posix_spawnattr_setarchpref_np"); |
| 1134 | + if (set_cpu_subtype && posix_spawnattr_setarchpref_np_fn) { |
| 1135 | + error.SetError((*posix_spawnattr_setarchpref_np_fn)( |
| 1136 | + &attr, 1, &cpu_type, &cpu_subtype, &ocount), |
| 1137 | + eErrorTypePOSIX); |
| 1138 | + if (error.Fail()) |
| 1139 | + LLDB_LOG(log, |
| 1140 | + "error: {0}, ::posix_spawnattr_setarchpref_np ( &attr, 1, " |
| 1141 | + "cpu_type = {1:x}, cpu_subtype = {1:x}, count => {2} )", |
| 1142 | + error, cpu_type, cpu_subtype, ocount); |
| 1143 | + |
| 1144 | + if (error.Fail() || ocount != 1) |
| 1145 | + return error; |
| 1146 | + } else { |
| 1147 | + error.SetError( |
| 1148 | + ::posix_spawnattr_setbinpref_np(&attr, 1, &cpu_type, &ocount), |
| 1149 | + eErrorTypePOSIX); |
| 1150 | + if (error.Fail()) |
| 1151 | + LLDB_LOG(log, |
| 1152 | + "error: {0}, ::posix_spawnattr_setbinpref_np ( &attr, 1, " |
| 1153 | + "cpu_type = {1:x}, count => {2} )", |
| 1154 | + error, cpu_type, ocount); |
| 1155 | + if (error.Fail() || ocount != 1) |
| 1156 | + return error; |
| 1157 | + } |
| 1158 | + } |
| 1159 | + } |
| 1160 | + |
1111 | 1161 | const char *tmp_argv[2]; |
1112 | 1162 | char *const *argv = const_cast<char *const *>( |
1113 | 1163 | launch_info.GetArguments().GetConstArgumentVector()); |
|
0 commit comments