Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 1 | import sys # FIXME: Shouldn't be needed. |
| 2 | |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 3 | import Arguments |
| 4 | import Jobs |
| 5 | import Types |
| 6 | |
| 7 | class Tool(object): |
Daniel Dunbar | ba6e323 | 2009-01-06 06:12:13 +0000 | [diff] [blame] | 8 | """Tool - A concrete implementation of an action.""" |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 9 | |
| 10 | eFlagsPipedInput = 1 << 0 |
| 11 | eFlagsPipedOutput = 1 << 1 |
| 12 | eFlagsIntegratedCPP = 1 << 2 |
| 13 | |
| 14 | def __init__(self, name, flags = 0): |
| 15 | self.name = name |
| 16 | self.flags = flags |
| 17 | |
| 18 | def acceptsPipedInput(self): |
| 19 | return not not (self.flags & Tool.eFlagsPipedInput) |
| 20 | def canPipeOutput(self): |
| 21 | return not not (self.flags & Tool.eFlagsPipedOutput) |
| 22 | def hasIntegratedCPP(self): |
| 23 | return not not (self.flags & Tool.eFlagsIntegratedCPP) |
| 24 | |
| 25 | class GCC_Common_Tool(Tool): |
| 26 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 27 | output, outputType, args, arglist, |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 28 | extraArgs): |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 29 | cmd_args = sum(map(arglist.render, args),[]) + extraArgs |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 30 | if arch: |
Daniel Dunbar | 39cbfaa | 2009-01-07 18:54:26 +0000 | [diff] [blame] | 31 | cmd_args.extend(arglist.render(arch)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 32 | if isinstance(output, Jobs.PipedJob): |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 33 | cmd_args.extend(['-o', '-']) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 34 | elif output is None: |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 35 | cmd_args.append('-fsyntax-only') |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 36 | else: |
Daniel Dunbar | 39cbfaa | 2009-01-07 18:54:26 +0000 | [diff] [blame] | 37 | cmd_args.extend(arglist.render(output)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 39 | # Only pass -x if gcc will understand it; otherwise hope gcc |
| 40 | # understands the suffix correctly. The main use case this |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 41 | # would go wrong in is for linker inputs if they happened to |
| 42 | # have an odd suffix; really the only way to get this to |
| 43 | # happen is a command like '-x foobar a.c' which will treat |
| 44 | # a.c like a linker input. |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 45 | # |
| 46 | # FIXME: For the linker case specifically, can we safely |
| 47 | # convert inputs into '-Wl,' options? |
| 48 | for input in inputs: |
| 49 | if input.type.canBeUserSpecified: |
| 50 | cmd_args.extend(['-x', input.type.name]) |
| 51 | |
| 52 | if isinstance(input.source, Jobs.PipedJob): |
| 53 | cmd_args.append('-') |
| 54 | else: |
Daniel Dunbar | 2ec55bc | 2009-01-12 03:33:58 +0000 | [diff] [blame] | 55 | assert isinstance(input.source, Arguments.Arg) |
| 56 | # If this is a linker input then assume we can forward |
| 57 | # just by rendering. |
| 58 | if input.source.opt.isLinkerInput: |
| 59 | cmd_args.extend(arglist.render(input.source)) |
| 60 | else: |
| 61 | cmd_args.extend(arglist.renderAsInput(input.source)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 62 | |
| 63 | jobs.addJob(Jobs.Command('gcc', cmd_args)) |
| 64 | |
| 65 | class GCC_PreprocessTool(GCC_Common_Tool): |
| 66 | def __init__(self): |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 67 | super(GCC_PreprocessTool, self).__init__('gcc (cpp)', |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 68 | (Tool.eFlagsPipedInput | |
| 69 | Tool.eFlagsPipedOutput)) |
| 70 | |
| 71 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 72 | output, outputType, args, arglist): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 73 | return super(GCC_PreprocessTool, self).constructJob(phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 74 | output, outputType, args, arglist, |
| 75 | ['-E']) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 76 | |
| 77 | class GCC_CompileTool(GCC_Common_Tool): |
| 78 | def __init__(self): |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 79 | super(GCC_CompileTool, self).__init__('gcc (cc1)', |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 80 | (Tool.eFlagsPipedInput | |
| 81 | Tool.eFlagsPipedOutput | |
| 82 | Tool.eFlagsIntegratedCPP)) |
| 83 | |
| 84 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 85 | output, outputType, args, arglist): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 86 | return super(GCC_CompileTool, self).constructJob(phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 87 | output, outputType, args, arglist, |
| 88 | ['-S']) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 89 | |
| 90 | class GCC_PrecompileTool(GCC_Common_Tool): |
| 91 | def __init__(self): |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 92 | super(GCC_PrecompileTool, self).__init__('gcc (pch)', |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 93 | (Tool.eFlagsPipedInput | |
| 94 | Tool.eFlagsIntegratedCPP)) |
| 95 | |
| 96 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 97 | output, outputType, args, arglist): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 98 | return super(GCC_PrecompileTool, self).constructJob(phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 99 | output, outputType, args, arglist, |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 100 | []) |
| 101 | |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 102 | class DarwinAssembleTool(Tool): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 103 | def __init__(self): |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 104 | super(DarwinAssembleTool, self).__init__('as', |
| 105 | Tool.eFlagsPipedInput) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 106 | |
| 107 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 108 | output, outputType, args, arglist): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 109 | assert len(inputs) == 1 |
| 110 | assert outputType is Types.ObjectType |
| 111 | |
| 112 | input = inputs[0] |
| 113 | |
| 114 | cmd_args = [] |
| 115 | if arch: |
Daniel Dunbar | 39cbfaa | 2009-01-07 18:54:26 +0000 | [diff] [blame] | 116 | cmd_args.extend(arglist.render(arch)) |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 117 | cmd_args.append('-force_cpusubtype_ALL') |
Daniel Dunbar | 39cbfaa | 2009-01-07 18:54:26 +0000 | [diff] [blame] | 118 | cmd_args.extend(arglist.render(output)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 119 | if isinstance(input.source, Jobs.PipedJob): |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 120 | cmd_args.append('-') |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 121 | else: |
Daniel Dunbar | 2ec55bc | 2009-01-12 03:33:58 +0000 | [diff] [blame] | 122 | cmd_args.extend(arglist.renderAsInput(input.source)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 123 | jobs.addJob(Jobs.Command('as', cmd_args)) |
| 124 | |
Daniel Dunbar | a9ad2bc | 2009-01-10 02:00:04 +0000 | [diff] [blame] | 125 | class GCC_AssembleTool(GCC_Common_Tool): |
| 126 | def __init__(self): |
| 127 | # We can't generally assume the assembler can take or output |
| 128 | # on pipes. |
| 129 | super(GCC_AssembleTool, self).__init__('gcc (as)') |
| 130 | |
| 131 | def constructJob(self, phase, arch, jobs, inputs, |
| 132 | output, outputType, args, arglist): |
| 133 | return super(GCC_AssembleTool, self).constructJob(phase, arch, jobs, inputs, |
| 134 | output, outputType, args, arglist, |
| 135 | ['-c']) |
| 136 | |
| 137 | class GCC_LinkTool(GCC_Common_Tool): |
| 138 | def __init__(self): |
| 139 | super(GCC_LinkTool, self).__init__('gcc (ld)') |
| 140 | |
| 141 | def constructJob(self, phase, arch, jobs, inputs, |
| 142 | output, outputType, args, arglist): |
| 143 | return super(GCC_LinkTool, self).constructJob(phase, arch, jobs, inputs, |
| 144 | output, outputType, args, arglist, |
| 145 | []) |
| 146 | |
Daniel Dunbar | 9c257c3 | 2009-01-12 04:21:12 +0000 | [diff] [blame^] | 147 | class Darwin_X86_LinkTool(Tool): |
| 148 | def __init__(self, darwinVersion, gccVersion): |
| 149 | super(Darwin_X86_LinkTool, self).__init__('collect2') |
| 150 | assert isinstance(darwinVersion, tuple) and len(darwinVersion) == 3 |
| 151 | assert isinstance(gccVersion, tuple) and len(gccVersion) == 3 |
| 152 | self.darwinVersion = darwinVersion |
| 153 | self.gccVersion = gccVersion |
| 154 | |
| 155 | def getCollect2Path(self): |
| 156 | return '/usr/libexec/gcc/%s/collect2' % self.getToolChainDir() |
| 157 | |
| 158 | def getToolChainDir(self): |
| 159 | return 'i686-apple-darwin%d/%s' % (self.darwinVersion[0], |
| 160 | '.'.join(map(str,self.gccVersion))) |
| 161 | |
| 162 | def getMacosxVersionMin(self): |
| 163 | major,minor,minorminor = self.darwinVersion |
| 164 | return '%d.%d.%d' % (10, major-4, minor) |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 165 | |
| 166 | def addDarwinArch(self, cmd_args, arch, arglist): |
| 167 | # Derived from darwin_arch spec. |
| 168 | cmd_args.append('-arch') |
| 169 | # FIXME: The actual spec uses -m64 for this, but we want to |
| 170 | # respect arch. Figure out what exactly gcc is doing. |
| 171 | #if arglist.getLastArg(arglist.parser.m_64Option): |
| 172 | if arglist.getValue(arch) == 'x86_64': |
| 173 | cmd_args.append('x86_64') |
| 174 | else: |
| 175 | cmd_args.append('i386') |
| 176 | |
| 177 | def addDarwinSubArch(self, cmd_args, arch, arglist): |
| 178 | # Derived from darwin_subarch spec, not sure what the |
| 179 | # distinction exists for but at least for this chain it is the same. |
| 180 | return self.addDarwinArch(cmd_args, arch, arglist) |
| 181 | |
| 182 | def addLinkArgs(self, cmd_args, arch, arglist): |
| 183 | # Derived from link spec. |
| 184 | if arglist.getLastArg(arglist.parser.staticOption): |
| 185 | cmd_args.append('-static') |
| 186 | else: |
| 187 | cmd_args.append('-dynamic') |
| 188 | if arglist.getLastArg(arglist.parser.f_gnuRuntimeOption): |
| 189 | # FIXME: Replace -lobjc in forward args with |
| 190 | # -lobjc-gnu. How do we wish to handle such things? |
| 191 | pass |
| 192 | |
| 193 | if not arglist.getLastArg(arglist.parser.ZdynamiclibOption): |
| 194 | if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption): |
| 195 | self.addDarwinArch(cmd_args, arch, arglist) |
| 196 | cmd_args.append('-force_cpusubtype_all') |
| 197 | else: |
| 198 | self.addDarwinSubArch(cmd_args, arch, arglist) |
| 199 | |
| 200 | if arglist.getLastArg(arglist.parser.ZbundleOption): |
| 201 | cmd_args.append('-bundle') |
| 202 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zbundle_loaderOption, |
| 203 | '-bundle_loader') |
| 204 | arglist.addAllArgs(cmd_args, arglist.parser.client_nameOption) |
| 205 | if arglist.getLastArg(arglist.parser.compatibility_versionOption): |
| 206 | # FIXME: Where should diagnostics go? |
| 207 | print >>sys.stderr, "-compatibility_version only allowed with -dynamiclib" |
| 208 | sys.exit(1) |
| 209 | if arglist.getLastArg(arglist.parser.current_versionOption): |
| 210 | print >>sys.stderr, "-current_version only allowed with -dynamiclib" |
| 211 | sys.exit(1) |
| 212 | if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption): |
| 213 | cmd_args.append('-force_flat_namespace') |
| 214 | if arglist.getLastArg(arglist.parser.Zinstall_nameOption): |
| 215 | print >>sys.stderr, "-install_name only allowed with -dynamiclib" |
| 216 | sys.exit(1) |
| 217 | arglist.addLastArg(cmd_args, arglist.parser.keep_private_externsOption) |
| 218 | arglist.addLastArg(cmd_args, arglist.parser.private_bundleOption) |
| 219 | else: |
| 220 | cmd_args.append('-dylib') |
| 221 | if arglist.getLastArg(arglist.parser.ZbundleOption): |
| 222 | print >>sys.stderr, "-bundle not allowed with -dynamiclib" |
| 223 | sys.exit(1) |
| 224 | if arglist.getLastArg(arglist.parser.Zbundle_loaderOption): |
| 225 | print >>sys.stderr, "-bundle_loader not allowed with -dynamiclib" |
| 226 | sys.exit(1) |
| 227 | if arglist.getLastArg(arglist.parser.client_nameOption): |
| 228 | print >>sys.stderr, "-client_name not allowed with -dynamiclib" |
| 229 | sys.exit(1) |
| 230 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.compatibility_versionOption, |
| 231 | '-dylib_compatibility_version') |
| 232 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.current_versionOption, |
| 233 | '-dylib_current_version') |
| 234 | |
| 235 | if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption): |
| 236 | self.addDarwinArch(cmd_args, arch, arglist) |
| 237 | # NOTE: We don't add -force_cpusubtype_ALL on this path. Ok. |
| 238 | else: |
| 239 | self.addDarwinSubArch(cmd_args, arch, arglist) |
| 240 | |
| 241 | if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption): |
| 242 | print >>sys.stderr, "-force_flat_namespace not allowed with -dynamiclib" |
| 243 | sys.exit(1) |
| 244 | |
| 245 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zinstall_nameOption, |
| 246 | '-dylib_install_name') |
| 247 | |
| 248 | if arglist.getLastArg(arglist.parser.keep_private_externsOption): |
| 249 | print >>sys.stderr, "-keep_private_externs not allowed with -dynamiclib" |
| 250 | sys.exit(1) |
| 251 | if arglist.getLastArg(arglist.parser.private_bundleOption): |
| 252 | print >>sys.stderr, "-private_bundle not allowed with -dynamiclib" |
| 253 | sys.exit(1) |
| 254 | |
| 255 | if arglist.getLastArg(arglist.parser.Zall_loadOption): |
| 256 | cmd_args.append('-all_load') |
| 257 | |
| 258 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zallowable_clientOption, |
| 259 | '-allowable_client') |
| 260 | |
| 261 | if arglist.getLastArg(arglist.parser.Zbind_at_loadOption): |
| 262 | cmd_args.append('-bind_at_load') |
| 263 | |
| 264 | if arglist.getLastArg(arglist.parser.Zdead_stripOption): |
| 265 | cmd_args.append('-dead_strip') |
| 266 | |
| 267 | if arglist.getLastArg(arglist.parser.Zno_dead_strip_inits_and_termsOption): |
| 268 | cmd_args.append('-no_dead_strip_inits_and_terms') |
| 269 | |
| 270 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zdylib_fileOption, |
| 271 | '-dylib_file') |
| 272 | |
| 273 | if arglist.getLastArg(arglist.parser.ZdynamicOption): |
| 274 | cmd_args.append('-dynamic') |
| 275 | |
| 276 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zexported_symbols_listOption, |
| 277 | '-exported_symbols_list') |
| 278 | |
| 279 | if arglist.getLastArg(arglist.parser.Zflat_namespaceOption): |
| 280 | cmd_args.append('-flat_namespace') |
| 281 | |
| 282 | arglist.addAllArgs(cmd_args, arglist.parser.headerpad_max_install_namesOption) |
| 283 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zimage_baseOption, |
| 284 | '-image_base') |
| 285 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZinitOption, |
| 286 | '-init') |
| 287 | |
| 288 | if not arglist.getLastArg(arglist.parser.m_macosxVersionMinOption): |
| 289 | if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption): |
| 290 | # FIXME: I don't understand what is going on |
| 291 | # here. This is supposed to come from |
| 292 | # darwin_ld_minversion, but gcc doesn't seem to be |
| 293 | # following that; it must be getting over-ridden |
| 294 | # somewhere. |
| 295 | cmd_args.append('-macosx_version_min') |
Daniel Dunbar | 9c257c3 | 2009-01-12 04:21:12 +0000 | [diff] [blame^] | 296 | cmd_args.append(self.getMacosxVersionMin()) |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 297 | else: |
| 298 | # addAll doesn't make sense here but this is what gcc |
| 299 | # does. |
| 300 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_macosxVersionMinOption, |
| 301 | '-macosx_version_min') |
| 302 | |
| 303 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_iphoneosVersionMinOption, |
| 304 | '-iphoneos_version_min') |
| 305 | arglist.addLastArg(cmd_args, arglist.parser.nomultidefsOption) |
| 306 | |
| 307 | if arglist.getLastArg(arglist.parser.Zmulti_moduleOption): |
| 308 | cmd_args.append('-multi_module') |
| 309 | |
| 310 | if arglist.getLastArg(arglist.parser.Zsingle_moduleOption): |
| 311 | cmd_args.append('-single_module') |
| 312 | |
| 313 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zmultiply_definedOption, |
| 314 | '-multiply_defined') |
| 315 | |
| 316 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZmultiplydefinedunusedOption, |
| 317 | '-multiply_defined_unused') |
| 318 | |
| 319 | if arglist.getLastArg(arglist.parser.f_pieOption): |
| 320 | cmd_args.append('-pie') |
| 321 | |
| 322 | arglist.addLastArg(cmd_args, arglist.parser.prebindOption) |
| 323 | arglist.addLastArg(cmd_args, arglist.parser.noprebindOption) |
| 324 | arglist.addLastArg(cmd_args, arglist.parser.nofixprebindingOption) |
| 325 | arglist.addLastArg(cmd_args, arglist.parser.prebind_all_twolevel_modulesOption) |
| 326 | arglist.addLastArg(cmd_args, arglist.parser.read_only_relocsOption) |
| 327 | arglist.addAllArgs(cmd_args, arglist.parser.sectcreateOption) |
| 328 | arglist.addAllArgs(cmd_args, arglist.parser.sectorderOption) |
| 329 | arglist.addAllArgs(cmd_args, arglist.parser.seg1addrOption) |
| 330 | arglist.addAllArgs(cmd_args, arglist.parser.segprotOption) |
| 331 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZsegaddrOption, |
| 332 | '-segaddr') |
| 333 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_only_addrOption, |
| 334 | '-segs_read_only_addr') |
| 335 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_write_addrOption, |
| 336 | '-segs_read_write_addr') |
| 337 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zseg_addr_tableOption, |
| 338 | '-seg_addr_table') |
| 339 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zfn_seg_addr_table_filenameOption, |
| 340 | '-fn_seg_addr_table_filename') |
| 341 | arglist.addAllArgs(cmd_args, arglist.parser.sub_libraryOption) |
| 342 | arglist.addAllArgs(cmd_args, arglist.parser.sub_umbrellaOption) |
| 343 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.isysrootOption, |
| 344 | '-syslibroot') |
| 345 | arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespaceOption) |
| 346 | arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespace_hintsOption) |
| 347 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZumbrellaOption, |
| 348 | '-umbrella') |
| 349 | arglist.addAllArgs(cmd_args, arglist.parser.undefinedOption) |
| 350 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zunexported_symbols_listOption, |
| 351 | '-unexported_symbols_list') |
| 352 | arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zweak_reference_mismatchesOption, |
| 353 | '-weak_reference_mismatches') |
| 354 | |
| 355 | if not arglist.getLastArg(arglist.parser.Zweak_reference_mismatchesOption): |
| 356 | cmd_args.append('-weak_reference_mismatches') |
| 357 | cmd_args.append('non-weak') |
| 358 | |
| 359 | arglist.addLastArg(cmd_args, arglist.parser.XOption) |
| 360 | arglist.addAllArgs(cmd_args, arglist.parser.yOption) |
| 361 | arglist.addLastArg(cmd_args, arglist.parser.wOption) |
| 362 | arglist.addAllArgs(cmd_args, arglist.parser.pagezero_sizeOption) |
| 363 | arglist.addAllArgs(cmd_args, arglist.parser.segs_read_Option) |
| 364 | arglist.addLastArg(cmd_args, arglist.parser.seglinkeditOption) |
| 365 | arglist.addLastArg(cmd_args, arglist.parser.noseglinkeditOption) |
| 366 | arglist.addAllArgs(cmd_args, arglist.parser.sectalignOption) |
| 367 | arglist.addAllArgs(cmd_args, arglist.parser.sectobjectsymbolsOption) |
| 368 | arglist.addAllArgs(cmd_args, arglist.parser.segcreateOption) |
| 369 | arglist.addLastArg(cmd_args, arglist.parser.whyloadOption) |
| 370 | arglist.addLastArg(cmd_args, arglist.parser.whatsloadedOption) |
| 371 | arglist.addAllArgs(cmd_args, arglist.parser.dylinker_install_nameOption) |
| 372 | arglist.addLastArg(cmd_args, arglist.parser.dylinkerOption) |
| 373 | arglist.addLastArg(cmd_args, arglist.parser.MachOption) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 374 | |
| 375 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 376 | output, outputType, args, arglist): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 377 | assert outputType is Types.ImageType |
| 378 | |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 379 | # The logic here is derived from gcc's behavior; most of which |
Daniel Dunbar | ee8cc26 | 2009-01-12 02:24:21 +0000 | [diff] [blame] | 380 | # comes from specs (starting with link_command). Consult gcc |
| 381 | # for more information. |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 382 | |
| 383 | # FIXME: gcc's spec controls when this is done; certain things |
| 384 | # like -filelist or -Wl, still trigger a link stage. I don't |
| 385 | # quite understand how gcc decides to execute the linker, |
| 386 | # investigate. Also, the spec references -fdump= which seems |
| 387 | # to have disappeared? |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 388 | cmd_args = [] |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 389 | |
| 390 | # Not sure why this particular decomposition exists in gcc. |
| 391 | self.addLinkArgs(cmd_args, arch, arglist) |
| 392 | |
Daniel Dunbar | ee8cc26 | 2009-01-12 02:24:21 +0000 | [diff] [blame] | 393 | # This toolchain never accumlates options in specs, the only |
| 394 | # place this gets used is to add -ObjC. |
| 395 | if (arglist.getLastArg(arglist.parser.ObjCOption) or |
| 396 | arglist.getLastArg(arglist.parser.f_objcOption)): |
| 397 | cmd_args.append('-ObjC') |
| 398 | if arglist.getLastArg(arglist.parser.ObjCXXOption): |
| 399 | cmd_args.append('-ObjC') |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 400 | |
| 401 | # FIXME: gcc has %{x} in here. How could this ever happen? |
| 402 | # Cruft? |
| 403 | arglist.addLastArg(cmd_args, arglist.parser.dOption) |
| 404 | arglist.addLastArg(cmd_args, arglist.parser.tOption) |
| 405 | arglist.addLastArg(cmd_args, arglist.parser.ZOption) |
| 406 | arglist.addLastArg(cmd_args, arglist.parser.uOption) |
| 407 | arglist.addLastArg(cmd_args, arglist.parser.AOption) |
| 408 | arglist.addLastArg(cmd_args, arglist.parser.eOption) |
| 409 | arglist.addLastArg(cmd_args, arglist.parser.mOption) |
| 410 | arglist.addLastArg(cmd_args, arglist.parser.rOption) |
| 411 | |
| 412 | cmd_args.extend(arglist.render(output)) |
| 413 | |
| 414 | if (not arglist.getLastArg(arglist.parser.AOption) and |
| 415 | not arglist.getLastArg(arglist.parser.nostdlibOption) and |
| 416 | not arglist.getLastArg(arglist.parser.nostartfilesOption)): |
| 417 | # Derived from startfile spec. |
| 418 | if arglist.getLastArg(arglist.parser.ZdynamiclibOption): |
| 419 | # Derived from darwin_dylib1 spec. |
| 420 | if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption): |
| 421 | cmd_args.append('-ldylib1.o') |
| 422 | else: |
| 423 | if self.macosxVersionCmp('<', '10.5', arglist): |
| 424 | cmd_args.append('-ldylib1.o') |
| 425 | else: |
| 426 | cmd_args.append('-ldylib1.10.5.o') |
| 427 | else: |
| 428 | if arglist.getLastArg(arglist.parser.ZbundleOption): |
| 429 | if not arglist.getLastArg(arglist.parser.staticOption): |
| 430 | cmd_args.append('-lbundle1.o') |
| 431 | else: |
| 432 | if arglist.getLastArg(arglist.parser.pgOption): |
| 433 | if arglist.getLastArg(arglist.parser.staticOption): |
| 434 | cmd_args.append('-lgcrt0.o') |
| 435 | else: |
| 436 | if arglist.getLastArg(arglist.parser.objectOption): |
| 437 | cmd_args.append('-lgcrt0.o') |
| 438 | else: |
| 439 | if arglist.getLastArg(arglist.parser.preloadOption): |
| 440 | cmd_args.append('-lgcrt0.o') |
| 441 | else: |
| 442 | cmd_args.append('-lgcrt1.o') |
| 443 | |
| 444 | # darwin_crt2 spec is empty. |
| 445 | pass |
| 446 | else: |
| 447 | if arglist.getLastArg(arglist.parser.staticOption): |
| 448 | cmd_args.append('-lcrt0.o') |
| 449 | else: |
| 450 | if arglist.getLastArg(arglist.parser.objectOption): |
| 451 | cmd_args.append('-lcrt0.o') |
| 452 | else: |
| 453 | if arglist.getLastArg(arglist.parser.preloadOption): |
| 454 | cmd_args.append('-lcrt0.o') |
| 455 | else: |
| 456 | # Derived from darwin_crt1 spec. |
| 457 | if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption): |
| 458 | cmd_args.append('-lcrt1.o') |
| 459 | else: |
| 460 | if self.macosxVersionCmp('<', '10.5', arglist): |
| 461 | cmd_args.append('-lcrt1.o') |
| 462 | else: |
| 463 | cmd_args.append('-lcrt1.10.5.o') |
| 464 | |
| 465 | # darwin_crt2 spec is empty. |
| 466 | pass |
| 467 | |
| 468 | if arglist.getLastArg(arglist.parser.sharedLibgccOption): |
| 469 | if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption): |
| 470 | if self.macosxVersionCmp('<', '10.5', arglist): |
| 471 | # FIXME: gcc does a library search for this |
| 472 | # file, this will be be broken currently. |
| 473 | cmd_args.append('crt3.o') |
| 474 | |
| 475 | arglist.addAllArgs(cmd_args, arglist.parser.LOption) |
| 476 | |
| 477 | if arglist.getLastArg(arglist.parser.f_openmpOption): |
| 478 | # This is more complicated in gcc... |
| 479 | cmd_args.append('-lgomp') |
| 480 | |
| 481 | # FIXME: Derive these correctly. |
Daniel Dunbar | 9c257c3 | 2009-01-12 04:21:12 +0000 | [diff] [blame^] | 482 | tcDir = self.getToolChainDir() |
| 483 | if arglist.getValue(arch) == 'x86_64': |
| 484 | cmd_args.extend(["-L/usr/lib/gcc/%s/x86_64" % tcDir, |
| 485 | "-L/usr/lib/gcc/%s/x86_64" % tcDir]) |
| 486 | cmd_args.extend(["-L/usr/lib/%s" % tcDir, |
| 487 | "-L/usr/lib/gcc/%s" % tcDir, |
| 488 | "-L/usr/lib/gcc/%s" % tcDir, |
| 489 | "-L/usr/lib/gcc/%s/../../../%s" % (tcDir,tcDir), |
| 490 | "-L/usr/lib/gcc/%s/../../.." % tcDir]) |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 491 | |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 492 | for input in inputs: |
Daniel Dunbar | 2ec55bc | 2009-01-12 03:33:58 +0000 | [diff] [blame] | 493 | cmd_args.extend(arglist.renderAsInput(input.source)) |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 494 | |
| 495 | if (arglist.getLastArg(arglist.parser.f_profileArcsOption) or |
| 496 | arglist.getLastArg(arglist.parser.f_profileGenerateOption) or |
| 497 | arglist.getLastArg(arglist.parser.f_createProfileOption) or |
| 498 | arglist.getLastArg(arglist.parser.coverageOption)): |
| 499 | cmd_args.append('-lgcov') |
| 500 | |
| 501 | if arglist.getLastArg(arglist.parser.f_nestedFunctionsOption): |
| 502 | cmd_args.append('-allow_stack_execute') |
| 503 | |
| 504 | if (not arglist.getLastArg(arglist.parser.nostdlibOption) and |
| 505 | not arglist.getLastArg(arglist.parser.nodefaultlibsOption)): |
| 506 | # link_ssp spec is empty. |
| 507 | |
| 508 | # Derived from libgcc spec. |
| 509 | if arglist.getLastArg(arglist.parser.staticOption): |
| 510 | cmd_args.append('-lgcc_static') |
| 511 | elif arglist.getLastArg(arglist.parser.staticLibgccOption): |
| 512 | cmd_args.append('-lgcc_eh') |
| 513 | cmd_args.append('-lgcc') |
| 514 | elif arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption): |
| 515 | # Derived from darwin_iphoneos_libgcc spec. |
| 516 | cmd_args.append('-lgcc_s.10.5') |
| 517 | cmd_args.append('-lgcc') |
| 518 | elif (arglist.getLastArg(arglist.parser.sharedLibgccOption) or |
| 519 | arglist.getLastArg(arglist.parser.f_exceptionsOption) or |
| 520 | arglist.getLastArg(arglist.parser.f_gnuRuntimeOption)): |
| 521 | if self.macosxVersionCmp('<', '10.5', arglist): |
| 522 | cmd_args.append('-lgcc_s.10.4') |
| 523 | else: |
| 524 | cmd_args.append('-lgcc_s.10.5') |
| 525 | cmd_args.append('-lgcc') |
| 526 | else: |
| 527 | if (self.macosxVersionCmp('<', '10.5', arglist) and |
| 528 | self.macosxVersionCmp('>=', '10.3.9', arglist)): |
| 529 | cmd_args.append('-lgcc_s.10.4') |
| 530 | else: |
| 531 | cmd_args.append('-lgcc_s.10.5') |
| 532 | cmd_args.append('-lgcc') |
| 533 | |
| 534 | # Derived from lib spec. |
| 535 | if not arglist.getLastArg(arglist.parser.staticOption): |
| 536 | cmd_args.append('-lSystem') |
| 537 | |
| 538 | if (not arglist.getLastArg(arglist.parser.AOption) and |
| 539 | not arglist.getLastArg(arglist.parser.nostdlibOption) and |
| 540 | not arglist.getLastArg(arglist.parser.nostartfilesOption)): |
| 541 | # endfile_spec is empty. |
| 542 | pass |
| 543 | |
| 544 | arglist.addAllArgs(cmd_args, arglist.parser.TOption) |
| 545 | arglist.addAllArgs(cmd_args, arglist.parser.FOption) |
| 546 | |
Daniel Dunbar | 9c257c3 | 2009-01-12 04:21:12 +0000 | [diff] [blame^] | 547 | jobs.addJob(Jobs.Command(self.getCollect2Path(), cmd_args)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 548 | |
Daniel Dunbar | 9c199a0 | 2009-01-11 23:13:15 +0000 | [diff] [blame] | 549 | # FIXME: We need to add a dsymutil job here in some particular |
| 550 | # cases (basically whenever we have a c-family input we are |
| 551 | # compiling, I think). Find out why this is the condition, and |
| 552 | # implement. See link_command spec for more details. |
| 553 | |
| 554 | def macosxVersionCmp(self, cmp, version, arglist): |
| 555 | import sys |
| 556 | print >>sys.stderr, 'FIXME: macosxVersionCmp unimplemented.' |
| 557 | return False |
| 558 | |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 559 | class LipoTool(Tool): |
| 560 | def __init__(self): |
| 561 | super(LipoTool, self).__init__('lipo') |
| 562 | |
| 563 | def constructJob(self, phase, arch, jobs, inputs, |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 564 | output, outputType, args, arglist): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 565 | assert outputType is Types.ImageType |
| 566 | |
Daniel Dunbar | db43990 | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 567 | cmd_args = ['-create'] |
Daniel Dunbar | 39cbfaa | 2009-01-07 18:54:26 +0000 | [diff] [blame] | 568 | cmd_args.extend(arglist.render(output)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 569 | for input in inputs: |
Daniel Dunbar | 2ec55bc | 2009-01-12 03:33:58 +0000 | [diff] [blame] | 570 | cmd_args.extend(arglist.renderAsInput(input.source)) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 571 | jobs.addJob(Jobs.Command('lipo', cmd_args)) |