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

ASAN incorrectly flags ODR violation on C++17 inline variables when one definition is compiled in C++14. #28765

Closed
llvmbot opened this issue Jul 2, 2016 · 4 comments
Labels
bugzilla Issues migrated from bugzilla compiler-rt invalid Resolved as invalid, i.e. not a bug

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 2, 2016

Bugzilla Link 28391
Resolution INVALID
Resolved on Aug 30, 2017 10:05
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@KernelAddress,@hfinkel,@rnk

Extended Description

Reproducer:
// Steps to reproduce:
// clang++ -std=c++14 -fsanitize=address -DTU_ONE -shared -fPIC -o libfoo.so test.cpp
// clang++ -std=c++1z -fsanitize=address test.cpp libfoo.so
// ./a.out
// EXPECTED: exit success
// ACTUAL: AddressSanitizer: odr-violation
struct Foo {
static constexpr bool inline_var = true;
};
#ifdef TU_ONE
constexpr bool Foo::inline_var;
#else
void test(const bool&) {}
int main() {
test(Foo::inline_var);
}
#endif

In the above reproducer the main program generates a definition for Foo::inline_var according to the C++17 inline variable rules. The program then links to a library compiled as C++14 which provides the explicit definition for Foo::inline_bool. When this program is run ASAN will emit an odr-violation diagnostic for 'inline_bool'.

I believe this diagnostic is a false positive even though one of the two definitions was not compiled with C++17 inline variable semantics.

@rnk
Copy link
Collaborator

rnk commented Jul 2, 2016

I think the bug is that C++17 introduces an ABI break with C++14 by changing the linkage of inline_var from external to linkonce_odr.

@KernelAddress
Copy link
Mannequin

KernelAddress mannequin commented Aug 30, 2017

Not as asan bug, the ODR violation is real.

@KernelAddress
Copy link
Mannequin

KernelAddress mannequin commented Aug 30, 2017

Not an asan bug

@dwblaikie
Copy link
Collaborator

I think the bug is that C++17 introduces an ABI break with C++14 by changing
the linkage of inline_var from external to linkonce_odr.

Is that an ABI break though? If the external definition and linkonce_odr definition are linked together the link will succeed, right? (the linkonce_odr will be dropped in favor of the external definition)

(maybe this is fine for ELF/maybe some other object formats but not in LLVM IR? Not sure what the semantics of linking a Module with a linkonce_odr definition with a Module with an external/strong definition are)

I mean it's a break if you do it the other way - ship your C++17 library to someone building as C++14. But if you ship your C++14 library to people building with your headers as C++17? That seems like it might thread the needle & be 'good'-ish?

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compiler-rt invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

3 participants