Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: src/common/mac/arch_utilities.cc

Issue 1340543002: Fix Mac Breakpad host tools to build in Linux cross-compile (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/common/mac/byteswap.h » ('j') | src/common/mac/byteswap.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, Google Inc. 1 // Copyright (c) 2012, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #include "common/mac/arch_utilities.h" 30 #include "common/mac/arch_utilities.h"
31 31
32 #include <mach-o/arch.h> 32 #include <mach-o/arch.h>
33 #include <mach-o/fat.h>
33 #include <stdio.h> 34 #include <stdio.h>
34 #include <string.h> 35 #include <string.h>
35 36
36 #ifndef CPU_TYPE_ARM 37 #ifndef CPU_TYPE_ARM
Mark Mentovai 2015/09/11 15:49:50 I don’t think we need backup definitions of CPU_TY
Ted Mielczarek 2015/09/15 12:58:36 Done.
37 #define CPU_TYPE_ARM (static_cast<cpu_type_t>(12)) 38 #define CPU_TYPE_ARM (static_cast<cpu_type_t>(12))
38 #endif // CPU_TYPE_ARM 39 #endif // CPU_TYPE_ARM
39 40
40 #ifndef CPU_SUBTYPE_ARM_V7 41 #ifndef CPU_SUBTYPE_ARM_V7
41 #define CPU_SUBTYPE_ARM_V7 (static_cast<cpu_subtype_t>(9)) 42 #define CPU_SUBTYPE_ARM_V7 (static_cast<cpu_subtype_t>(9))
42 #endif // CPU_SUBTYPE_ARM_V7 43 #endif // CPU_SUBTYPE_ARM_V7
43 44
44 #ifndef CPU_SUBTYPE_ARM_V7S 45 #ifndef CPU_SUBTYPE_ARM_V7S
45 #define CPU_SUBTYPE_ARM_V7S (static_cast<cpu_subtype_t>(11)) 46 #define CPU_SUBTYPE_ARM_V7S (static_cast<cpu_subtype_t>(11))
46 #endif // CPU_SUBTYPE_ARM_V7S 47 #endif // CPU_SUBTYPE_ARM_V7S
47 48
48 #ifndef CPU_TYPE_ARM64 49 #ifndef CPU_TYPE_ARM64
49 #define CPU_TYPE_ARM64 (static_cast<cpu_type_t>(16777228)) 50 #define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
50 #endif // CPU_TYPE_ARM64 51 #endif // CPU_TYPE_ARM64
51 52
52 #ifndef CPU_SUBTYPE_ARM64_ALL 53 #ifndef CPU_SUBTYPE_ARM64_ALL
53 #define CPU_SUBTYPE_ARM64_ALL (static_cast<cpu_type_t>(0)) 54 #define CPU_SUBTYPE_ARM64_ALL (static_cast<cpu_subtype_t>(0))
54 #endif // CPU_SUBTYPE_ARM64_ALL 55 #endif // CPU_SUBTYPE_ARM64_ALL
55 56
56 namespace { 57 namespace {
57 58
58 const NXArchInfo* ArchInfo_arm64() { 59 const NXArchInfo* ArchInfo_arm64() {
59 NXArchInfo* arm64 = new NXArchInfo; 60 NXArchInfo* arm64 = new NXArchInfo;
60 *arm64 = *NXGetArchInfoFromCpuType(CPU_TYPE_ARM, 61 *arm64 = *NXGetArchInfoFromCpuType(CPU_TYPE_ARM,
61 CPU_SUBTYPE_ARM_V7); 62 CPU_SUBTYPE_ARM_V7);
62 arm64->name = "arm64"; 63 arm64->name = "arm64";
63 arm64->cputype = CPU_TYPE_ARM64; 64 arm64->cputype = CPU_TYPE_ARM64;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // TODO: Remove this when the OS knows about armv7s. 105 // TODO: Remove this when the OS knows about armv7s.
105 if (cpu_type == CPU_TYPE_ARM && cpu_subtype == CPU_SUBTYPE_ARM_V7S) { 106 if (cpu_type == CPU_TYPE_ARM && cpu_subtype == CPU_SUBTYPE_ARM_V7S) {
106 static const NXArchInfo* armv7s = ArchInfo_armv7s(); 107 static const NXArchInfo* armv7s = ArchInfo_armv7s();
107 return armv7s; 108 return armv7s;
108 } 109 }
109 110
110 return NXGetArchInfoFromCpuType(cpu_type, cpu_subtype); 111 return NXGetArchInfoFromCpuType(cpu_type, cpu_subtype);
111 } 112 }
112 113
113 } // namespace google_breakpad 114 } // namespace google_breakpad
115
116 #ifndef __APPLE__
Mark Mentovai 2015/09/11 15:49:50 Did this code come from anywhere else or did you w
Ted Mielczarek 2015/09/11 15:58:00 I wrote it myself after I noticed the existing pol
Ted Mielczarek 2015/09/15 12:58:36 Acknowledged.
117 namespace {
118
119 enum Architecture {
120 kArch_i386 = 0,
121 kArch_x86_64,
122 kArch_arm,
123 kArch_arm64,
124 kArch_ppc,
125 // This must be last.
126 kNumArchitectures
127 };
128
129 const NXArchInfo kKnownArchitectures[] = {
Mark Mentovai 2015/09/11 15:49:50 Comment that Architecture and kKnownArchitectures[
Ted Mielczarek 2015/09/15 12:58:36 Done.
130 {
131 "i386",
132 CPU_TYPE_I386,
133 CPU_SUBTYPE_I386_ALL,
134 NX_LittleEndian,
135 "Intel 80x86"
136 },
137 {
138 "x86_64",
139 CPU_TYPE_X86_64,
140 CPU_SUBTYPE_X86_64_ALL,
141 NX_LittleEndian,
142 "Intel x86-64"
143 },
144 {
145 "arm",
146 CPU_TYPE_ARM,
147 CPU_SUBTYPE_ARM_ALL,
148 NX_LittleEndian,
149 "ARM"
150 },
151 {
152 "arm64",
153 CPU_TYPE_ARM64,
154 CPU_SUBTYPE_ARM64_ALL,
155 NX_LittleEndian,
156 "ARM64"
157 },
158 {
159 "ppc",
160 CPU_TYPE_POWERPC,
161 CPU_SUBTYPE_POWERPC_ALL,
162 NX_BigEndian,
163 "PowerPC"
164 }
165 };
166
167 } // namespace
168
169 const NXArchInfo *NXGetLocalArchInfo(void) {
170 Architecture arch;
171 #if defined(__i386__)
172 arch = kArch_i386;
173 #elif defined(__x86_64__)
174 arch = kArch_x86_64;
175 #elif defined(__arm64)
176 arch = kArch_arm64;
177 #elif defined(__arm__)
178 arch = kArch_arm;
179 #elif defined(__powerpc__)
180 arch = kArch_ppc;
181 #else
182 #error "Unsupported CPU architecture"
183 #endif
184 return &kKnownArchitectures[arch];
185 }
186
187 const NXArchInfo *NXGetArchInfoFromName(const char *name) {
188 for (int arch = 0; arch < kNumArchitectures; ++arch) {
189 if (strcmp(name, kKnownArchitectures[arch].name)) {
190 return &kKnownArchitectures[arch];
191 }
192 }
193 return nullptr;
194 }
195
196 const NXArchInfo *NXGetArchInfoFromCpuType(cpu_type_t cputype,
197 cpu_subtype_t cpusubtype) {
198 for (int arch = 0; arch < kNumArchitectures; ++arch) {
199 if (kKnownArchitectures[arch].cputype == cputype) {
200 return &kKnownArchitectures[arch];
201 }
202 }
203 return nullptr;
204 }
205
206 struct fat_arch *NXFindBestFatArch(cpu_type_t cputype,
207 cpu_subtype_t cpusubtype,
208 struct fat_arch *fat_archs,
209 uint32_t nfat_archs) {
210 for (uint32_t f = 0; f < nfat_archs; ++f) {
211 if (fat_archs[f].cputype == cputype) {
212 return &fat_archs[f];
213 }
214 }
215 return nullptr;
216 }
217 #endif // !__APPLE__
OLDNEW
« no previous file with comments | « no previous file | src/common/mac/byteswap.h » ('j') | src/common/mac/byteswap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698