Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Clang/LLVM expose a weak symbol, preventing us linking. #47533

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR48563
Status NEW
Importance P normal
Reported by Nick Andrews (kalamatee@gmail.com)
Reported on 2020-12-20 05:33:55 -0800
Last modified on 2020-12-22 16:01:38 -0800
Version 10.0
Hardware PC Windows NT
CC htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, rnk@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
We use an ASM macro to create an Alias extensively in our operating system,
however under LLVM/Clang it does not work, preventing us using the LLVM
toolchain from compiling the Operating System (www.aros.org).

#define __AROS_GM_STACKALIAS(fname, alias) \
    void alias(void); \
    asm(".weak " __GM_STRINGIZE(alias) "\n" \
        "\t.set " __GM_STRINGIZE(alias) "," #fname \
    );

The following is a simplified testcase showing the behaviour -:

extern void foo(void);
void bar(void);

asm(".weak foo\n"
        "\t.set foo,bar");

void*functable[] =
{
    &foo,
    (void *)0
};

When this is compiled with GNU/GCC, we only have 2 symbols exposed - "bar", and
"functable", however with LLVM/Clang - there is also a weak reference for "foo"
exposed, which then is not resolved during linking.
Quuxplusone commented 3 years ago
This is more likely to be a difference in behavior between the gnu binutils
assembler and the LLVM MC assembler. (llvm-mc vs as) Does the problem go away
if you add -fno-integrated-as?

As an alternative workaround, can you replace the module level assembly with an
alias attribute, like so?
  void foo () __attribute__ ((weak, alias ("bar")));
I'm not 100% confident that the above is equivalent, but the idea of a weak
alias is surely representable without asm.
Quuxplusone commented 3 years ago
> This is more likely to be a difference in behavior between the gnu binutils
assembler and the LLVM MC assembler. (llvm-mc vs as)

> Does the problem go away if you add -fno-integrated-as?

I'm currently looking at how we may integrate this into the build for the
affected components. Atleast for the test case itself it appears to work
however using the switch wholesale in our build causes other breakage earlier.

> As an alternative workaround, can you replace the module level assembly with
an  alias attribute, like so?
>   void foo () __attribute__ ((weak, alias ("bar")));
> I'm not 100% confident that the above is equivalent, but the idea of a weak
alias > is surely representable without asm

I don't think I cant get it to work this way, atleast not with my attempts so
far. The code where this is predominantly used may or may not include
prototypes for either of the aliased function, or the function itself - or
both, which causes various errors in my attempts so far.
Quuxplusone commented 3 years ago
(In reply to Nick Andrews from comment #2)
> > This is more likely to be a difference in behavior between the gnu binutils
assembler and the LLVM MC assembler. (llvm-mc vs as)
>
> > Does the problem go away if you add -fno-integrated-as?
>
> I'm currently looking at how we may integrate this into the build for the
> affected components. Atleast for the test case itself it appears to work
> however using the switch wholesale in our build causes other breakage
> earlier.
>

Ok this also doesn't work for us in practice. Adding it to the necessary flags
for the modules results in other failure (.s files processed using the compiler
with -x assembler-with-cpp now have problems).