Skip to content

[MergeFuncs] Don't introduce calls to (linkonce,weak)_odr functions. #10112

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

Merged
merged 3 commits into from
Mar 14, 2025

Conversation

fhahn
Copy link

@fhahn fhahn commented Feb 25, 2025

Avoid creating new calls to linkonce_odr/weak_odr functions when
merging 2 functions, as this may introduce an infinite call
cycle.

Consider 2 functions below, both present in 2 modules.

Module X

--
define linkonce_odr void @"A"() {
call void @"foo"()
}

define linkonce_odr void @"B"() {
call void @"foo"()
}

Module Y

global @"g" = @"B"

define linkonce_odr void @"A"() {
%l = load @"g"
call void %l()
}

define linkonce_odr void @"B"() {
call void @"foo"()
}

@"A" and @"B" in both modules are semantically equivalent

Module X after function merging:


define linkonce_odr void @"A"() {
call void @"foo"()
}

define linkonce_odr void @"B"() {
call void @"A"()
}

Module Y is unchanged.

Then the linker picks @"A" from module Y and @"B" from module X. Now there's an infinite call cycle

PR: llvm#125050
(cherry picked from commit f10e0f7)

rdar://143714290

@fhahn fhahn requested a review from a team as a code owner February 25, 2025 16:30
@fhahn
Copy link
Author

fhahn commented Feb 25, 2025

@swift-ci please test

@fhahn
Copy link
Author

fhahn commented Feb 26, 2025

Please test with following PR:
swiftlang/swift#79632

@swift-ci test

fhahn added a commit to swiftlang/swift that referenced this pull request Feb 26, 2025
@fhahn
Copy link
Author

fhahn commented Feb 26, 2025

Please test with following PR:
swiftlang/swift#79632

@swift-ci test

1 similar comment
@fhahn
Copy link
Author

fhahn commented Feb 27, 2025

Please test with following PR:
swiftlang/swift#79632

@swift-ci test

@fhahn fhahn force-pushed the fix-merge-func-link0nce branch from 3aa6707 to 6f09417 Compare March 4, 2025 14:44
@fhahn
Copy link
Author

fhahn commented Mar 4, 2025

@swift-ci please test

fhahn added 3 commits March 6, 2025 10:51
…lvm#125050)

Avoid creating new calls to linkonce_odr/weak_odr functions when
merging 2 functions, as this may introduce an infinite call
cycle.

Consider 2 functions below, both present in 2 modules.

Module X

--
define linkonce_odr void @"A"() {
  call void @"foo"()
}

define linkonce_odr void @"B"() {
  call void @"foo"()
}
---

Module Y
---
global @"g" = @"B"

define linkonce_odr void @"A"() {
  %l = load @"g"
  call void %l()
}

define linkonce_odr void @"B"() {
  call void @"foo"()
}
---

 @"A" and @"B" in both modules are semantically equivalent

Module X after function merging:

---
define linkonce_odr void @"A"() {
  call void @"foo"()
}

define linkonce_odr void @"B"() {
  call void @"A"()
}
---

Module Y is unchanged.

Then the linker picks @"A" from module Y and @"B" from module X. Now there's an infinite call cycle

PR: llvm#125050
(cherry picked from commit f10e0f7)
@fhahn fhahn force-pushed the fix-merge-func-link0nce branch from 6f09417 to 6f1edfc Compare March 6, 2025 10:53
@fhahn
Copy link
Author

fhahn commented Mar 6, 2025

Please test with following PR:
swiftlang/swift#79632

@swift-ci test

fhahn added a commit to swiftlang/swift that referenced this pull request Mar 6, 2025
@fhahn
Copy link
Author

fhahn commented Mar 6, 2025

Please test with following PR:
swiftlang/swift#79632

@swift-ci test

fhahn added a commit to swiftlang/swift that referenced this pull request Mar 10, 2025
fhahn added a commit to swiftlang/swift that referenced this pull request Mar 13, 2025
@fhahn
Copy link
Author

fhahn commented Mar 13, 2025

Please test with following PR:
swiftlang/swift#79632

@swift-ci test

fhahn added a commit to swiftlang/swift that referenced this pull request Mar 14, 2025
@fhahn fhahn merged commit 1e131df into swiftlang:stable/20240723 Mar 14, 2025
3 checks passed
@fhahn fhahn deleted the fix-merge-func-link0nce branch March 14, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant