From ea3ab85c01df27a4dcd1a855b4cf5f3e2bdb2791 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 8 Jun 2014 03:57:49 +0000 Subject: [PATCH] MC: fix text section characteristics for WoA link.exe requires that the text section has the IMAGE_SCN_MEM_16BIT flag set. Otherwise, it will treat the function as ARM. If this occurs, then jumps to the function will fail, switching from thumb to ARM mode execution. With this change, it is possible to link using the MSVC linker as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210415 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCObjectFileInfo.cpp | 3 +++ test/MC/ARM/Windows/text-attributes.s | 30 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/MC/ARM/Windows/text-attributes.s diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index d3d08323447..715dc844c78 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -569,6 +569,8 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) { void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) { + bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb; + // The object file format cannot represent common symbols with explicit // alignments. CommDirectiveSupportsAlignment = false; @@ -582,6 +584,7 @@ void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) { SectionKind::getBSS()); TextSection = Ctx->getCOFFSection(".text", + (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT : 0) | COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | COFF::IMAGE_SCN_MEM_READ, diff --git a/test/MC/ARM/Windows/text-attributes.s b/test/MC/ARM/Windows/text-attributes.s new file mode 100644 index 00000000000..62aa028789f --- /dev/null +++ b/test/MC/ARM/Windows/text-attributes.s @@ -0,0 +1,30 @@ +@ RUN: llvm-mc -triple thumbv7-windows-itanium -filetype obj -o - %s \ +@ RUN: | llvm-readobj -s - | FileCheck %s + + .syntax unified + .thumb + + .text + + .def function + .type 32 + .scl 2 + .endef + .global function + .thumb_func +function: + bx lr + +@ CHECK: Sections [ +@ CHECK: Section { +@ CHECK: Name: .text +@ CHECK: Characteristics [ +@ CHECK: IMAGE_SCN_ALIGN_4BYTES +@ CHECK: IMAGE_SCN_CNT_CODE +@ CHECK: IMAGE_SCN_MEM_16BIT +@ CHECK: IMAGE_SCN_MEM_EXECUTE +@ CHECK: IMAGE_SCN_MEM_PURGEABLE +@ CHECK: IMAGE_SCN_MEM_READ +@ CHECK: ] +@ CHECK: } +@ CHECK: ] -- 2.34.1