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.s =================================================================== --- test/MC/AMDGPU/elf64-dwarf-relocs.s +++ test/MC/AMDGPU/elf64-dwarf-relocs.s @@ -0,0 +1,128 @@ +; RUN: llvm-mc -filetype=obj -triple=amdgcn--amdhsa -mcpu=fiji %s -o %t.o +; RUN: llvm-readobj -r %t.o | FileCheck %s --check-prefix=READOBJ +; RUN: llvm-dwarfdump -debug-dump=info %t.o | FileCheck %s --check-prefix=DWARFDUMP + +; READOBJ: Relocations [ +; READOBJ: Section (6) .rela.debug_info { +; READOBJ: R_AMDGPU_ABS32 .debug_abbrev +; READOBJ: R_AMDGPU_ABS32 .debug_str +; READOBJ: R_AMDGPU_ABS32 .debug_str +; READOBJ: R_AMDGPU_ABS32 .debug_line +; READOBJ: R_AMDGPU_ABS32 .debug_str +; READOBJ: R_AMDGPU_ABS32 .text +; READOBJ: R_AMDGPU_ABS32 .text +; READOBJ: R_AMDGPU_ABS32 .text +; READOBJ: R_AMDGPU_ABS32 .text +; READOBJ: R_AMDGPU_ABS32 .debug_str +; READOBJ: } +; READOBJ: Section (8) .rela.debug_pubnames { +; READOBJ: R_AMDGPU_ABS32 .debug_info +; READOBJ: } +; READOBJ: Section (10) .rela.debug_line { +; READOBJ: R_AMDGPU_ABS32 .text +; READOBJ: } +; READOBJ: ] + +; DWARFDUMP: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = "clang version 3.9.0 (trunk 274858)") +; DWARFDUMP: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000023] = "amdgpu-elf64-dwarf-relocs.cl") +; DWARFDUMP: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000040] = "/home/kzhuravl/Git/Lightning/test") +; DWARFDUMP: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000062] = "amdgpu_elf64_dwarf_relocs") +; DWARFDUMP: DW_AT_decl_file [DW_FORM_data1] ("/home/kzhuravl/Git/Lightning/test/amdgpu-elf64-dwarf-relocs.cl") + +amdgpu_elf64_dwarf_relocs: +.Lfunc_begin0: + .file 1 "amdgpu-elf64-dwarf-relocs.cl" + .loc 1 1 0 + .loc 1 1 42 prologue_end + s_endpgm +.Lfunc_end0: + .size amdgpu_elf64_dwarf_relocs, .Lfunc_end0-amdgpu_elf64_dwarf_relocs + +.section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "clang version 3.9.0 (trunk 274858)" ; string offset=0 +.Linfo_string1: + .asciz "amdgpu-elf64-dwarf-relocs.cl" ; string offset=35 +.Linfo_string2: + .asciz "/home/kzhuravl/Git/Lightning/test" ; string offset=64 +.Linfo_string3: + .asciz "amdgpu_elf64_dwarf_relocs" ; string offset=98 + +.section .debug_abbrev +.Lsection_abbrev: + .byte 1 ; Abbreviation Code + .byte 17 ; DW_TAG_compile_unit + .byte 1 ; DW_CHILDREN_yes + .byte 37 ; DW_AT_producer + .byte 14 ; DW_FORM_strp + .byte 19 ; DW_AT_language + .byte 5 ; DW_FORM_data2 + .byte 3 ; DW_AT_name + .byte 14 ; DW_FORM_strp + .byte 16 ; DW_AT_stmt_list + .byte 6 ; DW_FORM_data4 + .byte 27 ; DW_AT_comp_dir + .byte 14 ; DW_FORM_strp + .byte 17 ; DW_AT_low_pc + .byte 1 ; DW_FORM_addr + .byte 18 ; DW_AT_high_pc + .byte 1 ; DW_FORM_addr + .byte 0 ; EOM(1) + .byte 0 ; EOM(2) + .byte 2 ; Abbreviation Code + .byte 46 ; DW_TAG_subprogram + .byte 0 ; DW_CHILDREN_no + .byte 17 ; DW_AT_low_pc + .byte 1 ; DW_FORM_addr + .byte 18 ; DW_AT_high_pc + .byte 1 ; DW_FORM_addr + .byte 3 ; DW_AT_name + .byte 14 ; DW_FORM_strp + .byte 58 ; DW_AT_decl_file + .byte 11 ; DW_FORM_data1 + .byte 59 ; DW_AT_decl_line + .byte 11 ; DW_FORM_data1 + .byte 63 ; DW_AT_external + .byte 12 ; DW_FORM_flag + .byte 0 ; EOM(1) + .byte 0 ; EOM(2) + .byte 0 ; EOM(3) + +.section .debug_info +.Lsection_info: +.Lcu_begin0: + .long 51 ; Length of Unit + .short 2 ; DWARF version number + .long .Lsection_abbrev ; Offset Into Abbrev. Section + .byte 4 ; Address Size (in bytes) + .byte 1 ; Abbrev [1] 0xb:0x2c DW_TAG_compile_unit + .long .Linfo_string0 ; DW_AT_producer + .short 12 ; DW_AT_language + .long .Linfo_string1 ; DW_AT_name + .long .Lline_table_start0 ; DW_AT_stmt_list + .long .Linfo_string2 ; DW_AT_comp_dir + .long .Lfunc_begin0 ; DW_AT_low_pc + .long .Lfunc_end0 ; DW_AT_high_pc + .byte 2 ; Abbrev [2] 0x26:0x10 DW_TAG_subprogram + .long .Lfunc_begin0 ; DW_AT_low_pc + .long .Lfunc_end0 ; DW_AT_high_pc + .long .Linfo_string3 ; DW_AT_name + .byte 1 ; DW_AT_decl_file + .byte 1 ; DW_AT_decl_line + .byte 1 ; DW_AT_external + .byte 0 ; End Of Children Mark +.Lcu_macro_begin0: + .byte 0 + .section .debug_pubnames + .long .LpubNames_end0-.LpubNames_begin0 +.LpubNames_begin0: + .short 2 + .long .Lcu_begin0 + .long 55 + .long 38 + .asciz "amdgpu_elf64_dwarf_relocs" + .long 0 +.LpubNames_end0: + +.section .debug_line +.Lline_table_start0: