Skip to content

Commit 0c3a02b

Browse files
committed
Function multi-versioning: disable ifunc for ELF targets other than glibc/Android/FreeBSD
Generalize D127933 (Fuchsia special case) to other ELF targets. Ensure that musl, NetBSD, OpenBSD, etc do not get ifunc codegen which is unsupported in their rtld. Link: https://discourse.llvm.org/t/does-ifunc-use-from-llvm-require-os-support/67628 Close: llvm#64631
1 parent ecc4ef9 commit 0c3a02b

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,9 @@ class TargetInfo : public TransferrableTargetInfo,
14141414

14151415
/// Identify whether this target supports IFuncs.
14161416
bool supportsIFunc() const {
1417-
return getTriple().isOSBinFormatELF() && !getTriple().isOSFuchsia();
1417+
return getTriple().isOSBinFormatELF() &&
1418+
((getTriple().isOSLinux() && !getTriple().isMusl()) ||
1419+
getTriple().isOSFreeBSD());
14181420
}
14191421

14201422
// Validate the contents of the __builtin_cpu_supports(const char*)
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
1+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=IFUNC-ELF
2+
// RUN: %clang_cc1 -triple x86_64-pc-freebsd -emit-llvm %s -o - | FileCheck %s --check-prefix=IFUNC-ELF
23
// RUN: %clang_cc1 -triple x86_64-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefixes=NO-IFUNC,WINDOWS
3-
// RUN: %clang_cc1 -triple x86_64-fuchsia -emit-llvm %s -o - | FileCheck %s --check-prefixes=NO-IFUNC,FUCHSIA
4+
// RUN: %clang_cc1 -triple x86_64-linux-musl -emit-llvm %s -o - | FileCheck %s --check-prefixes=NO-IFUNC,NO-IFUNC-ELF
5+
// RUN: %clang_cc1 -triple x86_64-fuchsia -emit-llvm %s -o - | FileCheck %s --check-prefixes=NO-IFUNC,NO-IFUNC-ELF
46
int __attribute__((target("sse4.2"))) foo(int i, ...) { return 0; }
57
int __attribute__((target("arch=sandybridge"))) foo(int i, ...);
68
int __attribute__((target("arch=ivybridge"))) foo(int i, ...) {return 1;}
@@ -10,23 +12,23 @@ int bar(void) {
1012
return foo(1, 'a', 1.1) + foo(2, 2.2, "asdf");
1113
}
1214

13-
// LINUX: @foo.ifunc = weak_odr ifunc i32 (i32, ...), ptr @foo.resolver
14-
// LINUX: define{{.*}} i32 @foo.sse4.2(i32 noundef %i, ...)
15-
// LINUX: ret i32 0
16-
// LINUX: define{{.*}} i32 @foo.arch_ivybridge(i32 noundef %i, ...)
17-
// LINUX: ret i32 1
18-
// LINUX: define{{.*}} i32 @foo(i32 noundef %i, ...)
19-
// LINUX: ret i32 2
20-
// LINUX: define{{.*}} i32 @bar()
21-
// LINUX: call i32 (i32, ...) @foo.ifunc(i32 noundef 1, i32 noundef 97, double
22-
// LINUX: call i32 (i32, ...) @foo.ifunc(i32 noundef 2, double noundef 2.2{{[0-9Ee+]+}}, ptr noundef
15+
// IFUNC-ELF: @foo.ifunc = weak_odr ifunc i32 (i32, ...), ptr @foo.resolver
16+
// IFUNC-ELF: define{{.*}} i32 @foo.sse4.2(i32 noundef %i, ...)
17+
// IFUNC-ELF: ret i32 0
18+
// IFUNC-ELF: define{{.*}} i32 @foo.arch_ivybridge(i32 noundef %i, ...)
19+
// IFUNC-ELF: ret i32 1
20+
// IFUNC-ELF: define{{.*}} i32 @foo(i32 noundef %i, ...)
21+
// IFUNC-ELF: ret i32 2
22+
// IFUNC-ELF: define{{.*}} i32 @bar()
23+
// IFUNC-ELF: call i32 (i32, ...) @foo.ifunc(i32 noundef 1, i32 noundef 97, double
24+
// IFUNC-ELF: call i32 (i32, ...) @foo.ifunc(i32 noundef 2, double noundef 2.2{{[0-9Ee+]+}}, ptr noundef
2325

24-
// LINUX: define weak_odr ptr @foo.resolver() comdat
25-
// LINUX: ret ptr @foo.arch_sandybridge
26-
// LINUX: ret ptr @foo.arch_ivybridge
27-
// LINUX: ret ptr @foo.sse4.2
28-
// LINUX: ret ptr @foo
29-
// LINUX: declare i32 @foo.arch_sandybridge(i32 noundef, ...)
26+
// IFUNC-ELF: define weak_odr ptr @foo.resolver() comdat
27+
// IFUNC-ELF: ret ptr @foo.arch_sandybridge
28+
// IFUNC-ELF: ret ptr @foo.arch_ivybridge
29+
// IFUNC-ELF: ret ptr @foo.sse4.2
30+
// IFUNC-ELF: ret ptr @foo
31+
// IFUNC-ELF: declare i32 @foo.arch_sandybridge(i32 noundef, ...)
3032

3133
// NO-IFUNC: define dso_local i32 @foo.sse4.2(i32 noundef %i, ...)
3234
// NO-IFUNC: ret i32 0
@@ -39,10 +41,10 @@ int bar(void) {
3941
// NO-IFUNC: call i32 (i32, ...) @foo.resolver(i32 noundef 2, double noundef 2.2{{[0-9Ee+]+}}, ptr noundef
4042

4143
// WINDOWS: define weak_odr dso_local i32 @foo.resolver(i32 %0, ...) comdat
42-
// FUCHSIA: define weak_odr i32 @foo.resolver(i32 %0, ...) comdat
44+
// NO-IFUNC-ELF: define weak_odr i32 @foo.resolver(i32 %0, ...) comdat
4345
// NO-IFUNC: musttail call i32 (i32, ...) @foo.arch_sandybridge
4446
// NO-IFUNC: musttail call i32 (i32, ...) @foo.arch_ivybridge
4547
// NO-IFUNC: musttail call i32 (i32, ...) @foo.sse4.2
4648
// NO-IFUNC: musttail call i32 (i32, ...) @foo
4749
// WINDOWS: declare dso_local i32 @foo.arch_sandybridge(i32 noundef, ...)
48-
// FUCHSIA: declare i32 @foo.arch_sandybridge(i32 noundef, ...)
50+
// NO-IFUNC-ELF: declare i32 @foo.arch_sandybridge(i32 noundef, ...)

clang/test/CodeGen/unique-internal-linkage-names.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test checks if internal linkage symbols get unique names with
22
// -funique-internal-linkage-names option.
3-
// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck %s --check-prefix=PLAIN
4-
// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
3+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -S -emit-llvm -o - < %s | FileCheck %s --check-prefix=PLAIN
4+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
55

66
static int glob;
77
static int foo() {

0 commit comments

Comments
 (0)