-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// RUN: %ldc -mtriple=x86_64-linux-gnu --relocation-model=static --output-ll -of=%t.ll %s && FileCheck --check-prefix=ELF_STATIC_RELOC %s < %t.ll | ||
// RUN: %ldc -mtriple=x86_64-linux-gnu --relocation-model=pic --output-ll -of=%t.ll %s && FileCheck --check-prefix=ELF_PIC_DEFAULT %s < %t.ll | ||
// RUN: %ldc -mtriple=x86_64-linux-gnu -fvisibility=hidden --relocation-model=pic --output-ll -of=%t.ll %s && FileCheck --check-prefix=ELF_PIC_HIDDEN %s < %t.ll | ||
// RUN: %ldc -mtriple=x86_64-apple-darwin --relocation-model=static --output-ll -of=%t.ll %s && FileCheck --check-prefix=MACHO_STATIC_RELOC %s < %t.ll | ||
// RUN: %ldc -mtriple=x86_64-apple-darwin --relocation-model=pic --output-ll -of=%t.ll %s && FileCheck --check-prefix=MACHO_PIC %s < %t.ll | ||
// RUN: %ldc -mtriple=x86_64-windows-coff -output-ll -of=%t.ll %s && FileCheck --check-prefix=COFF %s < %t.ll | ||
|
||
import ldc.attributes : weak; | ||
|
||
// ELF_STATIC_RELOC: define{{( dso_local)?}} i32 @{{.*}}3foo | ||
// ELF_PIC_DEFAULT: define i32 @{{.*}}3foo | ||
// ELF_PIC_HIDDEN: define{{( dso_local)?}} hidden i32 @{{.*}}3foo | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. besides functions, can you also add global variables? ( |
||
|
||
|
||
// ELF_STATIC_RELOC: define{{( dso_local)?}} i32 @{{.*}}3bar | ||
// ELF_PIC_DEFAULT: define i32 @{{.*}}3bar | ||
// ELF_PIC_HIDDEN: define hidden i32 @{{.*}}3bar | ||
// MACHO_STATIC_RELOC: define dso_local i32 @{{.*}}3bar | ||
// MACHO_PIC: define dso_local i32 @{{.*}}3bar | ||
// COFF: define dso_local {{.*}} i32 @{{.*}}3bar | ||
public int bar() { return foo(); } | ||
|
||
|
||
// ELF_STATIC_RELOC: define weak{{( dso_local)?}} i32 @{{.*}}3baz | ||
// ELF_PIC_DEFAULT: define weak i32 @{{.*}}3baz | ||
// ELF_PIC_HIDDEN: define weak hidden i32 @{{.*}}3baz | ||
// MACHO_STATIC_RELOC: define weak i32 @{{.*}}3baz | ||
// MACHO_PIC: define weak i32 @{{.*}}3baz | ||
// COFF: define x86_vectorcallcc i32 @{{.*}}3baz | ||
@weak int baz() { return 42; } | ||
|
||
|
||
version(Windows) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
{ | ||
// COFF: declare extern_weak void @weakreffunction | ||
pragma(LDC_extern_weak) extern(C) void weakreffunction(); | ||
|
||
void piyo() | ||
{ | ||
auto a = &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.
Don't we want dso_local here and in the other cases? (not optional)