diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -571,8 +571,8 @@ return false; // Relative pointers do not need to be dynamically relocated. - if (auto *LHSGV = dyn_cast(LHSOp0->stripPointerCasts())) - if (auto *RHSGV = dyn_cast(RHSOp0->stripPointerCasts())) + if (auto *LHSGV = dyn_cast(LHSOp0->stripInBoundsConstantOffsets())) + if (auto *RHSGV = dyn_cast(RHSOp0->stripInBoundsConstantOffsets())) if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal()) return false; } diff --git a/llvm/test/CodeGen/X86/relptr-rodata.ll b/llvm/test/CodeGen/X86/relptr-rodata.ll --- a/llvm/test/CodeGen/X86/relptr-rodata.ll +++ b/llvm/test/CodeGen/X86/relptr-rodata.ll @@ -19,3 +19,27 @@ ; CHECK: relro2: ; CHECK: .long hidden-relro2 @relro2 = constant i32 trunc (i64 sub (i64 ptrtoint (i8* @hidden to i64), i64 ptrtoint (i32* @relro2 to i64)) to i32) + +; CHECK: .section .rodata.cst16 +; CHECK-NEXT: .globl _ZTV4Test +; CHECK: _ZTV4Test +; CHECK: .quad 0 +; CHECK: .long (_ZTI4Test.rtti_proxy-_ZTV4Test)-12 +; CHECK: .long (_ZN4TestD1Ev.stub@PLT-_ZTV4Test)-12 + +@_ZTI4Test = external global i8 +@_ZTI4Test.rtti_proxy = hidden unnamed_addr constant i8* @_ZTI4Test + +declare void @_ZN4TestD2Ev() +define hidden void @_ZN4TestD1Ev.stub() unnamed_addr { +entry: + tail call void @_ZN4TestD2Ev() + ret void +} + +@_ZTV4Test = dso_local unnamed_addr constant { { i8*, i32, i32 } } { + { i8*, i32, i32 } { + i8* null, + i32 trunc (i64 sub (i64 ptrtoint (i8** @_ZTI4Test.rtti_proxy to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @_ZTV4Test, i32 0, i32 0, i32 2) to i64)) to i32), + i32 trunc (i64 sub (i64 ptrtoint (void ()* @_ZN4TestD1Ev.stub to i64), i64 ptrtoint (i32* getelementptr inbounds ({ { i8*, i32, i32 } }, { { i8*, i32, i32 } }* @_ZTV4Test, i32 0, i32 0, i32 2) to i64)) to i32) + } }, align 8