[llvm] r348875 - [COFF, ARM64] Emit COFF function header
Mandeep Singh Grang via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 11 10:36:15 PST 2018
Author: mgrang
Date: Tue Dec 11 10:36:14 2018
New Revision: 348875
URL: http://llvm.org/viewvc/llvm-project?rev=348875&view=rev
Log:
[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
Added:
llvm/trunk/test/MC/AArch64/coff-function-type-info.ll
Modified:
llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
Modified: llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp?rev=348875&r1=348874&r2=348875&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp Tue Dec 11 10:36:14 2018
@@ -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:
Added: llvm/trunk/test/MC/AArch64/coff-function-type-info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/coff-function-type-info.ll?rev=348875&view=auto
==============================================================================
--- llvm/trunk/test/MC/AArch64/coff-function-type-info.ll (added)
+++ llvm/trunk/test/MC/AArch64/coff-function-type-info.ll Tue Dec 11 10:36:14 2018
@@ -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: }
+
More information about the llvm-commits
mailing list