llvm.org GIT mirror llvm / 07df6a5
[RuntimeDyld, PowerPC] Fix check for external symbols when detecting reloction overflow The PowerPC part of processRelocationRef currently assumes that external symbols can be identified by checking for SymType == SymbolRef::ST_Unknown. This is actually incorrect in some cases, causing relocation overflows to be mis-detected. The correct check is to test whether Value.SymbolName is null. Includes test case. Note that it is a bit tricky to replicate the exact condition that triggers the bug in a test case. The one included here seems to fail reliably (before the fix) across different operating system versions on Power, but it still makes a few assumptions (called out in the test case comments). Also add ppc64le platform name to the supported list in the lit.local.cfg files for the MCJIT and OrcMCJIT directories, since those tests were currently not run at all. Fixes PR32650. Reviewer: hfinkel Differential Revision: https://reviews.llvm.org/D33402 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303637 91177308-0d34-0410-b5e6-96231b3b80d8 Ulrich Weigand 3 years ago
4 changed file(s) with 37 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
13231323 Obj.getPlatformFlags(AbiVariant);
13241324 AbiVariant &= ELF::EF_PPC64_ABI;
13251325 // A PPC branch relocation will need a stub function if the target is
1326 // an external symbol (Symbol::ST_Unknown) or if the target address
1326 // an external symbol (Value.SymbolName set) or if the target address
13271327 // is not within the signed 24-bits branch address.
13281328 SectionEntry &Section = Sections[SectionID];
13291329 uint8_t *Target = Section.getAddressWithOffset(Offset);
13301330 bool RangeOverflow = false;
1331 if (SymType != SymbolRef::ST_Unknown) {
1331 if (!Value.SymbolName) {
13321332 if (AbiVariant != 2) {
13331333 // In the ELFv1 ABI, a function call may point to the .opd entry,
13341334 // so the final symbol value is calculated based on the relocation
13471347 // If it is within 26-bits branch range, just set the branch target
13481348 if (SignExtend64<26>(delta) == delta) {
13491349 RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
1350 if (Value.SymbolName)
1351 addRelocationForSymbol(RE, Value.SymbolName);
1352 else
1353 addRelocationForSection(RE, Value.SectionID);
1350 addRelocationForSection(RE, Value.SectionID);
13541351 } else {
13551352 RangeOverflow = true;
13561353 }
13571354 }
1358 if (SymType == SymbolRef::ST_Unknown || RangeOverflow) {
1355 if (Value.SymbolName || RangeOverflow) {
13591356 // It is an external symbol (SymbolRef::ST_Unknown) or within a range
13601357 // larger than 24-bits.
13611358 StubMap::const_iterator i = Stubs.find(Value);
14111408 RelType, 0);
14121409 Section.advanceStubOffset(getMaxStubSize());
14131410 }
1414 if (SymType == SymbolRef::ST_Unknown) {
1411 if (Value.SymbolName) {
14151412 // Restore the TOC for external calls
14161413 if (AbiVariant == 2)
14171414 writeInt32BE(Target + 4, 0xE8410018); // ld r2,28(r1)
88 # FIXME: autoconf and cmake produce different arch names. We should normalize
99 # them before getting here.
1010 if root.host_arch not in ['i386', 'x86', 'x86_64', 'AMD64',
11 'AArch64', 'ARM', 'Mips', 'PowerPC', 'ppc64', 'SystemZ']:
11 'AArch64', 'ARM', 'Mips',
12 'PowerPC', 'ppc64', 'ppc64le', 'SystemZ']:
1213 config.unsupported = True
1314
1415 if 'armv7' in root.host_arch:
88 # FIXME: autoconf and cmake produce different arch names. We should normalize
99 # them before getting here.
1010 if root.host_arch not in ['i386', 'x86', 'x86_64', 'AMD64',
11 'AArch64', 'ARM', 'Mips', 'PowerPC', 'ppc64', 'SystemZ']:
11 'AArch64', 'ARM', 'Mips',
12 'PowerPC', 'ppc64', 'ppc64le', 'SystemZ']:
1213 config.unsupported = True
1314
1415 if 'armv7' in root.host_arch:
0 ; RUN: %lli -jit-kind=orc-mcjit %s
1
2 ; This test is intended to verify that a function weakly defined in
3 ; JITted code, and strongly defined in the main executable, can be
4 ; correctly resolved when called from elsewhere in JITted code.
5
6 ; This test makes the assumption that the lli executable in compiled
7 ; to export symbols (e.g. --export-dynamic), and that is actually does
8 ; contain the symbol LLVMInitializeCodeGen. (Note that this function
9 ; is not actually called by the test. The test simply verifes that
10 ; the reference can be resolved without relocation errors.)
11
12 define linkonce_odr void @LLVMInitializeCodeGen() {
13 entry:
14 ret void
15 }
16
17 define void @test() {
18 entry:
19 call void @LLVMInitializeCodeGen()
20 ret void
21 }
22
23 define i32 @main() {
24 entry:
25 ret i32 0
26 }
27