[PATCH] D105176: [InstrProfiling] Use external weak reference for bias variable

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 8 14:01:20 PDT 2021


MaskRay added a comment.

In D105176#2865477 <https://reviews.llvm.org/D105176#2865477>, @phosek wrote:

> In D105176#2865370 <https://reviews.llvm.org/D105176#2865370>, @MaskRay wrote:
>
>>> We also disable the use of runtime counter relocation on Darwin since Mach-O doesn't support weak external references, but Darwin already uses a different continous mode that relies on overmapping so runtime counter relocation isn't needed there.
>>
>> I think you can restrict undefined weak to ELF now. PE-COFF doesn't have undefined weak, either.
>
> Done, do you know if there's any alternative we could use for PE-COFF?

A `comdat any` is the easiest. The runtime defines a `comdat any` variable with value 0 which can be overridden by the program.

It does rely on the link order but is the easiest.

Alternatives include `IMAGE_SYM_CLASS_WEAK_EXTERNAL` (weak definition)  and linker directives `/alternative:` both of which are quite different.

So I want to re-ask how the order difference is a problem. Using a `comdat any` can be straightforwardly ported to PE/COFF.

> I'll clarify the commit message, the issue is that relying on link order is fragile and can lead to hard-to-notice issues which we observed in practice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105176/new/

https://reviews.llvm.org/D105176



More information about the llvm-commits mailing list