[cfe-dev] Creating an alias to a static function in C++

Evan Driscoll via cfe-dev cfe-dev at lists.llvm.org
Tue May 1 21:56:51 PDT 2018


On Tue, May 1, 2018 at 11:43 PM, Evan Driscoll <evaned at gmail.com> wrote:

>   $ cat huh.cc
>   extern "C" {
>     static __attribute__((used)) void dummy1(int x) { }
>   }
>   $ clang -c huh.cc && nm huh.o
>   0000000000000000 t f
>   0000000000000000 t _ZL1fi
>   $ clang -c huh.cc && nm huh.o | c++filt
>   0000000000000000 t f
>   0000000000000000 t f(int)
>

In the interest of hopefully eliminating confusion -- sorry for the output
not exactly matching up with the examples in terms of function names. I was
working half in Compiler Explorer and half with a file on a local file
system. I noticed as I was finishing the email, and thought I'd try to
align the names by editing the command output to match... but of course
that is always a bad idea. :-)

Anyway, of course that code doesn't produce an object file with a symbol
'f' in it, it'd be 'dummy1'. The presence of both the unmangled and mangled
symbols is the same though.

Evan




>
>
> So I tried using the mangled name in the alias, and that works:
>
>   extern "C" {
>     static __attribute__((used)) void f1 () {}
>     void f () __attribute__ ((weak, alias("_ZL2f1v"))); // OK
>   }
>
> and of course then so does this
>
>   static __attribute__((used)) void f1 () {}
>   extern "C" {
>     void f () __attribute__ ((weak, alias("_ZL2f1v")));
>   }
>
>
> Furthermore, if I browse the Itanium ABI page, I can't even figure out how
> you get a "_ZL..." mangled symbol, but I'm sure I'm missing something (e.g.
> c++filt demangles it fine...)
>
>
> Anyway, I can easily work around this is my actual code, but how much of
> this is expected behavior?
>
> Evan
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180501/1c3f8da6/attachment.html>


More information about the cfe-dev mailing list