[llvm-bugs] [Bug 24808] New: functions with weak_odr linkage place in 32-bit code section in arm coff

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 14 00:18:15 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24808

            Bug ID: 24808
           Summary: functions with weak_odr linkage place in 32-bit code
                    section in arm coff
           Product: libraries
           Version: trunk
          Hardware: Other
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: pagingio at 163.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

given

target datalayout =
"e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "thumbv7--windows-msvc"

; Function Attrs: inlinehint nounwind
define weak_odr arm_aapcs_vfpcc i32 @vsprintf(i8* %_Buffer, i8* %_Format, i8*
%_ArgList) #0 {
  %1 = alloca i8*, align 4
  %2 = alloca i8*, align 4
  %3 = alloca i8*, align 4
  store i8* %_ArgList, i8** %1, align 4
  store i8* %_Format, i8** %2, align 4
  store i8* %_Buffer, i8** %3, align 4
  %4 = load i8** %1, align 4
  %5 = load i8** %2, align 4
  %6 = load i8** %3, align 4
  %7 = call arm_aapcs_vfpcc i32 @_vsnprintf_l(i8* %6, i32 -1, i8* %5,
%struct.__crt_locale_pointers* null, i8* %4)
  ret i32 %7
}

Section selection for "vsprintf" is wrong. In generated coff object file,
vsprintf is placed in 32-bit code section. When linking with other object
files, instructions calling this function will be fixed with a "blx". This will
cause a run time crash since it will trigger a mode switch from thumb-2 into
arm, while instruction set for windows on arm is strictly limited to thumb-2.

A possible fix:

const MCSection *TargetLoweringObjectFileCOFF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                       Mangler &Mang, const TargetMachine &TM) const {
  // If we have -ffunction-sections then we should emit the global value to a
  // uniqued section specifically for it.
  bool EmitUniquedSection;
  if (Kind.isText())
    EmitUniquedSection = TM.getFunctionSections();
  else
    EmitUniquedSection = TM.getDataSections();

  // If this global is linkonce/weak and the target handles this by emitting it
  // into a 'uniqued' section name, create and return the section now.
  // Section names depend on the name of the symbol which is not feasible if
the
  // symbol has private linkage.
  if ((GV->isWeakForLinker() || EmitUniquedSection || GV->hasComdat()) &&
      !Kind.isCommon()) {
    const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
    unsigned Characteristics = getCOFFSectionFlags(Kind);

    Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
    int Selection = getSelectionForCOFF(GV);
    if (!Selection)
      Selection = COFF::IMAGE_COMDAT_SELECT_NODUPLICATES;
    const GlobalValue *ComdatGV;
    if (GV->hasComdat())
      ComdatGV = getComdatGVForCOFF(GV);
    else
      ComdatGV = GV;

    if (!ComdatGV->hasPrivateLinkage()) {
      MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang);
      StringRef COMDATSymName = Sym->getName();

+      if (Kind.isText()) {
+        const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
+        if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
+          Characteristics |= COFF::IMAGE_SCN_MEM_16BIT;
+      }
      return getContext().getCOFFSection(Name, Characteristics, Kind,
                                         COMDATSymName, Selection);
    }
  }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150914/eea8c0d8/attachment.html>


More information about the llvm-bugs mailing list