Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assembler output customization #17839

Open
Trass3r opened this issue Oct 3, 2013 · 8 comments
Open

assembler output customization #17839

Trass3r opened this issue Oct 3, 2013 · 8 comments
Labels
bugzilla Issues migrated from bugzilla clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

Comments

@Trass3r
Copy link
Contributor

Trass3r commented Oct 3, 2013

Bugzilla Link 17465
Version trunk
OS All
CC @gnzlbg,@jryans,@nico

Extended Description

It would be nice to have if clang supported gcc's -masm=dialect switch so I can get readable asm without a special case for clang to use -mllvm --x86-asm-syntax=intel.

But more importantly I'd love to have a way to generate assembler output with properly embedded source code, especially on Linux.
But that would even allow to support the /FAs switch in clang-cl and enable me to seamlessly use my existing VS addin for quick asm inspection with the newly available clang toolkit.

I already tried several different approaches.

But neither of these approaches reaches the readability of /FAs (in combination with AsmHighlighter):

?set@Point@@QEAAXNNN@Z PROC ; Point::set, COMDAT
; 47 : void set(const double X, const double Y, const double Z) { _xyz[0] = X; _xyz[1] = Y; _xyz[2] = Z; }

movsdx    QWORD PTR [rcx], xmm1
movsdx    QWORD PTR [rcx+8], xmm2
movsdx    QWORD PTR [rcx+16], xmm3
ret       0

?set@Point@@QEAAXNNN@Z ENDP ; Point::set

In this case source code is properly injected as assembler comments and there are no line numbers or machine code confusing the syntax highlighter.
But the /FA switch also allows you to add these if you need.

@nico
Copy link
Contributor

nico commented May 11, 2014

Here's a patch for -masm: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140505/105299.html

For the other thing, -fno-integrated-as -Xassembler -adhln might do the trick.

@gnzlbg
Copy link
Mannequin

gnzlbg mannequin commented Feb 23, 2016

+1 I would also like to generate source code annotated with assembly in a particular dialect. This is kind of a must to verify the assembly generated for a particular snippet of code within a large project.

@nico
Copy link
Contributor

nico commented Oct 18, 2016

fwiw, -masm=intel has been working since 208683 (clang 3.5).

@Trass3r
Copy link
Contributor Author

Trass3r commented Nov 14, 2018

MCAsmStreamer::EmitDwarfLocDirective is a POI for this.

@nico
Copy link
Contributor

nico commented Sep 4, 2019

Cross-ref "[cfe-dev] RFC: Add a way to interleave source code in assembler output" and https://reviews.llvm.org/D30897 / https://reviews.llvm.org/D30898 linked from there (apparently stalled, but maybe a good start).

See also bug 39360.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@nickdesaulniers
Copy link
Member

-fverbose-asm support in clang has come up at least twice so far on LKML (this being most recent).

@efriedma-quic mentions in https://reviews.llvm.org/D30897#inline-268745 that clang should have the source buffer around, but I thought clang was pretty aggressive about discarding the AST from memory ASAP? I think @aeubanks had some changes recently related to -clear-ast-before-backend?
https://reviews.llvm.org/D111270
https://lists.llvm.org/pipermail/cfe-dev/2021-September/068930.html

@aeubanks
Copy link
Contributor

I'm not sure if the AST is needed in this case, perhaps just the source buffer is enough? But if you do need the AST, you could skip passing -clear-ast-before-backend if -fverbose-asm.

@efriedma-quic
Copy link
Collaborator

You shouldn't need the AST, just the source code. We don't discard the source code; it's usually just mmap'ed anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
Projects
None yet
Development

No branches or pull requests

5 participants