Hello,
I have an assembly file test.s
shell # swiftc -emit-assembly test.swift -o test.s
I got an error while trying to produce an object file
shell # swiftc test.s -emit-object -o test.o
:0: error: unexpected input file: test.s
Regards,
Nikolai Kinash
That's not supported at the moment. You could compile the individual swift files to object files, but I'm guessing that's not what you're looking for.
Jumhyn
(Frederick Kellison-Linn)
3
Does swiftc's -emit-assembly option not produce an assembly file that could be compiled by clang?
Both Clang and Swift should be using the ~same assembler, so I don't think it should matter.
$ cat main.swift
print("Hello")
$ xcrun swiftc main.swift && ./main
Hello
$ xcrun swiftc main.swift -emit-assembly -o main.S && xcrun clang++ main.S -c -o main.o && xcrun swiftc main.o -emit-executable && ./main
Hello
It does seem to work, but I don't know if this will always work or if there are situations where it may fall over.
1 Like
jonprescott
(Jonathan Prescott)
5
But, you had to use clang/clang++ to generate the actual object file. I think the OP thought he could use swiftc for the whole toolchain.
I already answered OP's question in my first comment; you can ask swiftc to go from source code → object code, or source code → assembly, but assembly → object code is not supported.
My previous comment was meant as an answer to @.Jumhyn's question, not to OP's question.
2 Likes
Unfortunately it doesn't always works.
file 4.bc
4.bc: LLVM bitcode, wrapper arm
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -frontend -emit-assembly -target armv7-apple-ios10.0 -O -disable-llvm-optzns -module-name SwiftTester 4.bc -o 4.s
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -cc1as -triple armv7-apple-ios10.0 -o 4.o 4.s
4.s:1307:17: error: non-local symbol required in directive
.no_dead_strip "L___ir_hidden#98_"
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -frontend -emit-object -target armv7-apple-ios10.0 4.s -o 4.o
<unknown>:0: error: unable to load standard library for target 'armv7-apple-ios10.0'
But anyway thanks everybody for the answers