[cfe-dev] clang as an x64 assembler
Tim Northover via cfe-dev
cfe-dev at lists.llvm.org
Mon Jun 12 14:48:29 PDT 2017
Hi Mike,
On 12 June 2017 at 14:24, Mike Benfield via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Are these commands (and other relevant command line options) documented
> somewhere?
The "-x assembler" shouldn't be needed. It's assumed for files ending
in .s. I don't think it's really documented anywhere, it's just that
.s files are one of the inputs Clang accepts.
> Is the supported assembly syntax documented somewhere (it seems
> to support GAS syntax; is it reasonable to use the GAS manual as a
> reference?)?
It's broadly GNU syntax, though the concepts available in MachO differ
from ELF so some care is needed using the GNU manuals. For example on
AArch64, Linux you'd materialize a global address like this:
adrp x0, some_var
add x0, x0, :lo12:some_var
but targeting iOS you'd write:
adrp x0, some_var at PAGE
add x0, x0, some_var at PAGEOFF
Still, many/most GNU directives are cross-platform and we support
those in the way you'd expect (or we should do). And I'd also expect
GNU as to follow the same syntax if it was targeting Darwin.
I usually check Clang's output from a C file whenever I can't remember
what the right directives are.
> Is this recommended? That is, is the integrated assembler intended to be
> used to write assembly code for a production system in this way, and is it
> reasonable to rely on it continuing to work in the future?
Finally I can give some good news! This is fully supported and pretty
stable. There's loads of assembly files out there in the wild which
no-one is going to break.
Cheers.
Tim.
More information about the cfe-dev
mailing list