-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LinkerWrapper] Fix resolution of weak symbols during LTO (#68215)
Summary: Weak symbols are supposed to have the semantics that they can be overriden by a strong (i.e. global) definition. This wasn't being respected by the LTO pass because we simply used the first definition that was available. This patch fixes that logic by doing a first pass over the symbols to check for strong resolutions that could override a weak one. A lot of fake linker logic is ending up in the linker wrapper. If there were an option to handle this in `lld` it would be a lot cleaner, but unfortunately supporting NVPTX is a big restriction as their binaries require the `nvlink` tool.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 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,33 @@ | ||
// RUN: %libomptarget-compile-generic -DA -c -o %t-a.o | ||
// RUN: %libomptarget-compile-generic -DB -c -o %t-b.o | ||
// RUN: %libomptarget-compile-generic %t-a.o %t-b.o && \ | ||
// RUN: %libomptarget-run-generic | %fcheck-generic | ||
|
||
#if defined(A) | ||
__attribute__((weak)) int x = 999; | ||
#pragma omp declare target to(x) | ||
#elif defined(B) | ||
int x = 42; | ||
#pragma omp declare target to(x) | ||
__attribute__((weak)) int y = 42; | ||
#pragma omp declare target to(y) | ||
#else | ||
|
||
#include <stdio.h> | ||
|
||
extern int x; | ||
#pragma omp declare target to(x) | ||
extern int y; | ||
#pragma omp declare target to(y) | ||
|
||
int main() { | ||
x = 0; | ||
|
||
#pragma omp target update from(x) | ||
#pragma omp target update from(y) | ||
|
||
// CHECK: PASS | ||
if (x == 42 && y == 42) | ||
printf("PASS\n"); | ||
} | ||
#endif |