Author: Lang Hames Date: 2021-01-18T12:42:48+11:00 New Revision: a817f46d50c34ea6b798d28bd5fa6a3ee7435497
URL: https://github.com/llvm/llvm-project/commit/a817f46d50c34ea6b798d28bd5fa6a3ee7435497 DIFF: https://github.com/llvm/llvm-project/commit/a817f46d50c34ea6b798d28bd5fa6a3ee7435497.diff LOG: [JITLink][ELF] Skip DWARF sections in ELF objects. This matches current JITLink/MachO behavior and avoids processing currently unsupported relocations. Added: llvm/test/ExecutionEngine/JITLink/X86/ELF_skip_debug_sections.s Modified: llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp Removed: ################################################################################ diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp index f3a150d23737..30366a82a043 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -24,6 +24,7 @@ using namespace llvm::jitlink; using namespace llvm::jitlink::ELF_x86_64_Edges; namespace { + class ELF_x86_64_GOTAndStubsBuilder : public BasicGOTAndStubsBuilder<ELF_x86_64_GOTAndStubsBuilder> { public: @@ -110,6 +111,14 @@ class ELF_x86_64_GOTAndStubsBuilder Section *GOTSection = nullptr; Section *StubsSection = nullptr; }; + +const char *const DwarfSectionNames[] = { +#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \ + ELF_NAME, +#include "llvm/BinaryFormat/Dwarf.def" +#undef HANDLE_DWARF_SECTION +}; + } // namespace const uint8_t ELF_x86_64_GOTAndStubsBuilder::NullGOTEntryContent[8] = { @@ -191,6 +200,14 @@ static Error optimizeELF_x86_64_GOTAndStubs(LinkGraph &G) { return Error::success(); } + +static bool isDwarfSection(StringRef SectionName) { + for (auto &DwarfSectionName : DwarfSectionNames) + if (SectionName == DwarfSectionName) + return true; + return false; +} + namespace llvm { namespace jitlink { @@ -305,6 +322,16 @@ class ELFLinkGraphBuilder_x86_64 { auto Name = Obj.getSectionName(SecRef); if (!Name) return Name.takeError(); + + // Skip Dwarf sections. + if (isDwarfSection(*Name)) { + LLVM_DEBUG({ + dbgs() << *Name + << " is a debug section: No graph section will be created.\n"; + }); + continue; + } + sys::Memory::ProtectionFlags Prot; if (SecRef.sh_flags & ELF::SHF_EXECINSTR) { Prot = static_cast<sys::Memory::ProtectionFlags>(sys::Memory::MF_READ | @@ -373,6 +400,10 @@ class ELFLinkGraphBuilder_x86_64 { auto RelSectName = Obj.getSectionName(SecRef); if (!RelSectName) return RelSectName.takeError(); + + LLVM_DEBUG({ + dbgs() << "Adding relocations from section " << *RelSectName << "\n"; + }); // Deal with .eh_frame later if (*RelSectName == StringRef(".rela.eh_frame")) continue; @@ -385,6 +416,18 @@ class ELFLinkGraphBuilder_x86_64 { if (!UpdateSectionName) return UpdateSectionName.takeError(); + // Don't process relocations for debug sections. + if (isDwarfSection(*UpdateSectionName)) { + LLVM_DEBUG({ + dbgs() << " Target is dwarf section " << *UpdateSectionName + << ". Skipping.\n"; + }); + continue; + } else + LLVM_DEBUG({ + dbgs() << " For target section " << *UpdateSectionName << "\n"; + }); + auto JITSection = G->findSectionByName(*UpdateSectionName); if (!JITSection) return make_error<llvm::StringError>( @@ -473,6 +516,9 @@ class ELFLinkGraphBuilder_x86_64 { auto Name = Obj.getSectionName(SecRef); if (!Name) return Name.takeError(); + + LLVM_DEBUG(dbgs() << "Processing symbol section " << *Name << ":\n"); + auto Section = G->findSectionByName(*Name); if (!Section) return make_error<llvm::StringError>("Could not find a section " + @@ -531,6 +577,10 @@ class ELFLinkGraphBuilder_x86_64 { if (!sectName) return Name.takeError(); + // Skip debug section symbols. + if (isDwarfSection(*sectName)) + continue; + auto JitSection = G->findSectionByName(*sectName); if (!JitSection) return make_error<llvm::StringError>( diff --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_skip_debug_sections.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_skip_debug_sections.s new file mode 100644 index 000000000000..506bbdfd8844 --- /dev/null +++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_skip_debug_sections.s @@ -0,0 +1,240 @@ +# RUN: llvm-mc -triple=x86_64-pc-linux-gnu -filetype=obj -o %t %s +# RUN: llvm-jitlink -debug-only=jitlink -noexec %t 2>&1 | FileCheck %s +# +# Check that debug sections are not emitted. +# +# CHECK: .debug_info is a debug section: No graph section will be created. + + .text + .file "ELF_skip_debug_sections.c" + .globl foo + .p2align 4, 0x90 + .type foo,@function +foo: +.Lfunc_begin0: + .file 1 "/tmp" "ELF_skip_debug_sections.c" + .loc 1 1 0 + .cfi_startproc + + .loc 1 2 3 prologue_end + movl $42, %eax + retq +.Ltmp0: +.Lfunc_end0: + .size foo, .Lfunc_end0-foo + .cfi_endproc + + .globl main + .p2align 4, 0x90 + .type main,@function +main: +.Lfunc_begin1: + .loc 1 5 0 + .cfi_startproc + + + + .loc 1 6 3 prologue_end + movl $42, %eax + retq +.Ltmp1: +.Lfunc_end1: + .size main, .Lfunc_end1-main + .cfi_endproc + + .section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "clang version 10.0.0-4ubuntu1 " +.Linfo_string1: + .asciz "ELF_skip_debug_sections.c" +.Linfo_string2: + .asciz "/tmp" +.Linfo_string3: + .asciz "foo" +.Linfo_string4: + .asciz "int" +.Linfo_string5: + .asciz "main" +.Linfo_string6: + .asciz "argc" +.Linfo_string7: + .asciz "argv" +.Linfo_string8: + .asciz "char" + .section .debug_abbrev,"",@progbits + .byte 1 + .byte 17 + .byte 1 + .byte 37 + .byte 14 + .byte 19 + .byte 5 + .byte 3 + .byte 14 + .byte 16 + .byte 23 + .byte 27 + .byte 14 + .byte 17 + .byte 1 + .byte 18 + .byte 6 + .byte 0 + .byte 0 + .byte 2 + .byte 46 + .byte 0 + .byte 17 + .byte 1 + .byte 18 + .byte 6 + .byte 64 + .byte 24 + .ascii "\227B" + .byte 25 + .byte 3 + .byte 14 + .byte 58 + .byte 11 + .byte 59 + .byte 11 + .byte 39 + .byte 25 + .byte 73 + .byte 19 + .byte 63 + .byte 25 + .byte 0 + .byte 0 + .byte 3 + .byte 46 + .byte 1 + .byte 17 + .byte 1 + .byte 18 + .byte 6 + .byte 64 + .byte 24 + .ascii "\227B" + .byte 25 + .byte 3 + .byte 14 + .byte 58 + .byte 11 + .byte 59 + .byte 11 + .byte 39 + .byte 25 + .byte 73 + .byte 19 + .byte 63 + .byte 25 + .byte 0 + .byte 0 + .byte 4 + .byte 5 + .byte 0 + .byte 2 + .byte 24 + .byte 3 + .byte 14 + .byte 58 + .byte 11 + .byte 59 + .byte 11 + .byte 73 + .byte 19 + .byte 0 + .byte 0 + .byte 5 + .byte 36 + .byte 0 + .byte 3 + .byte 14 + .byte 62 + .byte 11 + .byte 11 + .byte 11 + .byte 0 + .byte 0 + .byte 6 + .byte 15 + .byte 0 + .byte 73 + .byte 19 + .byte 0 + .byte 0 + .byte 0 + .section .debug_info,"",@progbits +.Lcu_begin0: + .long .Ldebug_info_end0-.Ldebug_info_start0 +.Ldebug_info_start0: + .short 4 + .long .debug_abbrev + .byte 8 + .byte 1 + .long .Linfo_string0 + .short 12 + .long .Linfo_string1 + .long .Lline_table_start0 + .long .Linfo_string2 + .quad .Lfunc_begin0 + .long .Lfunc_end1-.Lfunc_begin0 + .byte 2 + .quad .Lfunc_begin0 + .long .Lfunc_end0-.Lfunc_begin0 + .byte 1 + .byte 87 + + .long .Linfo_string3 + .byte 1 + .byte 1 + + .long 119 + + .byte 3 + .quad .Lfunc_begin1 + .long .Lfunc_end1-.Lfunc_begin1 + .byte 1 + .byte 87 + + .long .Linfo_string5 + .byte 1 + .byte 5 + + .long 119 + + .byte 4 + .byte 1 + .byte 85 + .long .Linfo_string6 + .byte 1 + .byte 5 + .long 119 + .byte 4 + .byte 1 + .byte 84 + .long .Linfo_string7 + .byte 1 + .byte 5 + .long 126 + .byte 0 + .byte 5 + .long .Linfo_string4 + .byte 5 + .byte 4 + .byte 6 + .long 131 + .byte 6 + .long 136 + .byte 5 + .long .Linfo_string8 + .byte 6 + .byte 1 + .byte 0 +.Ldebug_info_end0: + .ident "clang version 10.0.0-4ubuntu1 " + .section ".note.GNU-stack","",@progbits + .addrsig + .section .debug_line,"",@progbits +.Lline_table_start0: _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits