This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Use COFF stubs for extern_weak functions
ClosedPublic

Authored by rnk on May 6 2019, 3:33 PM.

Details

Summary

A COFF stub indirects the reference to a symbol through memory. A
.refptr.$sym global variable pointer is created to refer to $sym.
Typically mingw uses these for external global variable declarations,
but we can use them for weak function declarations as well.

Updates the dso_local classification to add a special case for
extern_weak symbols on COFF in both clang and LLVM.

Fixes PR37598

Diff Detail

Repository
rC Clang

Event Timeline

rnk created this revision.May 6 2019, 3:33 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 6 2019, 3:33 PM
rnk updated this revision to Diff 198359.May 6 2019, 4:02 PM
  • fix some tests
mstorsjo accepted this revision.May 6 2019, 10:57 PM

LGTM, it's nice if this mechanism comes in handy in other cases than the one it was originally made for.

This revision is now accepted and ready to land.May 6 2019, 10:57 PM
smeenai accepted this revision.May 7 2019, 10:06 AM

LGTM, neat!

llvm/test/CodeGen/X86/extern_weak.ll
20–21 ↗(On Diff #198359)

I'm not parsing this too well (it's not quite clear what the relation between L_foo$non_lazy_ptr and _foo is, but I'm assuming $non_lazy_ptr is some Darwin thing that gets synthesized by the .weak_reference _foo), but I think you're just enhancing the Darwin test rather than changing that codegen in any way?

Ideally it'd be nice to have this consistent on arm and aarch64 as well, but it's not a blocker (it's not something I'm running into so far).

rnk marked an inline comment as done.May 7 2019, 11:21 AM

Thanks! I'll see about AArch64. It would be nice for this use of __attribute__((weak)) declarations to work there as well.

llvm/test/CodeGen/X86/extern_weak.ll
20–21 ↗(On Diff #198359)

Yes, it's basically the same thing as a COFF stub or a GOT entry: a global pointer that points to _foo.

This revision was automatically updated to reflect the committed changes.