[llvm] r210415 - MC: fix text section characteristics for WoA

Saleem Abdulrasool compnerd at compnerd.org
Sat Jun 7 20:57:50 PDT 2014


Author: compnerd
Date: Sat Jun  7 22:57:49 2014
New Revision: 210415

URL: http://llvm.org/viewvc/llvm-project?rev=210415&view=rev
Log:
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.

Added:
    llvm/trunk/test/MC/ARM/Windows/text-attributes.s
Modified:
    llvm/trunk/lib/MC/MCObjectFileInfo.cpp

Modified: llvm/trunk/lib/MC/MCObjectFileInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectFileInfo.cpp?rev=210415&r1=210414&r2=210415&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectFileInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectFileInfo.cpp Sat Jun  7 22:57:49 2014
@@ -569,6 +569,8 @@ void MCObjectFileInfo::InitELFMCObjectFi
 
 
 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::InitCOFFMCObjectF
                         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,

Added: llvm/trunk/test/MC/ARM/Windows/text-attributes.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/Windows/text-attributes.s?rev=210415&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/Windows/text-attributes.s (added)
+++ llvm/trunk/test/MC/ARM/Windows/text-attributes.s Sat Jun  7 22:57:49 2014
@@ -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: ]





More information about the llvm-commits mailing list