mirror of
https://github.com/RPCSX/llvm.git
synced 2025-03-06 20:09:02 +00:00
MC: adjust text section flags for WoA
Correct the section flags for code built for Windows on ARM with `-ffunction-sections`. Windows on ARM uses solely Thumb-2 instructions, and indicates that the function is thumb by placing it in a text section that has IMAGE_SCN_MEM_16BIT flag set. When we encounter a .section directive, a new section is constructed. This may be a text segment. In order to identify that we need the additional flag, expose the target triple through the ObjectFileInfo as this information is lost otherwise. Since any modern ARM targeting environment on Windows would be Thumb-2 (Windows ARM NT or Windows Embedded Compact), introducing a new flag to indicate the section attribute seems to be a bit overkill. Simply depend on the target triple. Since there is one location that this information is currently needed, creating a target specific assembly parser and delegating the parsing of section switches also feels a bit heavy handed. If it turns out that this information ends up changing additional behaviour, then it may be worth considering that alternative. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211481 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9124b45918
commit
7a3698ecc9
@ -14,13 +14,13 @@
|
|||||||
#ifndef LLVM_MC_MCBJECTFILEINFO_H
|
#ifndef LLVM_MC_MCBJECTFILEINFO_H
|
||||||
#define LLVM_MC_MCBJECTFILEINFO_H
|
#define LLVM_MC_MCBJECTFILEINFO_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/Triple.h"
|
||||||
#include "llvm/Support/CodeGen.h"
|
#include "llvm/Support/CodeGen.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCSection;
|
class MCSection;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
class Triple;
|
|
||||||
|
|
||||||
class MCObjectFileInfo {
|
class MCObjectFileInfo {
|
||||||
protected:
|
protected:
|
||||||
@ -380,6 +380,7 @@ private:
|
|||||||
Reloc::Model RelocM;
|
Reloc::Model RelocM;
|
||||||
CodeModel::Model CMModel;
|
CodeModel::Model CMModel;
|
||||||
MCContext *Ctx;
|
MCContext *Ctx;
|
||||||
|
Triple TT;
|
||||||
|
|
||||||
void InitMachOMCObjectFileInfo(Triple T);
|
void InitMachOMCObjectFileInfo(Triple T);
|
||||||
void InitELFMCObjectFileInfo(Triple T);
|
void InitELFMCObjectFileInfo(Triple T);
|
||||||
@ -388,6 +389,9 @@ private:
|
|||||||
/// InitEHFrameSection - Initialize EHFrameSection on demand.
|
/// InitEHFrameSection - Initialize EHFrameSection on demand.
|
||||||
///
|
///
|
||||||
void InitEHFrameSection();
|
void InitEHFrameSection();
|
||||||
|
|
||||||
|
public:
|
||||||
|
const Triple &getTargetTriple() const { return TT; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
@ -792,7 +792,7 @@ void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
|
|||||||
SectionKind::getDataRel());
|
SectionKind::getDataRel());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
|
void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
|
||||||
CodeModel::Model cm,
|
CodeModel::Model cm,
|
||||||
MCContext &ctx) {
|
MCContext &ctx) {
|
||||||
RelocM = relocm;
|
RelocM = relocm;
|
||||||
@ -817,8 +817,9 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
|
|||||||
DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
|
DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
|
||||||
DwarfAccelTypesSection = nullptr; // Used only by selected targets.
|
DwarfAccelTypesSection = nullptr; // Used only by selected targets.
|
||||||
|
|
||||||
Triple T(TT);
|
TT = Triple(T);
|
||||||
Triple::ArchType Arch = T.getArch();
|
|
||||||
|
Triple::ArchType Arch = TT.getArch();
|
||||||
// FIXME: Checking for Arch here to filter out bogus triples such as
|
// FIXME: Checking for Arch here to filter out bogus triples such as
|
||||||
// cellspu-apple-darwin. Perhaps we should fix in Triple?
|
// cellspu-apple-darwin. Perhaps we should fix in Triple?
|
||||||
if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
|
if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
|
||||||
@ -826,17 +827,17 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
|
|||||||
Arch == Triple::arm64 || Arch == Triple::aarch64 ||
|
Arch == Triple::arm64 || Arch == Triple::aarch64 ||
|
||||||
Arch == Triple::ppc || Arch == Triple::ppc64 ||
|
Arch == Triple::ppc || Arch == Triple::ppc64 ||
|
||||||
Arch == Triple::UnknownArch) &&
|
Arch == Triple::UnknownArch) &&
|
||||||
(T.isOSDarwin() || T.isOSBinFormatMachO())) {
|
(TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
|
||||||
Env = IsMachO;
|
Env = IsMachO;
|
||||||
InitMachOMCObjectFileInfo(T);
|
InitMachOMCObjectFileInfo(TT);
|
||||||
} else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
|
} else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
|
||||||
Arch == Triple::arm || Arch == Triple::thumb) &&
|
Arch == Triple::arm || Arch == Triple::thumb) &&
|
||||||
(T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
|
(TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
|
||||||
Env = IsCOFF;
|
Env = IsCOFF;
|
||||||
InitCOFFMCObjectFileInfo(T);
|
InitCOFFMCObjectFileInfo(TT);
|
||||||
} else {
|
} else {
|
||||||
Env = IsELF;
|
Env = IsELF;
|
||||||
InitELFMCObjectFileInfo(T);
|
InitELFMCObjectFileInfo(TT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
|
#include "llvm/MC/MCObjectFileInfo.h"
|
||||||
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
||||||
#include "llvm/MC/MCRegisterInfo.h"
|
#include "llvm/MC/MCRegisterInfo.h"
|
||||||
#include "llvm/MC/MCSectionCOFF.h"
|
#include "llvm/MC/MCSectionCOFF.h"
|
||||||
@ -378,6 +379,11 @@ bool COFFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
|
|||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
|
|
||||||
SectionKind Kind = computeSectionKind(Flags);
|
SectionKind Kind = computeSectionKind(Flags);
|
||||||
|
if (Kind.isText()) {
|
||||||
|
const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
|
||||||
|
if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
|
||||||
|
Flags |= COFF::IMAGE_SCN_MEM_16BIT;
|
||||||
|
}
|
||||||
ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
|
ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
58
test/MC/ARM/Windows/multiple-text-sections.s
Normal file
58
test/MC/ARM/Windows/multiple-text-sections.s
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
@ RUN: llvm-mc -triple thumbv7-windows-itanium -filetype obj -o - %s \
|
||||||
|
@ RUN: | llvm-readobj -s - | FileCheck %s
|
||||||
|
|
||||||
|
.syntax unified
|
||||||
|
.text
|
||||||
|
.thumb
|
||||||
|
|
||||||
|
.section .text,"xr",one_only,a
|
||||||
|
|
||||||
|
.def a;
|
||||||
|
.scl 2;
|
||||||
|
.type 32;
|
||||||
|
.endef
|
||||||
|
a:
|
||||||
|
movs r0, #65
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
.section .text,"xr",one_only,b
|
||||||
|
|
||||||
|
.def b;
|
||||||
|
.scl 2;
|
||||||
|
.type 32;
|
||||||
|
.endef
|
||||||
|
.thumb_func
|
||||||
|
b:
|
||||||
|
movs r0, #66
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
@ CHECK: Sections [
|
||||||
|
@ CHECK: Section {
|
||||||
|
@ CHECK: Name: .text
|
||||||
|
@ CHECK: Characteristics [
|
||||||
|
@ CHECK: IMAGE_SCN_CNT_CODE
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_16BIT
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_EXECUTE
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_READ
|
||||||
|
@ CHECK: ]
|
||||||
|
@ CHECK: }
|
||||||
|
@ CHECK: Section {
|
||||||
|
@ CHECK: Name: .text
|
||||||
|
@ CHECK: Characteristics [
|
||||||
|
@ CHECK: IMAGE_SCN_CNT_CODE
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_16BIT
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_EXECUTE
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_READ
|
||||||
|
@ CHECK: ]
|
||||||
|
@ CHECK: }
|
||||||
|
@ CHECK: Section {
|
||||||
|
@ CHECK: Name: .text
|
||||||
|
@ CHECK: Characteristics [
|
||||||
|
@ CHECK: IMAGE_SCN_CNT_CODE
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_16BIT
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_EXECUTE
|
||||||
|
@ CHECK: IMAGE_SCN_MEM_READ
|
||||||
|
@ CHECK: ]
|
||||||
|
@ CHECK: }
|
||||||
|
@ CHECK: ]
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user