From 60230ef987f234df88a166fc7878cf3051bca0a1 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Fri, 4 Jan 2013 17:59:22 +0000 Subject: Add section information for the DWARF5 split debug proposal string offset section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171474 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCObjectFileInfo.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/MC/MCObjectFileInfo.cpp') diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index d57e0c5b4a..d73b9b1005 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -426,6 +426,9 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { DwarfLocDWOSection = Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, SectionKind::getMetadata()); + DwarfStrOffDWOSection = + Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0, + SectionKind::getMetadata()); } -- cgit v1.2.3-70-g09d2 From 7b449889e7886b263718b5103538970f287bc37e Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Fri, 4 Jan 2013 19:08:13 +0000 Subject: PowerPC: Fix eh_frame relocation for PIC This patch fixes the PPC eh_frame definitions for the personality and frame unwinding for PIC objects. It makes PIC build correctly creates relative relocations in the '.rela.eh_frame' segments and thus avoiding a text relocation that generates a DT_TEXTREL segments in link phase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171506 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ELF.h | 2 + lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 6 ++ lib/MC/MCObjectFileInfo.cpp | 11 +++ .../PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp | 5 + test/MC/PowerPC/ppc64-initial-cfa.ll | 103 ++++++++++++++------- 5 files changed, 94 insertions(+), 33 deletions(-) (limited to 'lib/MC/MCObjectFileInfo.cpp') diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h index d0422b3bfa..e351fbc795 100644 --- a/include/llvm/Support/ELF.h +++ b/include/llvm/Support/ELF.h @@ -464,6 +464,7 @@ enum { // ELF Relocation types for PPC64 enum { + R_PPC64_ADDR32 = 1, R_PPC64_ADDR16_LO = 4, R_PPC64_ADDR16_HI = 5, R_PPC64_ADDR14 = 7, @@ -471,6 +472,7 @@ enum { R_PPC64_ADDR64 = 38, R_PPC64_ADDR16_HIGHER = 39, R_PPC64_ADDR16_HIGHEST = 41, + R_PPC64_REL64 = 44, R_PPC64_TOC16 = 47, R_PPC64_TOC16_LO = 48, R_PPC64_TOC16_HA = 50, diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index f32e3871b8..efb34df8c5 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -517,6 +517,12 @@ void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section, uint8_t aalk = *(LocalAddress+3); writeInt16BE(LocalAddress + 2, (aalk & 3) | ((Value + Addend) & 0xfffc)); } break; + case ELF::R_PPC64_ADDR32 : { + int32_t Result = static_cast(Value + Addend); + if (SignExtend32<32>(Result) != Result) + llvm_unreachable("Relocation R_PPC64_REL32 overflow"); + writeInt32BE(LocalAddress, Result); + } break; case ELF::R_PPC64_REL24 : { uint64_t FinalAddress = (Section.LoadAddress + Offset); int32_t delta = static_cast(Value - FinalAddress + Addend); diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index d73b9b1005..a46f7be5da 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -256,6 +256,17 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { TTypeEncoding = (CMModel == CodeModel::Small) ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; } + } else if (T.getArch() == Triple::ppc64) { + PersonalityEncoding = dwarf::DW_EH_PE_udata8; + PersonalityEncoding |= (RelocM == Reloc::PIC_) + ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel + : dwarf::DW_EH_PE_absptr; + unsigned PICFlag = (RelocM == Reloc::PIC_) ? dwarf::DW_EH_PE_pcrel + : dwarf::DW_EH_PE_absptr; + FDECFIEncoding = PICFlag | dwarf::DW_EH_PE_sdata4; + LSDAEncoding = PICFlag | dwarf::DW_EH_PE_udata8; + FDEEncoding = PICFlag | dwarf::DW_EH_PE_sdata4; + TTypeEncoding = PICFlag | dwarf::DW_EH_PE_sdata4; } // Solaris requires different flags for .eh_frame to seemingly every other diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp index 7f4d9a28d0..d61e741ef5 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp @@ -77,9 +77,14 @@ unsigned PPCELFObjectWriter::getRelocTypeInner(const MCValue &Target, case PPC::fixup_ppc_br24: Type = ELF::R_PPC_REL24; break; + case FK_Data_4: case FK_PCRel_4: Type = ELF::R_PPC_REL32; break; + case FK_Data_8: + case FK_PCRel_8: + Type = ELF::R_PPC64_REL64; + break; } } else { switch ((unsigned)Fixup.getKind()) { diff --git a/test/MC/PowerPC/ppc64-initial-cfa.ll b/test/MC/PowerPC/ppc64-initial-cfa.ll index 3936cf2e81..0e36fb7138 100644 --- a/test/MC/PowerPC/ppc64-initial-cfa.ll +++ b/test/MC/PowerPC/ppc64-initial-cfa.ll @@ -1,41 +1,78 @@ -;; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -filetype=obj %s -o - | \ -;; RUN: elf-dump --dump-section-data | FileCheck %s +; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -filetype=obj -relocation-model=static %s -o - | \ +; RUN: elf-dump --dump-section-data | FileCheck %s -check-prefix=STATIC +; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -filetype=obj -relocation-model=pic %s -o - | \ +; RUN: elf-dump --dump-section-data | FileCheck %s -check-prefix=PIC -;; FIXME: this file should be in .s form, change when asm parser is available. +; FIXME: this file should be in .s form, change when asm parser is available. define void @f() { entry: ret void } -;; CHECK: ('sh_name', 0x{{.*}}) # '.eh_frame' -;; CHECK-NEXT: ('sh_type', 0x00000001) -;; CHECK-NEXT: ('sh_flags', 0x0000000000000002) -;; CHECK-NEXT: ('sh_addr', 0x{{.*}}) -;; CHECK-NEXT: ('sh_offset', 0x{{.*}}) -;; CHECK-NEXT: ('sh_size', 0x0000000000000030) -;; CHECK-NEXT: ('sh_link', 0x00000000) -;; CHECK-NEXT: ('sh_info', 0x00000000) -;; CHECK-NEXT: ('sh_addralign', 0x0000000000000008) -;; CHECK-NEXT: ('sh_entsize', 0x0000000000000000) -;; CHECK-NEXT: ('_section_data', '00000010 00000000 017a5200 01784101 000c0100 00000018 00000018 00000000 00000000 00000000 00000010 00000000') - -;; CHECK: ('sh_name', 0x{{.*}}) # '.rela.eh_frame' -;; CHECK-NEXT: ('sh_type', 0x00000004) -;; CHECK-NEXT: ('sh_flags', 0x0000000000000000) -;; CHECK-NEXT: ('sh_addr', 0x{{.*}}) -;; CHECK-NEXT: ('sh_offset', 0x{{.*}}) -;; CHECK-NEXT: ('sh_size', 0x0000000000000018) -;; CHECK-NEXT: ('sh_link', 0x{{.*}}) -;; CHECK-NEXT: ('sh_info', 0x{{.*}}) -;; CHECK-NEXT: ('sh_addralign', 0x0000000000000008) -;; CHECK-NEXT: ('sh_entsize', 0x0000000000000018) -;; CHECK-NEXT: ('_relocations', [ -;; CHECK-NEXT: # Relocation 0 -;; CHECK-NEXT: (('r_offset', 0x000000000000001c) -;; CHECK-NEXT: ('r_sym', 0x{{.*}}) -;; CHECK-NEXT: ('r_type', 0x00000026) -;; CHECK-NEXT: ('r_addend', 0x0000000000000000) -;; CHECK-NEXT: ), -;; CHECK-NEXT: ]) +; STATIC: ('sh_name', 0x{{.*}}) # '.eh_frame' +; STATIC-NEXT: ('sh_type', 0x00000001) +; STATIC-NEXT: ('sh_flags', 0x0000000000000002) +; STATIC-NEXT: ('sh_addr', 0x{{.*}}) +; STATIC-NEXT: ('sh_offset', 0x{{.*}}) +; STATIC-NEXT: ('sh_size', 0x0000000000000028) +; STATIC-NEXT: ('sh_link', 0x00000000) +; STATIC-NEXT: ('sh_info', 0x00000000) +; STATIC-NEXT: ('sh_addralign', 0x0000000000000008) +; STATIC-NEXT: ('sh_entsize', 0x0000000000000000) +; STATIC-NEXT: ('_section_data', '00000010 00000000 017a5200 01784101 0b0c0100 00000010 00000018 00000000 00000010 00000000') +; STATIC: ('sh_name', 0x{{.*}}) # '.rela.eh_frame' +; STATIC-NEXT: ('sh_type', 0x00000004) +; STATIC-NEXT: ('sh_flags', 0x0000000000000000) +; STATIC-NEXT: ('sh_addr', 0x{{.*}}) +; STATIC-NEXT: ('sh_offset', 0x{{.*}}) +; STATIC-NEXT: ('sh_size', 0x0000000000000018) +; STATIC-NEXT: ('sh_link', 0x{{.*}}) +; STATIC-NEXT: ('sh_info', 0x{{.*}}) +; STATIC-NEXT: ('sh_addralign', 0x0000000000000008) +; STATIC-NEXT: ('sh_entsize', 0x0000000000000018) +; STATIC-NEXT: ('_relocations', [ + +; Static build should create R_PPC64_ADDR32 relocations +; STATIC-NEXT: # Relocation 0 +; STATIC-NEXT: (('r_offset', 0x000000000000001c) +; STATIC-NEXT: ('r_sym', 0x{{.*}}) +; STATIC-NEXT: ('r_type', 0x00000001) +; STATIC-NEXT: ('r_addend', 0x0000000000000000) +; STATIC-NEXT: ), +; STATIC-NEXT: ]) + + +; PIC: ('sh_name', 0x{{.*}}) # '.eh_frame' +; PIC-NEXT: ('sh_type', 0x00000001) +; PIC-NEXT: ('sh_flags', 0x0000000000000002) +; PIC-NEXT: ('sh_addr', 0x{{.*}}) +; PIC-NEXT: ('sh_offset', 0x{{.*}}) +; PIC-NEXT: ('sh_size', 0x0000000000000028) +; PIC-NEXT: ('sh_link', 0x00000000) +; PIC-NEXT: ('sh_info', 0x00000000) +; PIC-NEXT: ('sh_addralign', 0x0000000000000008) +; PIC-NEXT: ('sh_entsize', 0x0000000000000000) +; PIC-NEXT: ('_section_data', '00000010 00000000 017a5200 01784101 1b0c0100 00000010 00000018 00000000 00000010 00000000') + +; PIC: ('sh_name', 0x{{.*}}) # '.rela.eh_frame' +; PIC-NEXT: ('sh_type', 0x00000004) +; PIC-NEXT: ('sh_flags', 0x0000000000000000) +; PIC-NEXT: ('sh_addr', 0x{{.*}}) +; PIC-NEXT: ('sh_offset', 0x{{.*}}) +; PIC-NEXT: ('sh_size', 0x0000000000000018) +; PIC-NEXT: ('sh_link', 0x{{.*}}) +; PIC-NEXT: ('sh_info', 0x{{.*}}) +; PIC-NEXT: ('sh_addralign', 0x0000000000000008) +; PIC-NEXT: ('sh_entsize', 0x0000000000000018) +; PIC-NEXT: ('_relocations', [ + +; PIC build should create R_PPC64_REL32 relocations +; PIC-NEXT: # Relocation 0 +; PIC-NEXT: (('r_offset', 0x000000000000001c) +; PIC-NEXT: ('r_sym', 0x{{.*}}) +; PIC-NEXT: ('r_type', 0x0000001a) +; PIC-NEXT: ('r_addend', 0x0000000000000000) +; PIC-NEXT: ), +; PIC-NEXT: ]) -- cgit v1.2.3-70-g09d2 From a1db5de9e70dd8ffda57b1a4373915ea866b6f1d Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Wed, 9 Jan 2013 17:08:15 +0000 Subject: PowerPC: EH adjustments This patch adjust the r171506 to make all DWARF enconding pc-relative for PPC64. It also adds the R_PPC64_REL32 relocation handling in MCJIT (since the eh_frame will not generate PIC-relative relocation) and also adds the emission of stubs created by the TTypeEncoding. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171979 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ELF.h | 1 + lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 9 ++++++++- lib/MC/MCObjectFileInfo.cpp | 17 +++++++---------- lib/Target/PowerPC/PPCAsmPrinter.cpp | 19 +++++++++++++++++++ test/MC/PowerPC/ppc64-initial-cfa.ll | 6 +++--- 5 files changed, 38 insertions(+), 14 deletions(-) (limited to 'lib/MC/MCObjectFileInfo.cpp') diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h index fa97d6e6dc..6eb1d8f744 100644 --- a/include/llvm/Support/ELF.h +++ b/include/llvm/Support/ELF.h @@ -469,6 +469,7 @@ enum { R_PPC64_ADDR16_HI = 5, R_PPC64_ADDR14 = 7, R_PPC64_REL24 = 10, + R_PPC64_REL32 = 26, R_PPC64_ADDR64 = 38, R_PPC64_ADDR16_HIGHER = 39, R_PPC64_ADDR16_HIGHEST = 41, diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 0a68f4e654..1524b48c54 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -523,7 +523,7 @@ void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section, case ELF::R_PPC64_ADDR32 : { int32_t Result = static_cast(Value + Addend); if (SignExtend32<32>(Result) != Result) - llvm_unreachable("Relocation R_PPC64_REL32 overflow"); + llvm_unreachable("Relocation R_PPC64_ADDR32 overflow"); writeInt32BE(LocalAddress, Result); } break; case ELF::R_PPC64_REL24 : { @@ -534,6 +534,13 @@ void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section, // Generates a 'bl
' instruction writeInt32BE(LocalAddress, 0x48000001 | (delta & 0x03FFFFFC)); } break; + case ELF::R_PPC64_REL32 : { + uint64_t FinalAddress = (Section.LoadAddress + Offset); + int32_t delta = static_cast(Value - FinalAddress + Addend); + if (SignExtend32<32>(delta) != delta) + llvm_unreachable("Relocation R_PPC64_REL32 overflow"); + writeInt32BE(LocalAddress, delta); + } break; case ELF::R_PPC64_ADDR64 : writeInt64BE(LocalAddress, Value + Addend); break; diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index a46f7be5da..a3045848b6 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -257,16 +257,13 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr; } } else if (T.getArch() == Triple::ppc64) { - PersonalityEncoding = dwarf::DW_EH_PE_udata8; - PersonalityEncoding |= (RelocM == Reloc::PIC_) - ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel - : dwarf::DW_EH_PE_absptr; - unsigned PICFlag = (RelocM == Reloc::PIC_) ? dwarf::DW_EH_PE_pcrel - : dwarf::DW_EH_PE_absptr; - FDECFIEncoding = PICFlag | dwarf::DW_EH_PE_sdata4; - LSDAEncoding = PICFlag | dwarf::DW_EH_PE_udata8; - FDEEncoding = PICFlag | dwarf::DW_EH_PE_sdata4; - TTypeEncoding = PICFlag | dwarf::DW_EH_PE_sdata4; + PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | + dwarf::DW_EH_PE_udata8; + FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; + LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8; + FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8; + TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | + dwarf::DW_EH_PE_udata8; } // Solaris requires different flags for .eh_frame to seemingly every other diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 4319894376..839f918a06 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -768,6 +768,25 @@ bool PPCLinuxAsmPrinter::doFinalization(Module &M) { } } + MachineModuleInfoELF &MMIELF = + MMI->getObjFileInfo(); + + MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList(); + if (!Stubs.empty()) { + OutStreamer.SwitchSection(getObjFileLowering().getDataSection()); + for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { + // L_foo$stub: + OutStreamer.EmitLabel(Stubs[i].first); + // .long _foo + OutStreamer.EmitValue(MCSymbolRefExpr::Create(Stubs[i].second.getPointer(), + OutContext), + isPPC64 ? 8 : 4/*size*/, 0/*addrspace*/); + } + + Stubs.clear(); + OutStreamer.AddBlankLine(); + } + return AsmPrinter::doFinalization(M); } diff --git a/test/MC/PowerPC/ppc64-initial-cfa.ll b/test/MC/PowerPC/ppc64-initial-cfa.ll index 0e36fb7138..16236c9c65 100644 --- a/test/MC/PowerPC/ppc64-initial-cfa.ll +++ b/test/MC/PowerPC/ppc64-initial-cfa.ll @@ -20,7 +20,7 @@ entry: ; STATIC-NEXT: ('sh_info', 0x00000000) ; STATIC-NEXT: ('sh_addralign', 0x0000000000000008) ; STATIC-NEXT: ('sh_entsize', 0x0000000000000000) -; STATIC-NEXT: ('_section_data', '00000010 00000000 017a5200 01784101 0b0c0100 00000010 00000018 00000000 00000010 00000000') +; STATIC-NEXT: ('_section_data', '00000010 00000000 017a5200 01784101 1b0c0100 00000010 00000018 00000000 00000010 00000000') ; STATIC: ('sh_name', 0x{{.*}}) # '.rela.eh_frame' ; STATIC-NEXT: ('sh_type', 0x00000004) @@ -34,11 +34,11 @@ entry: ; STATIC-NEXT: ('sh_entsize', 0x0000000000000018) ; STATIC-NEXT: ('_relocations', [ -; Static build should create R_PPC64_ADDR32 relocations +; Static build should create R_PPC64_REL32 relocations ; STATIC-NEXT: # Relocation 0 ; STATIC-NEXT: (('r_offset', 0x000000000000001c) ; STATIC-NEXT: ('r_sym', 0x{{.*}}) -; STATIC-NEXT: ('r_type', 0x00000001) +; STATIC-NEXT: ('r_type', 0x0000001a) ; STATIC-NEXT: ('r_addend', 0x0000000000000000) ; STATIC-NEXT: ), ; STATIC-NEXT: ]) -- cgit v1.2.3-70-g09d2