From: Alexei Starovoitov Date: Mon, 21 Nov 2016 06:21:23 +0000 (+0000) Subject: [bpf] fix dwarf elf relocs and line numbers X-Git-Tag: llvmorg-4.0.0-rc1~4024 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ab125dbf344e2343ce3fd66bc5496635a1a6f42;p=platform%2Fupstream%2Fllvm.git [bpf] fix dwarf elf relocs and line numbers - teach RelocVisitor to recognize bpf relocations - fix AsmInfo->PointerSize to make sure dwarf is emitted correctly - add a test for the above Signed-off-by: Alexei Starovoitov llvm-svn: 287521 --- diff --git a/llvm/include/llvm/Object/RelocVisitor.h b/llvm/include/llvm/Object/RelocVisitor.h index 27f949d..e1926aa 100644 --- a/llvm/include/llvm/Object/RelocVisitor.h +++ b/llvm/include/llvm/Object/RelocVisitor.h @@ -95,6 +95,17 @@ private: HasError = true; return RelocToApply(); } + case Triple::bpfel: + case Triple::bpfeb: + switch (RelocType) { + case llvm::ELF::R_BPF_64_64: + return visitELF_BPF_64_64(R, Value); + case llvm::ELF::R_BPF_64_32: + return visitELF_BPF_64_32(R, Value); + default: + HasError = true; + return RelocToApply(); + } case Triple::mips64el: case Triple::mips64: switch (RelocType) { @@ -316,6 +327,15 @@ private: return RelocToApply(Res, 4); } + /// BPF ELF + RelocToApply visitELF_BPF_64_32(RelocationRef R, uint64_t Value) { + uint32_t Res = Value & 0xFFFFFFFF; + return RelocToApply(Res, 4); + } + RelocToApply visitELF_BPF_64_64(RelocationRef R, uint64_t Value) { + return RelocToApply(Value, 8); + } + /// PPC64 ELF RelocToApply visitELF_PPC64_ADDR32(RelocationRef R, uint64_t Value) { int64_t Addend = getELFAddend(R); diff --git a/llvm/include/llvm/Support/ELFRelocs/BPF.def b/llvm/include/llvm/Support/ELFRelocs/BPF.def index 868974d..5dd7f70 100644 --- a/llvm/include/llvm/Support/ELFRelocs/BPF.def +++ b/llvm/include/llvm/Support/ELFRelocs/BPF.def @@ -4,6 +4,5 @@ // No relocation ELF_RELOC(R_BPF_NONE, 0) -// Map index in "maps" section to file descriptor -// within ld_64 instruction. -ELF_RELOC(R_BPF_MAP_FD, 1) +ELF_RELOC(R_BPF_64_64, 1) +ELF_RELOC(R_BPF_64_32, 10) diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp index 4b92e3e..3d1c0eb 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp @@ -41,13 +41,13 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target, default: llvm_unreachable("invalid fixup kind!"); case FK_SecRel_8: - return ELF::R_X86_64_64; + return ELF::R_BPF_64_64; case FK_SecRel_4: - return ELF::R_X86_64_PC32; + return ELF::R_BPF_64_32; case FK_Data_8: - return IsPCRel ? ELF::R_X86_64_PC64 : ELF::R_X86_64_64; + return ELF::R_BPF_64_64; case FK_Data_4: - return IsPCRel ? ELF::R_X86_64_PC32 : ELF::R_X86_64_32; + return ELF::R_BPF_64_32; } } diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h index 9a2e223..559ac29 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h @@ -34,6 +34,15 @@ public: HasDotTypeDotSizeDirective = false; SupportsDebugInformation = true; + ExceptionsType = ExceptionHandling::DwarfCFI; + MinInstAlignment = 8; + + // the default is 4 and it only affects dwarf elf output + // so if not set correctly, the dwarf data will be + // messed up in random places by 4 bytes. .debug_line + // section will be parsable, but with odd offsets and + // line numbers, etc. + PointerSize = 8; } }; } diff --git a/llvm/test/CodeGen/BPF/dwarfdump.ll b/llvm/test/CodeGen/BPF/dwarfdump.ll new file mode 100644 index 0000000..7278945 --- /dev/null +++ b/llvm/test/CodeGen/BPF/dwarfdump.ll @@ -0,0 +1,58 @@ +; RUN: llc -O2 %s -o %t -filetype=obj +; RUN: llvm-dwarfdump -debug-dump=line %t | FileCheck %s + +source_filename = "testprog.c" +target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128" +target triple = "bpf" + +@testprog.myvar_c = internal unnamed_addr global i32 0, align 4, !dbg !0 + +define i32 @testprog(i32, i32) local_unnamed_addr #0 !dbg !1 { + tail call void @llvm.dbg.value(metadata i32 %0, i64 0, metadata !10, metadata !15), !dbg !16 + tail call void @llvm.dbg.value(metadata i32 %1, i64 0, metadata !11, metadata !15), !dbg !17 + %3 = load i32, i32* @testprog.myvar_c, align 4, !dbg !18, !tbaa !19 + %4 = add i32 %1, %0, !dbg !23 + %5 = add i32 %4, %3, !dbg !24 + store i32 %5, i32* @testprog.myvar_c, align 4, !dbg !25, !tbaa !19 + ret i32 %5, !dbg !26 +} + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + +attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!6} +!llvm.module.flags = !{!12, !13} +!llvm.ident = !{!14} + +!0 = distinct !DIGlobalVariable(name: "myvar_c", scope: !1, file: !2, line: 3, type: !5, isLocal: true, isDefinition: true) +!1 = distinct !DISubprogram(name: "testprog", scope: !2, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !6, variables: !9) +!2 = !DIFile(filename: "testprog.c", directory: "/w/llvm/bld") +!3 = !DISubroutineType(types: !4) +!4 = !{!5, !5, !5} +!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!6 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 4.0.0 (trunk 287518) (llvm/trunk 287520)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, globals: !8) +!7 = !{} +!8 = !{!0} +!9 = !{!10, !11} +!10 = !DILocalVariable(name: "myvar_a", arg: 1, scope: !1, file: !2, line: 1, type: !5) +!11 = !DILocalVariable(name: "myvar_b", arg: 2, scope: !1, file: !2, line: 1, type: !5) +!12 = !{i32 2, !"Dwarf Version", i32 4} +!13 = !{i32 2, !"Debug Info Version", i32 3} +!14 = !{!"clang version 4.0.0 (trunk 287518) (llvm/trunk 287520)"} +!15 = !DIExpression() +!16 = !DILocation(line: 1, column: 18, scope: !1) +!17 = !DILocation(line: 1, column: 31, scope: !1) +!18 = !DILocation(line: 5, column: 19, scope: !1) +!19 = !{!20, !20, i64 0} +!20 = !{!"int", !21, i64 0} +!21 = !{!"omnipotent char", !22, i64 0} +!22 = !{!"Simple C/C++ TBAA"} +!23 = !DILocation(line: 5, column: 27, scope: !1) +!24 = !DILocation(line: 7, column: 27, scope: !1) +!25 = !DILocation(line: 7, column: 17, scope: !1) +!26 = !DILocation(line: 9, column: 9, scope: !1) +; CHECK: file_names[ 1] 0 0x00000000 0x00000000 testprog.c +; CHECK: 0x0000000000000000 2 +; CHECK: 0x0000000000000020 7