-
-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark a function or global variable as dso_local if possible #3713
Conversation
See #2783 |
Is
|
It depends on binary format(i.e,` on COFF, extern_weak or dllimport GlobalValues must be dso_preemptable), These rules have been implemented in LLVM(shouldAssumeDSOLocal function) and I use it. My concern is that LLVM 12 drops implied dso_local for definitions in ELF static relocation model/PIE to avoid copy relocation. |
Please add testcases for all known interesting cases. Then automatically we will notice when LLVM's behavior is changing. |
b6af27a
to
b3839ee
Compare
|
||
// CHECK: declare extern_weak void @weakreffunction | ||
pragma(LDC_extern_weak) extern(C) void weakreffunction(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should also have a test for @weak
, see https://wiki.dlang.org/LDC-specific_language_changes#.40.28ldc.attributes.weak.29
@@ -0,0 +1,5 @@ | |||
// REQUIRES: atleast_llvm1200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what makes this test LLVM>=12? Is the behavior still correct for <12 ?
For the testing, I think it is more clear if you put all possibilities in one file, and have multiple |
dso_local allows the compiler to assume a function or global variable will resolve to a symbol within the same linkage unit. reference: https://llvm.org/docs/LangRef.html#runtime-preemption-specifiers
|
||
import ldc.attributes : weak; | ||
|
||
// ELF_STATIC_RELOC: define{{( dso_local)?}} i32 @{{.*}}3foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want dso_local here and in the other cases? (not optional)
@weak int baz() { return 42; } | ||
|
||
|
||
version(Windows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the version(Windows) ? This should be tested for all triples. The extern_weak attribute is afaik only useful for ELF object files.
// MACHO_STATIC_RELOC: define dso_local i32 @{{.*}}3foo | ||
// MACHO_PIC: define dso_local i32 @{{.*}}3foo | ||
// COFF: define dso_local {{.*}} i32 @{{.*}}3foo | ||
private int foo() { return 42; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
besides functions, can you also add global variables? (@weak
is also applicable to global variables btw)
I doubt this has any real effect, because the spec talks about
but the attribute is currently set for definitions only. So I think the interesting case is the opposite, declarations in other IR modules. It most likely also won't affect Windows at all, because the loader doesn't support such runtime preemption AFAIK. Whether these direct accesses are safe is another question; TypeInfos and instantiated symbols might be defined in multiple shared objects (exe/.so), so identity checks relying on the loader uniquing such symbols will probably break. AFAIK, that's why MSVC++ EH is based on type strings, and why comparing a |
Ah,, true. I'm wrong so closing now., sorry for noise. |
dso_local allows the compiler to assume a function or global variable will resolve to a symbol within the same linkage unit.
reference: https://llvm.org/docs/LangRef.html#runtime-preemption-specifiers