[PATCH] D125418: [Arm64EC 6/?] Implement C/C++ mangling for Arm64EC function definitions.

chenglin.bi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 22 16:18:31 PDT 2022


bcl5980 added a comment.

In D125418#3806720 <https://reviews.llvm.org/D125418#3806720>, @efriedma wrote:

>> Sometimes we will emit the alias here but later the function will be inlined or eliminated by DCE.
>
> If the alias is externally visible, it can't be eliminated; the compiler can't tell whether the symbol is referenced.  If the alias isn't externally visible, it's dead from the outset.  Not sure how this could become an issue.

There will be no functional issue here. I mean that we can avoid generate some redundant alias if it is in the arm64eccalllowering.

>> And later we need to emit alias for direct call thunk also, like $originname$exitthunk.
>
> Direct call thunks aren't directly relevant here; we only emit them for declarations, not definitions.  I guess this does imply that we need to teach arm64eccalllowering how to modify mangled symbol names... and we could use that same code to insert the $$h.
>
>> Put all of them into arm64eccalllowering pass should be better I think.
>
> I really don't want to do demangling in arm64eccalllowering.  But looking at the generated patterns a bit more closely, maybe we don't have to fully parse the mangled symbol.  If we can get away with just parsing the "?symbolname@@" at the beginning of the symbol, and ignore all the type-related stuff, I guess that would be okay.
>
> Alternatively, I guess we could use attributes to communicate the different mangled forms to the backend, but probably better to avoid that if we can.
>
> If we can solve the mangling issues, I guess generating the alias in arm64eccalllowering would be fine.

As far as I know, there are three kinds of alias we need to generate, For example:

  extern "C" void function_name(void a)
      arm64 signature: #function_name(native)

If it is function definition, we need to create an alias to be x86 signature, and mangle a new name to arm64ec signature. That is what this change do.

  x86 signature: function_name

If it is a function direct call case, we need to create two alias:

  function thunk: #function_name$exit_thunk
  x86 signature: function_name

I don't understand too much why we need to demangle the function name in arm64eccallovering. It looks what we need to do is generate the arm64 signature name from the default symbol name which is x86 signature by default.
I'm not familiar with normal mangle rules. If `#` and `$$h` are unique, maybe we can just insert `#` on the beginning for C symbol name or insert `$$h` after first`@@` for C++ symbol name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125418/new/

https://reviews.llvm.org/D125418



More information about the cfe-commits mailing list