From 0e124b37bd7fa42ab1087668b1fa7c35a9684deb Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 30 May 2019 19:59:20 +0000 Subject: [PATCH] [RuntimeDyld] Apply padding and alignment bumps to all sections with stubs, and increase the MachO/x86-64 stub alignment to 8. Stub alignment should be guaranteed for any section containing RuntimeDyld stubs/GOT-entries. To do this we should pad and align all sections containing stubs, not just code sections. This commit also bumps the MachO/x86-64 stub alignment to 8, so that GOT entries will be aligned. llvm-svn: 362139 --- llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 11 +++++------ .../RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h | 2 +- .../RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s | 5 +++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index f99868db4439..b1d22b89af08 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -799,13 +799,12 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, pData = data.data(); } - // Code section alignment needs to be at least as high as stub alignment or - // padding calculations may by incorrect when the section is remapped to a - // higher alignment. - if (IsCode) { + // If there are any stubs then the section alignment needs to be at least as + // high as stub alignment or padding calculations may by incorrect when the + // section is remapped. + if (StubBufSize != 0) { Alignment = std::max(Alignment, getStubAlignment()); - if (StubBufSize > 0) - PaddingSize += getStubAlignment() - 1; + PaddingSize += getStubAlignment() - 1; } // Some sections, such as debug info, don't need to be loaded for execution. diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h index 249f8dc0f29e..28febbdb948c 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h @@ -28,7 +28,7 @@ public: unsigned getMaxStubSize() const override { return 8; } - unsigned getStubAlignment() override { return 1; } + unsigned getStubAlignment() override { return 8; } Expected processRelocationRef(unsigned SectionID, relocation_iterator RelI, diff --git a/llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s b/llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s index dc69a1507259..92052957a37d 100644 --- a/llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s +++ b/llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s @@ -22,8 +22,9 @@ insn2: movl x(%rip), %eax # Test PC-rel GOT relocation. -# Verify both the contents of the GOT entry for y, and that the movq instruction -# references the correct GOT entry address: +# Verify the alignment of the GOT entry, the contents of the GOT entry for y, +# and that the movq instruction references the correct GOT entry address: +# rtdyld-check: stub_addr(test_x86-64.o/__text, y)[2:0] = 0 # rtdyld-check: *{8}(stub_addr(test_x86-64.o/__text, y)) = y # rtdyld-check: decode_operand(insn3, 4) = stub_addr(test_x86-64.o/__text, y) - next_pc(insn3) insn3: -- 2.34.1