Page MenuHomePhabricator

[Clang] Move assembler into a separate file
Needs ReviewPublic

Authored by aykevl on Jun 26 2019, 4:53 PM.



This change adds an AssemblerInvocation class, similar to the CompilerInvocation class. It can be used to invoke cc1as directly.

The project I'm working on wants to compile Clang and use it as a static library. For that to work, there must be a way to invoke the assembler programmatically, using the same arguments as you would otherwise pass to cc1as.

This patch is outdated, updating it is fairly trivial. I'd like to have some feedback on the idea first, though.

Diff Detail

Event Timeline

aykevl created this revision.Jun 26 2019, 4:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2019, 4:53 PM
aykevl updated this revision to Diff 206769.Jun 26 2019, 5:00 PM
  • removed useless anonymous namespace

*friendly ping*

aykevl added a comment.Dec 3 2019, 8:52 AM

This would be super useful to have: it avoids copying most of cc1as.

aykevl added a comment.Apr 5 2020, 8:32 AM

I'm not sure who to add as a reviewer.

aykevl edited the summary of this revision. (Show Details)Apr 5 2020, 8:33 AM

@echristo any chance you could take a look at this?

Hmm. In general I'd like to hear more about what you're trying. Can you give an idea of how you'd like to invoke the library to assemble something via clang? Why not just call into llvm directly? I'm not necessarily against changing the layering here fwiw, just wanted to get a better visual on what this is going to look like at the end and how it'll be used.


(sorry, I missed your comment)

I basically want to run clang by linking to it and calling it directly, without invoking any external commands.
You can see here how I did it:
I copied the cc1as code in the project and modified it a little bit to be callable, essentially what this patch does:

Ideally there would be something like the tinygo_clang_driver in Clang. Maybe there is, the last time I looked I couldn't find it.
What is most important is that it will not try to call clang externally, because that will make distribution much harder.

As a sidenote: I have needed to work around some global state in Clang/LLVM by creating a new process (essentially calling argv[0]) and doing the C file compilation in there. As one compiler invocation of TinyGo may need to compile several C files, global state led to problems. This is different from calling clang as I'm still shipping a single statically linked binary instead of several binaries.

The reason to not call into LLVM directly is because I want to use the compiler driver, to be compatible with all the compiler flags. Reimplementing the assembler driver would be a pain.