[COFF, ARM64] Emit COFF function header

Summary:
Emit COFF header when printing out the function. This is important as the
header contains two important pieces of information: the storage class for the
symbol and the symbol type information. This bit of information is required for
the linker to correctly identify the type of symbol that it is dealing with.

This patch mimics X86 and ARM COFF behavior for function header emission.

Reviewers: rnk, mstorsjo, compnerd, TomTan, ssijaric

Reviewed By: mstorsjo

Subscribers: dmajor, javed.absar, kristof.beyls, llvm-commits

Differential Revision: https://reviews.llvm.org/D55535

llvm-svn: 348875
This commit is contained in:
Mandeep Singh Grang 2018-12-11 18:36:14 +00:00
parent 316f423876
commit 802dc40f41
2 changed files with 72 additions and 5 deletions

View File

@ -28,6 +28,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
@ -109,12 +110,33 @@ public:
AU.setPreservesAll();
}
bool runOnMachineFunction(MachineFunction &F) override {
AArch64FI = F.getInfo<AArch64FunctionInfo>();
STI = static_cast<const AArch64Subtarget*>(&F.getSubtarget());
bool Result = AsmPrinter::runOnMachineFunction(F);
bool runOnMachineFunction(MachineFunction &MF) override {
AArch64FI = MF.getInfo<AArch64FunctionInfo>();
STI = static_cast<const AArch64Subtarget*>(&MF.getSubtarget());
SetupMachineFunction(MF);
if (STI->isTargetCOFF()) {
bool Internal = MF.getFunction().hasInternalLinkage();
COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
: COFF::IMAGE_SYM_CLASS_EXTERNAL;
int Type =
COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
OutStreamer->EmitCOFFSymbolStorageClass(Scl);
OutStreamer->EmitCOFFSymbolType(Type);
OutStreamer->EndCOFFSymbolDef();
}
// Emit the rest of the function body.
EmitFunctionBody();
// Emit the XRay table for this function.
emitXRayTable();
return Result;
// We didn't modify anything.
return false;
}
private:

View File

@ -0,0 +1,45 @@
; RUN: llc -mtriple arm64-windows -filetype asm -o - %s \
; RUN: | FileCheck %s -check-prefix CHECK-ASM
; RUN: llc -mtriple arm64-windows -filetype obj -o - %s \
; RUN: | llvm-readobj -t | FileCheck %s -check-prefix CHECK-OBJECT
define arm_aapcs_vfpcc void @external() {
entry:
ret void
}
; CHECK-ASM: .def external
; CHECK-ASM: .scl 2
; CHECK-ASM: .type 32
; CHECK-ASM: .endef
; CHECK-ASM: .globl external
define internal arm_aapcs_vfpcc void @internal() {
entry:
ret void
}
; CHECK-ASM: .def internal
; CHECK-ASM: .scl 3
; CHECK-ASM: .type 32
; CHECK-ASM: .endef
; CHECK-ASM-NOT: .globl internal
; CHECK-OBJECT: Symbol {
; CHECK-OBJECT: Name: external
; CHECK-OBJECT: Section: .text
; CHECK-OBJECT: BaseType: Null
; CHECK-OBJECT: ComplexType: Function
; CHECK-OBJECT: StorageClass: External
; CHECK-OBJECT: AuxSymbolCount: 0
; CHECK-OBJECT: }
; CHECK-OBJECT: Symbol {
; CHECK-OBJECT: Name: internal
; CHECK-OBJECT: Section: .text
; CHECK-OBJECT: BaseType: Null
; CHECK-OBJECT: ComplexType: Function
; CHECK-OBJECT: StorageClass: Static
; CHECK-OBJECT: AuxSymbolCount: 0
; CHECK-OBJECT: }