[cfe-dev] LInk with/without LLVM_ENABLE_ABI_BREAKING_CHECKS
Fāng-ruì Sòng via cfe-dev
cfe-dev at lists.llvm.org
Thu Sep 17 15:10:16 PDT 2020
On Thu, Sep 17, 2020 at 2:16 PM Andy <borucki.andrzej at gmail.com> wrote:
>
> Why sometimes is OK and not need link file llvm/lib/Support/ABIBreak.cpp and sometimes is error with linked this file (required EnableABIBreakingChecks or DisableABIBreakingChecks) In abi-breaking.h is:
>
> namespace llvm {
> #if LLVM_ENABLE_ABI_BREAKING_CHECKS
> extern int EnableABIBreakingChecks;
> LLVM_HIDDEN_VISIBILITY
> __attribute__((weak)) int *VerifyEnableABIBreakingChecks =
> &EnableABIBreakingChecks;
> #else
> extern int DisableABIBreakingChecks;
> LLVM_HIDDEN_VISIBILITY
> __attribute__((weak)) int *VerifyDisableABIBreakingChecks =
> &DisableABIBreakingChecks;
> #endif
> }
>
> Always is extern EnableABIBreakingChecks or DisableABIBreakingChecks, but if is OK, no need link ABIBreak.cpp.
>
>
The mechanism was introduced in https://reviews.llvm.org/D26876 . The
idea is that a translation unit including abi-breaking.h will get a
weak hidden variable referencing either EnableABIBreakingChecks or
DisableABIBreakingChecks. The definitions are weak so multiple
definitions are allowed. But the references are strong -> if
EnableABIBreakingChecks is referenced but not defined, it will be a
linker error.
However, this scheme can create many small input .data sections if
-Wl,--gc-sections or dead stripping is not enabled. More precisely, we
waste 1778 * 8 bytes for 'opt' in a non -Wl,--gc-sections build. On
ELF, we can use zero cost references (.reloc directives) but that can
make the code even uglier.
More information about the cfe-dev
mailing list