Anahit Hayrapetyan via llvm-dev
2020-Feb-17 10:06 UTC
[llvm-dev] Compile assembly to llvm bitcode
Hi all, Is it possible to compile assembler source code to llvm bitcode? And if yes, then how? I’m trying to compile a project to llvm bitcode. The project has both C (.c) sources and some assembly(.S) sources. The make compiles all sources to object (.o) files and then links them together. What I’m trying to do is replace all commands compiling to .o with ‘clang -c -emit-llvm ...’ to get bitcodes and then use “llvm-link” to link them together in one .bc. However the llvm-link fails as the bitcodes I got from .s files are not recognized as llvm bitcodes (the header does not correspond to llvm bitcode header). Best, Anahit. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200217/d58bc3d9/attachment-0001.html>
David Blaikie via llvm-dev
2020-Feb-18 17:27 UTC
[llvm-dev] Compile assembly to llvm bitcode
There's no compiler driver support for that task, no. Why are you trying to compile everything to bitcode/link them together in that way? (might be other solutions to consider) On Mon, Feb 17, 2020 at 6:13 PM Anahit Hayrapetyan via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi all, > > Is it possible to compile assembler source code to llvm bitcode? And if > yes, then how? > > I’m trying to compile a project to llvm bitcode. The project has both C > (.c) sources and some assembly(.S) sources. The make compiles all sources > to object (.o) files and then links them together. What I’m trying to do is > replace all commands compiling to .o with ‘clang -c -emit-llvm ...’ to get > bitcodes and then use “llvm-link” to link them together in one .bc. However > the llvm-link fails as the bitcodes I got from .s files are not recognized > as llvm bitcodes (the header does not correspond to llvm bitcode header). > > Best, > Anahit. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200218/13f0e195/attachment.html>
Reid Kleckner via llvm-dev
2020-Feb-18 20:05 UTC
[llvm-dev] Compile assembly to llvm bitcode
If you are able to treat the assembly routines as calls to external functions, you should be able to use LLD or gold for this use case instead of llvm-link. In this case, the .s files will be compiled to native objects, symbol resolution will occur as usual, LLD will perform an LTO link, and there should be a way to get the fully linked and optimized bitcode blob before it is compiled to a native object file. At the very least, you can do this with -save-temps. I can't find a better way to do it at the moment, although I see -lto-obj-path=, which controls where the native object file goes. On Mon, Feb 17, 2020 at 6:13 PM Anahit Hayrapetyan via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi all, > > Is it possible to compile assembler source code to llvm bitcode? And if > yes, then how? > > I’m trying to compile a project to llvm bitcode. The project has both C > (.c) sources and some assembly(.S) sources. The make compiles all sources > to object (.o) files and then links them together. What I’m trying to do is > replace all commands compiling to .o with ‘clang -c -emit-llvm ...’ to get > bitcodes and then use “llvm-link” to link them together in one .bc. However > the llvm-link fails as the bitcodes I got from .s files are not recognized > as llvm bitcodes (the header does not correspond to llvm bitcode header). > > Best, > Anahit. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200218/c9b00234/attachment.html>