-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FMV][AArch64] Do not emit ifunc resolver on use. (#97761)
It was raised in #81494 that we are not generating correct code when there is no TU-local caller. The suggestion was to emit a resolver: * Whenever there is a use in the TU. * When the TU has a definition of the default version. See the comment for more details: #81494 (comment) This got addressed with #84405. Generating a resolver on use means that we may end up with multiple resolvers across different translation units. Those resolvers may not be the same because each translation unit may contain different version declarations (user's fault). Therefore the order of linking the final image determines which of these weak symbols gets selected, resulting in non consisted behavior. I am proposing to stop emitting a resolver on use and only do so in the translation unit which contains the default definition. This way we guarantee the existence of a single resolver. Now, when a versioned function is used we want to emit a declaration of the function symbol omitting the multiversion mangling. I have added a requirement to ACLE mandating that all the function versions are declared in the translation unit which contains the default definition: ARM-software/acle#328
- Loading branch information
Showing
9 changed files
with
1,117 additions
and
880 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s | ||
|
||
// CHECK: @used_before_default_def = weak_odr ifunc void (), ptr @used_before_default_def.resolver | ||
// CHECK: @used_after_default_def = weak_odr ifunc void (), ptr @used_after_default_def.resolver | ||
// CHECK-NOT: @used_before_default_decl = weak_odr ifunc void (), ptr @used_before_default_decl.resolver | ||
// CHECK-NOT: @used_after_default_decl = weak_odr ifunc void (), ptr @used_after_default_decl.resolver | ||
// CHECK-NOT: @used_no_default = weak_odr ifunc void (), ptr @used_no_default.resolver | ||
// CHECK-NOT: @not_used_no_default = weak_odr ifunc void (), ptr @not_used_no_default.resolver | ||
// CHECK: @not_used_with_default = weak_odr ifunc void (), ptr @not_used_with_default.resolver | ||
|
||
|
||
// Test that an ifunc is generated and used when the default | ||
// version is defined after the first use of the function. | ||
// | ||
__attribute__((target_version("aes"))) void used_before_default_def(void) {} | ||
// CHECK-LABEL: define dso_local void @used_before_default_def._Maes( | ||
// | ||
void call_before_def(void) { used_before_default_def(); } | ||
// CHECK-LABEL: define dso_local void @call_before_def( | ||
// CHECK: call void @used_before_default_def() | ||
// | ||
__attribute__((target_version("default"))) void used_before_default_def(void) {} | ||
// CHECK-LABEL: define dso_local void @used_before_default_def.default( | ||
// | ||
// CHECK-NOT: declare void @used_before_default_def( | ||
|
||
|
||
// Test that an ifunc is generated and used when the default | ||
// version is defined before the first use of the function. | ||
// | ||
__attribute__((target_version("aes"))) void used_after_default_def(void) {} | ||
// CHECK-LABEL: define dso_local void @used_after_default_def._Maes( | ||
// | ||
__attribute__((target_version("default"))) void used_after_default_def(void) {} | ||
// CHECK-LABEL: define dso_local void @used_after_default_def.default( | ||
// | ||
void call_after_def(void) { used_after_default_def(); } | ||
// CHECK-LABEL: define dso_local void @call_after_def( | ||
// CHECK: call void @used_after_default_def() | ||
// | ||
// CHECK-NOT: declare void @used_after_default_def( | ||
|
||
|
||
// Test that an unmagled declaration is generated and used when the | ||
// default version is declared after the first use of the function. | ||
// | ||
__attribute__((target_version("aes"))) void used_before_default_decl(void) {} | ||
// CHECK-LABEL: define dso_local void @used_before_default_decl._Maes( | ||
// | ||
void call_before_decl(void) { used_before_default_decl(); } | ||
// CHECK-LABEL: define dso_local void @call_before_decl( | ||
// CHECK: call void @used_before_default_decl() | ||
// | ||
__attribute__((target_version("default"))) void used_before_default_decl(void); | ||
// CHECK: declare void @used_before_default_decl() | ||
|
||
|
||
// Test that an unmagled declaration is generated and used when the | ||
// default version is declared before the first use of the function. | ||
// | ||
__attribute__((target_version("aes"))) void used_after_default_decl(void) {} | ||
// CHECK-LABEL: define dso_local void @used_after_default_decl._Maes( | ||
// | ||
__attribute__((target_version("default"))) void used_after_default_decl(void); | ||
// CHECK: declare void @used_after_default_decl() | ||
// | ||
void call_after_decl(void) { used_after_default_decl(); } | ||
// CHECK-LABEL: define dso_local void @call_after_decl( | ||
// CHECK: call void @used_after_default_decl() | ||
|
||
|
||
// Test that an unmagled declaration is generated and used when | ||
// the default version is not present. | ||
// | ||
__attribute__((target_version("aes"))) void used_no_default(void) {} | ||
// CHECK-LABEL: define dso_local void @used_no_default._Maes( | ||
// | ||
void call_no_default(void) { used_no_default(); } | ||
// CHECK-LABEL: define dso_local void @call_no_default( | ||
// CHECK: call void @used_no_default() | ||
// | ||
// CHECK: declare void @used_no_default() | ||
|
||
|
||
// Test that neither an ifunc nor a declaration is generated if the default | ||
// definition is missing since the versioned function is not used. | ||
// | ||
__attribute__((target_version("aes"))) void not_used_no_default(void) {} | ||
// CHECK-LABEL: define dso_local void @not_used_no_default._Maes( | ||
// | ||
// CHECK-NOT: declare void @not_used_no_default( | ||
|
||
|
||
// Test that an ifunc is generated if the default version is defined but not used. | ||
// | ||
__attribute__((target_version("aes"))) void not_used_with_default(void) {} | ||
// CHECK-LABEL: define dso_local void @not_used_with_default._Maes( | ||
// | ||
__attribute__((target_version("default"))) void not_used_with_default(void) {} | ||
// CHECK-LABEL: define dso_local void @not_used_with_default.default( | ||
// | ||
// CHECK-NOT: declare void @not_used_with_default( | ||
|
||
|
||
// CHECK: define weak_odr ptr @used_before_default_def.resolver() | ||
// CHECK: define weak_odr ptr @used_after_default_def.resolver() | ||
// CHECK-NOT: define weak_odr ptr @used_before_default_decl.resolver( | ||
// CHECK-NOT: define weak_odr ptr @used_after_default_decl.resolver( | ||
// CHECK-NOT: define weak_odr ptr @used_no_default.resolver( | ||
// CHECK-NOT: define weak_odr ptr @not_used_no_default.resolver( | ||
// CHECK: define weak_odr ptr @not_used_with_default.resolver() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.