2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
|
2009-05-17 05:02:39 +08:00
|
|
|
namespace foo {
|
|
|
|
|
2014-02-18 07:34:47 +08:00
|
|
|
// CHECK-NOT: @a = global
|
2009-05-17 05:02:39 +08:00
|
|
|
extern "C" int a;
|
|
|
|
|
2014-02-18 07:34:47 +08:00
|
|
|
// CHECK-NOT: @_ZN3foo1bE = global
|
2009-05-17 05:02:39 +08:00
|
|
|
extern int b;
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @_ZN3foo1cE = {{(dso_local )?}}global
|
2009-05-17 05:02:39 +08:00
|
|
|
int c = 5;
|
|
|
|
|
2013-03-12 23:06:22 +08:00
|
|
|
// CHECK-NOT: @_ZN3foo1dE
|
2010-02-07 16:38:28 +08:00
|
|
|
extern "C" struct d;
|
|
|
|
|
2014-02-19 02:35:57 +08:00
|
|
|
// CHECK-NOT: should_not_appear
|
|
|
|
extern "C++" int should_not_appear;
|
2014-02-18 07:34:47 +08:00
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @_ZN3foo10extern_cxxE = {{(dso_local )?}}global
|
2016-04-29 09:23:20 +08:00
|
|
|
extern "C++" int extern_cxx = 0;
|
|
|
|
|
2009-05-17 05:02:39 +08:00
|
|
|
}
|
2013-03-12 23:06:22 +08:00
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK-NOT: @global_a = {{(dso_local )?}}global
|
2016-04-29 09:23:20 +08:00
|
|
|
extern "C" int global_a;
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @global_b = {{(dso_local )?}}global
|
2016-04-29 09:23:20 +08:00
|
|
|
extern "C" int global_b = 0;
|
|
|
|
|
|
|
|
// CHECK-NOT: should_not_appear
|
|
|
|
extern "C++" int should_not_appear;
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @extern_cxx = {{(dso_local )?}}global
|
2016-04-29 09:23:20 +08:00
|
|
|
extern "C++" int extern_cxx = 0;
|
|
|
|
|
2013-03-12 23:06:22 +08:00
|
|
|
namespace test1 {
|
|
|
|
namespace {
|
|
|
|
struct X {};
|
|
|
|
}
|
|
|
|
extern "C" {
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @test1_b = {{(dso_local )?}}global
|
2013-03-12 23:22:39 +08:00
|
|
|
X test1_b = X();
|
2013-03-12 23:06:22 +08:00
|
|
|
}
|
2013-03-12 23:22:39 +08:00
|
|
|
void *use = &test1_b;
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @_ZN5test13useE = {{(dso_local )?}}global
|
2013-03-12 23:06:22 +08:00
|
|
|
}
|
2013-03-12 23:22:39 +08:00
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
namespace {
|
|
|
|
struct X {};
|
|
|
|
}
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @test2_b = {{(dso_local )?}}global
|
2013-03-12 23:22:39 +08:00
|
|
|
extern "C" X test2_b;
|
|
|
|
X test2_b;
|
|
|
|
}
|
2013-04-06 13:00:46 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
static int unused_var;
|
|
|
|
static int unused_fn() { return 0; }
|
|
|
|
|
|
|
|
__attribute__((used)) static int internal_var;
|
|
|
|
__attribute__((used)) static int internal_fn() { return 0; }
|
|
|
|
|
|
|
|
__attribute__((used)) static int duplicate_internal_var;
|
|
|
|
__attribute__((used)) static int duplicate_internal_fn() { return 0; }
|
|
|
|
|
|
|
|
namespace N {
|
|
|
|
__attribute__((used)) static int duplicate_internal_var;
|
|
|
|
__attribute__((used)) static int duplicate_internal_fn() { return 0; }
|
|
|
|
}
|
|
|
|
|
Change some addUsedGlobal to addUsedOrCompilerUsedGlobal
An global value in the `llvm.used` list does not have GC root semantics on ELF targets.
This will be changed in a subsequent backend patch.
Change some `llvm.used` in the ELF code path to use `llvm.compiler.used` to
prevent undesired GC root semantics.
Change one extern "C" alias (due to `__attribute__((used))` in extern "C") to use `llvm.compiler.used` on all targets.
GNU ld has a rule "`__start_/__stop_` references from a live input section retain the associated C identifier name sections",
which LLD may drop entirely (currently refined to exclude SHF_LINK_ORDER/SHF_GROUP) in a future release (the rule makes it clumsy to GC metadata sections; D96914 added a way to try the potential future behavior).
For `llvm.used` global values defined in a C identifier name section, keep using `llvm.used` so that
the future LLD change will not affect them.
rnk kindly categorized the changes:
```
ObjC/blocks: this wants GC root semantics, since ObjC mainly runs on Mac.
MS C++ ABI stuff: wants GC root semantics, no change
OpenMP: unsure, but GC root semantics probably don't hurt
CodeGenModule: affected in this patch to *not* use GC root semantics so that __attribute__((used)) behavior remains the same on ELF, plus two other minor use cases that don't want GC semantics
Coverage: Probably want GC root semantics
CGExpr.cpp: refers to LTO, wants GC root
CGDeclCXX.cpp: one is MS ABI specific, so yes GC root, one is some other C++ init functionality, which should form GC roots (C++ initializers can have side effects and must run)
CGDecl.cpp: Changed in this patch for __attribute__((used))
```
Differential Revision: https://reviews.llvm.org/D97446
2021-02-27 02:42:07 +08:00
|
|
|
// CHECK: @llvm.compiler.used = appending global {{.*}} @internal_var {{.*}} @internal_fn
|
2013-04-06 13:00:46 +08:00
|
|
|
|
|
|
|
// CHECK-NOT: @unused
|
|
|
|
// CHECK-NOT: @duplicate_internal
|
2016-04-29 09:23:20 +08:00
|
|
|
// CHECK: @internal_var = internal alias i32, i32* @_ZL12internal_var
|
2013-04-06 13:00:46 +08:00
|
|
|
// CHECK-NOT: @unused
|
|
|
|
// CHECK-NOT: @duplicate_internal
|
2016-04-29 09:23:20 +08:00
|
|
|
// CHECK: @internal_fn = internal alias i32 (), i32 ()* @_ZL11internal_fnv
|
2013-04-06 13:00:46 +08:00
|
|
|
// CHECK-NOT: @unused
|
|
|
|
// CHECK-NOT: @duplicate_internal
|
|
|
|
}
|
2014-04-15 04:23:58 +08:00
|
|
|
|
|
|
|
namespace PR19411 {
|
|
|
|
struct A { void f(); };
|
|
|
|
extern "C" void A::f() { void g(); g(); }
|
|
|
|
// CHECK-LABEL: @_ZN7PR194111A1fEv(
|
2015-06-30 01:29:50 +08:00
|
|
|
// CHECK: call {{.*}}void @g()
|
2014-04-15 04:23:58 +08:00
|
|
|
}
|