<div dir="ltr"><div><div><div><div><div><div><div><div><div>I'm not sure if this is a potential bug report (I could file something more formally) or what, but I'm hitting something that's pretty weird to me.<br><br></div><div><br>G++ (random versions from GCC 4.6ish to 7.3) accepts the following code:<br><br><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><div><span style="color:rgb(0,0,255)">  extern</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(163,21,21)">"C"</span><span style="color:rgb(0,0,0)"> {</span></div><div>    <span style="color:rgb(0,0,0)"></span><span style="color:rgb(0,0,255)">static</span><span style="color:rgb(0,0,0)"> __attribute__((used)) </span><span style="color:rgb(0,0,255)">void</span><span style="color:rgb(0,0,0)"> f1() {}</span></div><div>    <span style="color:rgb(0,0,0)"></span><span style="color:rgb(0,0,255)">void</span><span style="color:rgb(0,0,0)"> f() __attribute__ ((weak, alias(</span><span style="color:rgb(163,21,21)">"f1"</span><span style="color:rgb(0,0,0)">)));</span></div><div><span style="color:rgb(0,0,0)">  }</span></div><br></div>however Clang rejects it (interested in version 6 but earlier versions reject as well), with <br><br>  <source>:3:35: error: alias must point to a defined variable or function<br><br></div>(sandbox: <a href="https://godbolt.org/g/38VVPS">https://godbolt.org/g/38VVPS</a>)<br><br></div>After playing around it for a bit, I notice something interesting. If I drop the alias and static, I get an object file with the expected symbols:<br><br>  $ cat huh.cc<br>  extern "C" {<br>    __attribute__((used)) void f(int x) { }<br>  }<br>  $ clang -c huh.cc && nm huh.o<br>  0000000000000000 T f<br><br></div>but if I include the static, then I get something that is weird to me:<br><br>  $ cat huh.cc<br>  extern "C" {<br>    static __attribute__((used)) void dummy1(int x) { }<br>  }<br>  $ clang -c huh.cc && nm huh.o<br>  0000000000000000 t f<br>  0000000000000000 t _ZL1fi<br>  $ clang -c huh.cc && nm huh.o | c++filt<br>  0000000000000000 t f<br>  0000000000000000 t f(int)<br><br></div><br></div>So I tried using the mangled name in the alias, and that works:<br><br>  extern "C" {<br>    static __attribute__((used)) void f1 () {}<br>    void f () __attribute__ ((weak, alias("_ZL2f1v"))); // OK<br>  }<br><br></div>and of course then so does this<br><br>  static __attribute__((used)) void f1 () {}<br>  extern "C" {<br>    void f () __attribute__ ((weak, alias("_ZL2f1v")));<br>  }<br><br><br></div>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...)<br><br><br></div>Anyway, I can easily work around this is my actual code, but how much of this is expected behavior?<br><br></div>Evan<br><br></div>