Skip to content
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

ThinLTO + CFI can introduce duplicate symbols #60135

Open
ilovepi opened this issue Jan 19, 2023 · 3 comments
Open

ThinLTO + CFI can introduce duplicate symbols #60135

ilovepi opened this issue Jan 19, 2023 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior compiler-rt:cfi Control Flow Integrity LTO Link time optimization (regular/full LTO or ThinLTO)

Comments

@ilovepi
Copy link
Contributor

ilovepi commented Jan 19, 2023

In https://reviews.llvm.org/D137982 we found that introducing an alias to a function could interact poorly w/ ThinLTO + PGO + CFI, and introduced duplicate symbols into the binary.

The original bug can be found in the chromium bug tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1408161

In our investigation we found that GlobalOpt replaced the alias we generated in InstrProfiling.cpp. This only appears to manifest w/ non-local linkage types. Note we only observed this w/ weak/linkonce_odr in comdat groups where the alias and function had hidden visibility. It's not entirely clear this is the correct behavior, however, since the surrounding code in GlobalOpt doesn't appear to only do this for functions with hidden visibility. The other issue was that, despite it replacing all the uses of the alias, the alias was not removed from the module.

Later in LowerTypeTests, there is some fairly complex logic to generate and/or replace existing aliases. This appears to be where the duplicate symbol is introduced, since it was not completely removed in GlobalOpt. I think it's also possible that the duplicate symbol is introduced through use of a Twine, but that is only speculation at this point.

We should investigate this more thoroughly and make sure that the implementations in both GlobalOpt and LowerTypeTests correctly handle these cases and work well together. While we've mitigated this problem in https://reviews.llvm.org/D137982 for the aliases we introduced during PGO instrumentation, the alias types we introduced were legal and should not have resulted duplicate symbols.

Looping in relevant parties from the original bug report.
CC @aeubanks @teresajohnson @petrhosek

@ilovepi ilovepi added bug Indicates an unexpected problem or unintended behavior compiler-rt:cfi Control Flow Integrity LTO Link time optimization (regular/full LTO or ThinLTO) labels Jan 19, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 19, 2023

@llvm/issue-subscribers-bug

@teresajohnson
Copy link
Contributor

@pcc can you take a look? I'm less familiar with the CFI code in LowerTypeTests referenced here.

@pcc
Copy link
Contributor

pcc commented Jan 21, 2023

I reproduced the bug, looking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler-rt:cfi Control Flow Integrity LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

No branches or pull requests

4 participants