Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -341,6 +341,7 @@ /// EmitGlobalVariable - Emit the specified global variable to the .s file. void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { + GV->dump(); bool IsEmuTLSVar = TM.Options.EmulatedTLS && GV->isThreadLocal(); assert(!(IsEmuTLSVar && GV->hasCommonLinkage()) && "No emulated TLS variables in the common section"); @@ -351,6 +352,7 @@ return; if (GV->hasInitializer()) { + dbgs() << "Has Init\n"; // Check to see if this is a special global used by LLVM, if so, emit it. if (EmitSpecialLLVMGlobal(GV)) return; @@ -372,6 +374,7 @@ MCSymbol *GVSym = getSymbol(GV); MCSymbol *EmittedSym = GVSym; + dbgs() << "EmitVisibility\n"; // getOrCreateEmuTLSControlSym only creates the symbol with name and default // attributes. // GV's or GVSym's attributes will be used for the EmittedSym. @@ -415,6 +418,7 @@ return; } + dbgs() << "SectionForGlobal\n"; // Determine to which section this global should be emitted. MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM); @@ -431,6 +435,7 @@ return; } + dbgs() << "A\n"; // If this is a BSS local symbol and we are emitting in the BSS // section use .lcomm/.comm directive. if (GVKind.isBSSLocal() && @@ -461,6 +466,7 @@ return; } + dbgs() << "B\n"; // Handle thread local data for mach-o which requires us to output an // additional structure of data and mangle the original symbol so that we // can reference it later. @@ -513,6 +519,7 @@ return; } + dbgs() << "C\n"; MCSymbol *EmittedInitSym = GVSym; OutStreamer->SwitchSection(TheSection); @@ -522,8 +529,10 @@ OutStreamer->EmitLabel(EmittedInitSym); + dbgs() << "D\n"; EmitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer()); + dbgs() << "E\n"; if (MAI->hasDotTypeDotSizeDirective()) // .size foo, 42 OutStreamer->emitELFSize(cast(EmittedInitSym), @@ -2223,6 +2232,7 @@ uint64_t Offset) { uint64_t Size = DL.getTypeAllocSize(CV->getType()); + dbgs() << "emitGlobalConstantImpl()" << *CV << "\n"; // Globals with sub-elements such as combinations of arrays and structs // are handled recursively by emitGlobalConstantImpl. Keep track of the // constant symbol base and the current position with BaseCV and Offset. @@ -2267,6 +2277,7 @@ return emitGlobalConstantStruct(DL, CVS, AP, BaseCV, Offset); if (const ConstantExpr *CE = dyn_cast(CV)) { + dbgs() << "Is CE\n"; // Look through bitcasts, which might not be able to be MCExpr'ized (e.g. of // vectors). if (CE->getOpcode() == Instruction::BitCast) @@ -2287,19 +2298,25 @@ // Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it // thread the streamer with EmitValue. + dbgs() << "Lower constant\n"; const MCExpr *ME = AP.lowerConstant(CV); // Since lowerConstant already folded and got rid of all IR pointer and // integer casts, detect GOT equivalent accesses by looking into the MCExpr // directly. - if (AP.getObjFileLowering().supportIndirectSymViaGOTPCRel()) + dbgs() <<" Support via GOTPCREL\n"; + if (AP.getObjFileLowering().supportIndirectSymViaGOTPCRel()) { + dbgs() << "True\n"; handleIndirectSymViaGOTPCRel(AP, &ME, BaseCV, Offset); + } + dbgs() << "EmitValue\n"; AP.OutStreamer->EmitValue(ME, Size); } /// EmitGlobalConstant - Print a general LLVM constant to the .s file. void AsmPrinter::EmitGlobalConstant(const DataLayout &DL, const Constant *CV) { + dbgs() << "EmitGlobalConstant( " << *CV << ")\n"; uint64_t Size = DL.getTypeAllocSize(CV->getType()); if (Size) emitGlobalConstantImpl(DL, CV, *this); Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp @@ -11,6 +11,7 @@ #include "AMDGPUMCTargetDesc.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCFixup.h" +#include "llvm/Support/Debug.h" using namespace llvm; @@ -62,8 +63,11 @@ case FK_Data_4: case FK_SecRel_4: return ELF::R_AMDGPU_ABS32; + case FK_Data_8: + return ELF::R_AMDGPU_ABS64; } + dbgs() << "Fixup kind = " << Fixup.getKind() << '\n'; llvm_unreachable("unhandled relocation type"); } Index: test/MC/AMDGPU/reloc.s =================================================================== --- test/MC/AMDGPU/reloc.s +++ test/MC/AMDGPU/reloc.s @@ -1,10 +1,15 @@ // RUN: llvm-mc -filetype=obj -triple amdgcn-- -mcpu=kaveri -show-encoding %s | llvm-readobj -relocations | FileCheck %s // CHECK: Relocations [ +// CHECK: .rel.text { // CHECK: R_AMDGPU_ABS32_LO SCRATCH_RSRC_DWORD0 0x0 // CHECK: R_AMDGPU_ABS32_HI SCRATCH_RSRC_DWORD1 0x0 // CHECK: R_AMDGPU_GOTPCREL global_var 0x0 // CHECK: R_AMDGPU_ABS32 var 0x0 +// CHECK: } +// CHECK: .rel.data { +// CHECK: R_AMDGPU_ABS64 temp 0x0 +// CHECK: } // CHECK: ] kernel: @@ -18,3 +23,13 @@ .section nonalloc, "w", @progbits .long var, common_var + + +// 8 byte relocations + .type ptr,@object + .data + .globl ptr + .p2align 3 +ptr: + .quad temp + .size ptr, 8