llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.86k stars 11.48k forks source link

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

Open llvmbot opened 3 years ago

llvmbot commented 3 years ago
Bugzilla Link 48563
Version 10.0
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @rnk

Extended Description

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.

llvmbot 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.

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).

llvmbot 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.

rnk 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.