Index: include/llvm/Object/RelocVisitor.h =================================================================== --- include/llvm/Object/RelocVisitor.h +++ include/llvm/Object/RelocVisitor.h @@ -139,6 +139,14 @@ HasError = true; return RelocToApply(); } + case Triple::amdgcn: + switch (RelocType) { + case llvm::ELF::R_AMDGPU_ABS32: + return visitELF_AMDGPU_ABS32(R, Value); + default: + HasError = true; + return RelocToApply(); + } default: HasError = true; return RelocToApply(); @@ -403,6 +411,11 @@ return RelocToApply(static_cast(Res), 4); } + RelocToApply visitELF_AMDGPU_ABS32(RelocationRef R, uint64_t Value) { + int64_t Addend = getELFAddend(R); + return RelocToApply(Value + Addend, 4); + } + /// I386 COFF RelocToApply visitCOFF_I386_SECREL(RelocationRef R, uint64_t Value) { return RelocToApply(static_cast(Value), /*Width=*/4); Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp @@ -56,6 +56,7 @@ default: break; case FK_PCRel_4: return ELF::R_AMDGPU_REL32; + case FK_Data_4: case FK_SecRel_4: return ELF::R_AMDGPU_ABS32; } Index: test/MC/AMDGPU/elf64-dwarf-relocs.ll =================================================================== --- test/MC/AMDGPU/elf64-dwarf-relocs.ll +++ test/MC/AMDGPU/elf64-dwarf-relocs.ll @@ -0,0 +1,53 @@ +; RUN: llc -filetype=obj -mtriple=amdgcn--amdhsa -mcpu=fiji < %s | llvm-readobj -r | FileCheck %s --check-prefix=READOBJ +; RUN: llc -filetype=obj -mtriple=amdgcn--amdhsa -mcpu=fiji %s -o %t.o +; RUN: llvm-dwarfdump -debug-dump=info %t.o | FileCheck %s --check-prefix=DWARFDUMP + +; READOBJ: Relocations [ +; READOBJ-NEXT: Section (9) .rela.debug_info { +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_abbrev +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_str +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_str +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_line +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_str +; READOBJ-NEXT: R_AMDGPU_ABS32 .text +; READOBJ-NEXT: R_AMDGPU_ABS32 .text +; READOBJ-NEXT: R_AMDGPU_ABS32 .text +; READOBJ-NEXT: R_AMDGPU_ABS32 .text +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_str +; READOBJ-NEXT: } +; READOBJ-NEXT: Section (13) .rela.debug_pubnames { +; READOBJ-NEXT: R_AMDGPU_ABS32 .debug_info +; READOBJ-NEXT: } +; READOBJ-NEXT: Section (17) .rela.debug_line { +; READOBJ-NEXT: R_AMDGPU_ABS32 .text +; READOBJ-NEXT: } +; READOBJ-NEXT: ] + +; DWARFDUMP: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = "clang version 3.9.0 (trunk 274777)") +; DWARFDUMP: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000023] = "elf64-dwarf-relocs.cl") +; DWARFDUMP: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000039] = "/home/kzhuravl/Git/Lightning/temp") +; DWARFDUMP: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000005b] = "elf64_dwarf_relocs") +; DWARFDUMP: DW_AT_decl_file [DW_FORM_data1] ("/home/kzhuravl/Git/Lightning/temp/elf64-dwarf-relocs.cl") + +; Function Attrs: norecurse nounwind readnone +define amdgpu_kernel void @elf64_dwarf_relocs() local_unnamed_addr #0 !dbg !6 !kernel_arg_addr_space !2 !kernel_arg_access_qual !2 !kernel_arg_type !2 !kernel_arg_base_type !2 !kernel_arg_type_qual !2 { +entry: + ret void, !dbg !9 +} + +attributes #0 = { norecurse nounwind readnone "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" "stack-protector-buffer-size"="8" "target-cpu"="fiji" "target-features"="+16-bit-insts,+s-memrealtime" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 274777)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "elf64-dwarf-relocs.cl", directory: "/home/kzhuravl/Git/Lightning/temp") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 2} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 3.9.0 (trunk 274777)"} +!6 = distinct !DISubprogram(name: "elf64_dwarf_relocs", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, variables: !2) +!7 = !DISubroutineType(types: !8) +!8 = !{null} +!9 = !DILocation(line: 1, column: 35, scope: !6)